1
1
mirror of https://github.com/wader/fq.git synced 2024-10-06 00:17:58 +03:00

interp: Fix interrupt panic for cli eval

Rewrite cli query to use display as output query, same as for repl.
Without this "tovalue" values that don't print in the current eval
will end up in the paren eval and be written using an output without
a cancel context.
This commit is contained in:
Mattias Wadman 2022-09-29 17:59:25 +02:00
parent 88b598ead7
commit c4219d69db
2 changed files with 8 additions and 4 deletions

View File

@ -135,6 +135,9 @@ def _cli_repl_error($_):
_eval_error("compile"; "repl can only be used from interactive repl");
def _cli_slurp_error(_):
_eval_error("compile"; "slurp can only be used from interactive repl");
# TODO: rewrite query to reuse _display_default_opts value? also _repl_display
def _cli_display:
display(_display_default_opts);
# _cli_eval halts on compile errors
def _cli_eval($expr; $opts):
eval(
@ -145,7 +148,7 @@ def _cli_eval($expr; $opts):
repl: "_cli_repl_error",
slurp: "_cli_slurp_error"
},
catch_query: _query_func("_cli_eval_on_expr_error")
catch_query: _query_func("_cli_eval_on_expr_error"),
};
_cli_eval_on_error;
_cli_eval_on_compile_error
@ -235,7 +238,6 @@ def _main:
)
else
( _cli_last_expr_error(null) as $_
| _display_default_opts as $default_opts
| _cli_eval(
$opts.expr;
( $eval_opts
@ -248,9 +250,11 @@ def _main:
else _query_func("inputs")
end
)
# call display in sub eval so it can be interrupted
# for repl case value will used as input to _repl instead
| .output_query = _query_func("_cli_display")
)
)
| display($default_opts)
)
end;
# finally

View File

@ -227,7 +227,7 @@ def _repl_eval($expr; on_error; on_compile_error):
},
# input to repl is always array of values to iterate
input_query: (_query_ident | _query_iter), # .[]
# each input should be evaluted separatel like with cli, so catch and just print errors
# each input should be evaluted separately like cli file args, so catch and just print errors
catch_query: _query_func("_repl_on_expr_error"),
# run display in sub eval so it can be interrupted
output_query: _query_func("_repl_display")