Skip to content

Commit

Permalink
cli: Add --options to make help a bit nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 12, 2021
1 parent c8776ab commit 17104f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
13 changes: 9 additions & 4 deletions pkg/interp/interp.jq
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,16 @@ def _main:
description: "Null input (use input/0 and inputs/0 to read input)",
bool: true
},
"options": {
"option": {
short: "-o",
long: "--option",
description: "Set option, eg: color=true",
object: "KEY=VALUE",
default: {},
help_default: _build_default_options
},
"options": {
long: "--options",
description: "Show all options",
bool: true
},
"string_input": {
short: "-R",
Expand Down Expand Up @@ -489,7 +492,7 @@ def _main:
| _parsed_args($parsed_args) as $_
| _default_options(_build_default_options) as $_
| _options_stack(
[ ($parsed_args.options | _to_options)
[ ($parsed_args.option | _to_options)
+ ({
compact: $parsed_args.compact,
expr_file: $parsed_args.expr_file,
Expand Down Expand Up @@ -526,6 +529,8 @@ def _main:
$version | println
elif $parsed_args.formats then
_formats_list | println
elif $parsed_args.options then
$opts | display
elif
( ($rest | length) == 0 and
($opts.repl | not) and
Expand Down
50 changes: 27 additions & 23 deletions pkg/interp/testdata/args.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,7 @@ Usage: fq [OPTIONS] [--] [EXPR] [FILE...]
--null-input,-n Null input (use input/0 and inputs/0 to read input)
--null-output,-0 Null byte between outputs
--option,-o KEY=VALUE Set option, eg: color=true
addrbase=16
arraytruncate=50
bitsformat=snippet
bytecolors=0-0xff=brightwhite,0=brightblack,32-126:9-13=white
color=false
colors=array=white,dumpaddr=yellow,dumpheader=yellow+underline,error=brightred,false=yellow,index=white,null=brightblack,number=cyan,object=white,objectkey=brightblue,string=green,true=yellow,value=white
compact=false
decode_progress=false
depth=0
displaybytes=16
expr_file=
include_path=
join_string=\n
linebytes=16
null_input=false
raw_output=false
raw_string=false
repl=false
sizebase=10
slurp=false
string_input=false
unicode=false
verbose=false
--options Show all options
--raw-output,-r Raw string output (without quotes)
--repl,-i Interactive REPL
--slurp,-s Read (slurp) all inputs into an array
Expand Down Expand Up @@ -133,6 +111,32 @@ vpx_ccr VPX Codec Configuration Record
wav WAV file
webp WebP image
xing Xing header
$ fq --options
{
"addrbase": 16,
"arraytruncate": 50,
"bitsformat": "snippet",
"bytecolors": "0-0xff=brightwhite,0=brightblack,32-126:9-13=white",
"color": false,
"colors": "array=white,dumpaddr=yellow,dumpheader=yellow+underline,error=brightred,false=yellow,index=white,null=brightblack,number=cyan,object=white,objectkey=brightblue,string=green,true=yellow,value=white",
"compact": false,
"decode_progress": false,
"depth": 0,
"displaybytes": 16,
"expr_file": null,
"include_path": null,
"join_string": "\n",
"linebytes": 16,
"null_input": false,
"raw_output": false,
"raw_string": false,
"repl": false,
"sizebase": 10,
"slurp": false,
"string_input": false,
"unicode": false,
"verbose": false
}
$ fq -X
exitcode: 2
stderr:
Expand Down

0 comments on commit 17104f0

Please sign in to comment.