Skip to content

Commit

Permalink
implement --library-path option as the alias of -L option
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Nov 19, 2024
1 parent af0c3da commit 5fbda3f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
4 changes: 2 additions & 2 deletions _gojq
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _gojq()
'(-r --raw-output -j --join-output)--raw-output0[implies -r with NUL character delimiter]' \
'(-r --raw-output --raw-output0 -j --join-output)'{-j,--join-output}'[implies -r with no newline delimiter]' \
'(-c --compact-output --indent --tab --yaml-output)'{-c,--compact-output}'[output without pretty-printing]' \
'(-c --compact-output --tab --yaml-output)--indent=[number of spaces for indentation]:indentation count:(2 4 8)' \
'(-c --compact-output --tab --yaml-output)--indent[number of spaces for indentation]:indentation count:(2 4 8)' \
'(-c --compact-output --indent --yaml-output)--tab[use tabs for indentation]' \
'(-c --compact-output --indent --tab )--yaml-output[output in YAML format]' \
'(-C --color-output -M --monochrome-output)'{-C,--color-output}'[output with colors even if piped]' \
Expand All @@ -18,7 +18,7 @@ _gojq()
'(-R --raw-input --stream )--yaml-input[read input as YAML format]' \
'(-s --slurp)'{-s,--slurp}'[read all inputs into an array]' \
'(-f --from-file 1)'{-f,--from-file}'[load query from file]:filename of jq query:_files' \
'*-L=[directory to search modules from]:module directory:_directories' \
'*'{-L,--library-path}'[directory to search modules from]:module directory:_directories' \
'*--arg[set a string value to a variable]:variable name: :string value' \
'*--argjson[set a JSON value to a variable]:variable name: :JSON value' \
'*--slurpfile[set the JSON contents of a file to a variable]:variable name: :JSON file:_files' \
Expand Down
12 changes: 6 additions & 6 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type flagopts struct {
OutputRaw0 bool `long:"raw-output0" description:"implies -r with NUL character delimiter"`
OutputJoin bool `short:"j" long:"join-output" description:"implies -r with no newline delimiter"`
OutputCompact bool `short:"c" long:"compact-output" description:"output without pretty-printing"`
OutputIndent *int `long:"indent" description:"number of spaces for indentation"`
OutputIndent *int `long:"indent" args:"number" description:"number of spaces for indentation"`
OutputTab bool `long:"tab" description:"use tabs for indentation"`
OutputYAML bool `long:"yaml-output" description:"output in YAML format"`
OutputColor bool `short:"C" long:"color-output" description:"output with colors even if piped"`
Expand All @@ -69,11 +69,11 @@ type flagopts struct {
InputYAML bool `long:"yaml-input" description:"read input as YAML format"`
InputSlurp bool `short:"s" long:"slurp" description:"read all inputs into an array"`
FromFile bool `short:"f" long:"from-file" description:"load query from file"`
ModulePaths []string `short:"L" description:"directory to search modules from"`
Arg map[string]string `long:"arg" description:"set a string value to a variable"`
ArgJSON map[string]string `long:"argjson" description:"set a JSON value to a variable"`
SlurpFile map[string]string `long:"slurpfile" description:"set the JSON contents of a file to a variable"`
RawFile map[string]string `long:"rawfile" description:"set the contents of a file to a variable"`
ModulePaths []string `short:"L" long:"library-path" args:"dir" description:"directory to search modules from"`
Arg map[string]string `long:"arg" args:"name value" description:"set a string value to a variable"`
ArgJSON map[string]string `long:"argjson" args:"name value" description:"set a JSON value to a variable"`
SlurpFile map[string]string `long:"slurpfile" args:"name file" description:"set the JSON contents of a file to a variable"`
RawFile map[string]string `long:"rawfile" args:"name file" description:"set the contents of a file to a variable"`
Args []any `long:"args" positional:"" description:"consume remaining arguments as positional string values"`
JSONArgs []any `long:"jsonargs" positional:"" description:"consume remaining arguments as positional JSON values"`
ExitStatus bool `short:"e" long:"exit-status" description:"exit 1 when the last value is false or null"`
Expand Down
20 changes: 4 additions & 16 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,10 @@ func formatFlags(opts any) string {
}
sb.WriteString("--")
sb.WriteString(flag)
switch val.Field(i).Kind() {
case reflect.Bool:
sb.WriteString(" ")
case reflect.Map:
if strings.HasSuffix(flag, "file") {
sb.WriteString(" name file")
} else {
sb.WriteString(" name value")
}
default:
if _, ok = tag.Lookup("positional"); !ok {
sb.WriteString("=")
}
}
} else {
sb.WriteString("=")
}
if args, ok := tag.Lookup("args"); ok {
sb.WriteString(" ")
sb.WriteString(args)
}
sb.WriteString(strings.Repeat(" ", 24-(sb.Len()-m)))
sb.WriteString(tag.Get("description"))
Expand Down
4 changes: 2 additions & 2 deletions cli/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7902,7 +7902,7 @@
- name: module directory option
args:
- -c
- -L
- --library-path
- 'testdata'
- 'import "7" as $foo; $foo, $foo::foo'
input: '0'
Expand All @@ -7913,7 +7913,7 @@
- name: module directory option
args:
- -c
- -L
- --library-path
- 'testdata'
- 'import "m1" as $x; $x, $x::x, $x[1].m1*100000000000000000000'
input: '0'
Expand Down

0 comments on commit 5fbda3f

Please sign in to comment.