Skip to content

Commit

Permalink
Improve cli help a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Sep 12, 2021
1 parent 27095b5 commit 57f0ec1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
94 changes: 47 additions & 47 deletions pkg/interp/fq.jq
Original file line number Diff line number Diff line change
Expand Up @@ -280,33 +280,10 @@ def _main:
);
def _opts($version):
{
"version": {
short: "-v",
long: "--version",
description: "Show version (\($version))",
bool: true
},
"help": {
short: "-h",
long: "--help",
description: "Show help",
bool: true
},
"formats": {
long: "--formats",
description: "Show supported formats",
bool: true
},
"nullinput": {
short: "-n",
long: "--null-input",
description: "Null input (can still use input/0 or inputs/0)",
bool: true
},
"slurp": {
short: "-s",
long: "--slurp",
description: "Read (slurp) all inputs into an array",
"compact": {
short: "-c",
long: "--compact",
description: "Compact output",
bool: true
},
"decode_format": {
Expand All @@ -316,28 +293,21 @@ def _main:
default: "probe",
string: "NAME"
},
"repl": {
short: "-i",
long: "--repl",
description: "Interactive REPL",
bool: true
},
"file": {
short: "-f",
long: "--file",
description: "Read script from file",
description: "Read EXPR from file",
string: "PATH"
},
"raw_output": {
short: "-r",
long: "--raw-output",
description: "Raw string output (without quotes)",
"formats": {
long: "--formats",
description: "Show supported formats",
bool: true
},
"compact": {
short: "-c",
long: "--compact",
description: "Compact output",
"help": {
short: "-h",
long: "--help",
description: "Show help",
bool: true
},
"join_output": {
Expand All @@ -352,6 +322,12 @@ def _main:
description: "Null byte between outputs",
bool: true
},
"null_input": {
short: "-n",
long: "--null-input",
description: "Null input (can still use input/0 or inputs/0)",
bool: true
},
"options": {
short: "-o",
long: "--option",
Expand All @@ -360,9 +336,33 @@ def _main:
default: {},
help_default: _build_default_options
},
"raw_output": {
short: "-r",
long: "--raw-output",
description: "Raw string output (without quotes)",
bool: true
},
"repl": {
short: "-i",
long: "--repl",
description: "Interactive REPL",
bool: true
},
"slurp": {
short: "-s",
long: "--slurp",
description: "Read (slurp) all inputs into an array",
bool: true
},
"version": {
short: "-v",
long: "--version",
description: "Show version (\($version))",
bool: true
},
};
def _usage($arg0; $version):
"Usage: \($arg0) [OPTIONS] [EXPR] [FILE...]";
"Usage: \($arg0) [OPTIONS] [--] [EXPR] [FILE...]";
( . as {$version, $args, args: [$arg0]}
# make sure we don't unintentionally use . to make things clearer
| null
Expand Down Expand Up @@ -404,7 +404,7 @@ def _main:
else
# use finally as display etc prints and results in empty
finally(
( { nullinput: ($parsed_args.nullinput == true) }
( { null_input: ($parsed_args.null_input == true) }
| if $parsed_args.file then
( .expr = ($parsed_args.file | open | string)
| .filenames = $rest
Expand All @@ -415,13 +415,13 @@ def _main:
)
end
| if $parsed_args.repl and .filenames == [] then
.nullinput = true
.null_input = true
elif .filenames == [] then
.filenames = ["-"]
end
| . as {$expr, $filenames, $nullinput}
| . as {$expr, $filenames, $null_input}
| inputs($filenames) as $_ # store inputs
| if $nullinput then null
| if $null_input then null
elif $parsed_args.slurp then [inputs]
else inputs # will iterate inputs
end
Expand Down
10 changes: 5 additions & 5 deletions pkg/interp/testdata/args.fqtest
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/test.mp3:
> fq
Usage: fq [OPTIONS] [EXPR] [FILE...]
Usage: fq [OPTIONS] [--] [EXPR] [FILE...]
> fq -h
Usage: fq [OPTIONS] [EXPR] [FILE...]
Usage: fq [OPTIONS] [--] [EXPR] [FILE...]
--compact,-c Compact output
--decode,-d=NAME Decode format (probe)
--file,-f=PATH Read script from file
--file,-f=PATH Read EXPR from file
--formats Show supported formats
--help,-h Show help
--join-output,-j No newline between outputs
--null-output,-0 Null byte between outputs
--null-input,-n Null input (can still use input/0 or inputs/0)
--null-output,-0 Null byte between outputs
--option,-o=KEY=VALUE,... Set option, eg: color=true
addrbase=16
bytecolors=0-0xff=brightwhite,0=brightblack,32-126:9-13=white
Expand All @@ -33,7 +33,7 @@ null> ^D
> fq -i . /test.mp3
mp3> ^D
> fq -n
Usage: fq [OPTIONS] [EXPR] [FILE...]
Usage: fq [OPTIONS] [--] [EXPR] [FILE...]
> fq -ni
null> ^D
> fq -n 123
Expand Down

0 comments on commit 57f0ec1

Please sign in to comment.