From 44d8b66a8e5976c38f12e9967cc7804d86170125 Mon Sep 17 00:00:00 2001 From: Mattias Wadman Date: Tue, 7 Sep 2021 18:02:14 +0200 Subject: [PATCH] repl: Give error if repl is used in non-repl mode --- pkg/interp/interp.jq | 7 +++++-- pkg/interp/testdata/repl.fqtest | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/interp/interp.jq b/pkg/interp/interp.jq index bee0ef85..bdd7a9ee 100644 --- a/pkg/interp/interp.jq +++ b/pkg/interp/interp.jq @@ -331,8 +331,11 @@ def _repl_iter($opts): _repl($opts); def _repl_iter: _repl({}); # just gives error, call appearing last will be renamed to _repl_iter -def repl($_): error("repl must be last"); -def repl: error("repl must be last"); +def repl($_): + if options.repl then error("repl must be last") + else error("repl can't be used in non-repl mode") + end; +def repl: repl(null); def _cli_expr_on_error: diff --git a/pkg/interp/testdata/repl.fqtest b/pkg/interp/testdata/repl.fqtest index 8bb3c856..51a9dedb 100644 --- a/pkg/interp/testdata/repl.fqtest +++ b/pkg/interp/testdata/repl.fqtest @@ -58,3 +58,7 @@ $ fq -i '[1,2,3]' [1,2,3] > [number, ...][3]> ^D [number, ...][3]> ^D +$ fq -n repl +exitcode: 5 +stderr: +error: repl can't be used in non-repl mode