Skip to content

Commit 5fbda3f

Browse files
committed
implement --library-path option as the alias of -L option
1 parent af0c3da commit 5fbda3f

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

_gojq

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ _gojq()
77
'(-r --raw-output -j --join-output)--raw-output0[implies -r with NUL character delimiter]' \
88
'(-r --raw-output --raw-output0 -j --join-output)'{-j,--join-output}'[implies -r with no newline delimiter]' \
99
'(-c --compact-output --indent --tab --yaml-output)'{-c,--compact-output}'[output without pretty-printing]' \
10-
'(-c --compact-output --tab --yaml-output)--indent=[number of spaces for indentation]:indentation count:(2 4 8)' \
10+
'(-c --compact-output --tab --yaml-output)--indent[number of spaces for indentation]:indentation count:(2 4 8)' \
1111
'(-c --compact-output --indent --yaml-output)--tab[use tabs for indentation]' \
1212
'(-c --compact-output --indent --tab )--yaml-output[output in YAML format]' \
1313
'(-C --color-output -M --monochrome-output)'{-C,--color-output}'[output with colors even if piped]' \
@@ -18,7 +18,7 @@ _gojq()
1818
'(-R --raw-input --stream )--yaml-input[read input as YAML format]' \
1919
'(-s --slurp)'{-s,--slurp}'[read all inputs into an array]' \
2020
'(-f --from-file 1)'{-f,--from-file}'[load query from file]:filename of jq query:_files' \
21-
'*-L=[directory to search modules from]:module directory:_directories' \
21+
'*'{-L,--library-path}'[directory to search modules from]:module directory:_directories' \
2222
'*--arg[set a string value to a variable]:variable name: :string value' \
2323
'*--argjson[set a JSON value to a variable]:variable name: :JSON value' \
2424
'*--slurpfile[set the JSON contents of a file to a variable]:variable name: :JSON file:_files' \

cli/cli.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type flagopts struct {
5858
OutputRaw0 bool `long:"raw-output0" description:"implies -r with NUL character delimiter"`
5959
OutputJoin bool `short:"j" long:"join-output" description:"implies -r with no newline delimiter"`
6060
OutputCompact bool `short:"c" long:"compact-output" description:"output without pretty-printing"`
61-
OutputIndent *int `long:"indent" description:"number of spaces for indentation"`
61+
OutputIndent *int `long:"indent" args:"number" description:"number of spaces for indentation"`
6262
OutputTab bool `long:"tab" description:"use tabs for indentation"`
6363
OutputYAML bool `long:"yaml-output" description:"output in YAML format"`
6464
OutputColor bool `short:"C" long:"color-output" description:"output with colors even if piped"`
@@ -69,11 +69,11 @@ type flagopts struct {
6969
InputYAML bool `long:"yaml-input" description:"read input as YAML format"`
7070
InputSlurp bool `short:"s" long:"slurp" description:"read all inputs into an array"`
7171
FromFile bool `short:"f" long:"from-file" description:"load query from file"`
72-
ModulePaths []string `short:"L" description:"directory to search modules from"`
73-
Arg map[string]string `long:"arg" description:"set a string value to a variable"`
74-
ArgJSON map[string]string `long:"argjson" description:"set a JSON value to a variable"`
75-
SlurpFile map[string]string `long:"slurpfile" description:"set the JSON contents of a file to a variable"`
76-
RawFile map[string]string `long:"rawfile" description:"set the contents of a file to a variable"`
72+
ModulePaths []string `short:"L" long:"library-path" args:"dir" description:"directory to search modules from"`
73+
Arg map[string]string `long:"arg" args:"name value" description:"set a string value to a variable"`
74+
ArgJSON map[string]string `long:"argjson" args:"name value" description:"set a JSON value to a variable"`
75+
SlurpFile map[string]string `long:"slurpfile" args:"name file" description:"set the JSON contents of a file to a variable"`
76+
RawFile map[string]string `long:"rawfile" args:"name file" description:"set the contents of a file to a variable"`
7777
Args []any `long:"args" positional:"" description:"consume remaining arguments as positional string values"`
7878
JSONArgs []any `long:"jsonargs" positional:"" description:"consume remaining arguments as positional JSON values"`
7979
ExitStatus bool `short:"e" long:"exit-status" description:"exit 1 when the last value is false or null"`

cli/flags.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,10 @@ func formatFlags(opts any) string {
186186
}
187187
sb.WriteString("--")
188188
sb.WriteString(flag)
189-
switch val.Field(i).Kind() {
190-
case reflect.Bool:
191-
sb.WriteString(" ")
192-
case reflect.Map:
193-
if strings.HasSuffix(flag, "file") {
194-
sb.WriteString(" name file")
195-
} else {
196-
sb.WriteString(" name value")
197-
}
198-
default:
199-
if _, ok = tag.Lookup("positional"); !ok {
200-
sb.WriteString("=")
201-
}
202-
}
203-
} else {
204-
sb.WriteString("=")
189+
}
190+
if args, ok := tag.Lookup("args"); ok {
191+
sb.WriteString(" ")
192+
sb.WriteString(args)
205193
}
206194
sb.WriteString(strings.Repeat(" ", 24-(sb.Len()-m)))
207195
sb.WriteString(tag.Get("description"))

cli/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7902,7 +7902,7 @@
79027902
- name: module directory option
79037903
args:
79047904
- -c
7905-
- -L
7905+
- --library-path
79067906
- 'testdata'
79077907
- 'import "7" as $foo; $foo, $foo::foo'
79087908
input: '0'
@@ -7913,7 +7913,7 @@
79137913
- name: module directory option
79147914
args:
79157915
- -c
7916-
- -L
7916+
- --library-path
79177917
- 'testdata'
79187918
- 'import "m1" as $x; $x, $x::x, $x[1].m1*100000000000000000000'
79197919
input: '0'

0 commit comments

Comments
 (0)