Skip to content

Commit d06adb0

Browse files
committed
fix(cli): rewrite zsh completion with proper state machine pattern
Use _arguments -C with state dispatch instead of manual CURRENT checking. Fixes flag completion not working after subcommand. Supports short flags (-p, -c, -o, -s, -f, -v, -r) alongside long.
1 parent e2e83a4 commit d06adb0

1 file changed

Lines changed: 61 additions & 57 deletions

File tree

completions/argus.zsh

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#compdef argus
22

33
# Zsh completion for argus CLI
4-
# Copy to a directory in your $fpath, or source directly:
4+
# Source this file or copy to a directory in $fpath:
55
# source completions/argus.zsh
66

77
_argus() {
@@ -25,67 +25,71 @@ _argus() {
2525
severity=(critical high medium low none)
2626
formats=(terminal markdown sarif json)
2727

28-
if (( CURRENT == 2 )); then
29-
_describe 'command' commands
30-
return
31-
fi
28+
_arguments -C \
29+
'--version[Show version]' \
30+
'--help[Show help]' \
31+
'1:command:->command' \
32+
'*::arg:->args'
3233

33-
case "${words[2]}" in
34-
scan)
35-
if (( CURRENT == 3 )) && [[ "${words[3]}" != -* ]]; then
36-
_describe 'scanner' scanners
37-
return
38-
fi
39-
_arguments \
40-
'--path[Path to scan]:path:_files -/' \
41-
'--config[Path to argus.yml]:config:_files' \
42-
'--output-dir[Output directory]:dir:_files -/' \
43-
'--severity-threshold[Fail threshold]:severity:($severity)' \
44-
'--format[Output format]:format:($formats)' \
45-
'--output-vars[Write counts to file]:file:_files' \
46-
'--list[List available scanners]' \
47-
'--verbose[Enable verbose output]' \
48-
'--no-spinner[Disable spinner]' \
49-
'--no-timestamp[Flat output directory]' \
50-
'--fail-fast[Abort on first failure]' \
51-
'--timeout[Per-scanner timeout]:seconds:' \
52-
'--image[Container image to scan]:image:' \
53-
'--discover[Discover Dockerfiles]:path:_files -/' \
54-
'--target[URL to scan]:url:' \
55-
'--scan-type[ZAP scan type]:type:(baseline full)'
34+
case "$state" in
35+
command)
36+
_describe 'command' commands
5637
;;
57-
report)
58-
if (( CURRENT == 3 )); then
59-
_describe 'format' formats
60-
return
61-
fi
62-
_arguments \
63-
'--results-dir[Results directory]:dir:_files -/' \
64-
'--output-dir[Output directory]:dir:_files -/' \
65-
'--verbose[Enable verbose output]'
66-
;;
67-
validate)
68-
_arguments \
69-
'--config[Path to argus.yml]:config:_files' \
70-
'--check-tools[Check scanner availability]' \
71-
'--strict[Treat warnings as errors]'
72-
;;
73-
init)
74-
_arguments \
75-
'--platform[Generate CI workflow]:platform:(github gitlab jenkins none)' \
76-
'--force[Overwrite existing config]' \
77-
'--no-detect[Skip auto-detection]'
78-
;;
79-
collect)
80-
_arguments \
81-
'1:input directory:_files -/' \
82-
'--output-dir[Output directory]:dir:_files -/' \
83-
'--verbose[Enable verbose output]'
38+
args)
39+
case "${words[1]}" in
40+
scan)
41+
_arguments \
42+
'1:scanner:($scanners)' \
43+
'(-p --path)'{-p,--path}'[Path to scan]:path:_files -/' \
44+
'(-c --config)'{-c,--config}'[Path to argus.yml]:config:_files' \
45+
'(-o --output-dir)'{-o,--output-dir}'[Output directory]:dir:_files -/' \
46+
'(-s --severity-threshold)'{-s,--severity-threshold}'[Fail threshold]:severity:($severity)' \
47+
'(-f --format)'{-f,--format}'[Output format]:format:($formats)' \
48+
'--output-vars[Write counts to file]:file:_files' \
49+
'--list[List available scanners]' \
50+
'(-v --verbose)'{-v,--verbose}'[Enable verbose output]' \
51+
'--no-spinner[Disable spinner]' \
52+
'--no-timestamp[Flat output directory]' \
53+
'--fail-fast[Abort on first failure]' \
54+
'--timeout[Per-scanner timeout]:seconds:' \
55+
'--image[Container image to scan]:image:' \
56+
'--discover[Discover Dockerfiles]:path:_files -/' \
57+
'--scanners[Sub-scanners for container]:scanners:' \
58+
'--target[URL to scan]:url:' \
59+
'--port[Override exposed port]:port:' \
60+
'--env[Environment variable]:env:' \
61+
'--scan-type[ZAP scan type]:type:(baseline full)' \
62+
'--startup-timeout[Target startup timeout]:seconds:'
63+
;;
64+
report)
65+
_arguments \
66+
'1:format:($formats)' \
67+
'(-r --results-dir)'{-r,--results-dir}'[Results directory]:dir:_files -/' \
68+
'(-o --output-dir)'{-o,--output-dir}'[Output directory]:dir:_files -/' \
69+
'(-v --verbose)'{-v,--verbose}'[Enable verbose output]'
70+
;;
71+
validate)
72+
_arguments \
73+
'(-c --config)'{-c,--config}'[Path to argus.yml]:config:_files' \
74+
'--check-tools[Check scanner availability]' \
75+
'--strict[Treat warnings as errors]'
76+
;;
77+
init)
78+
_arguments \
79+
'--platform[Generate CI workflow]:platform:(github gitlab jenkins none)' \
80+
'--force[Overwrite existing config]' \
81+
'--no-detect[Skip auto-detection]'
82+
;;
83+
collect)
84+
_arguments \
85+
'1:input directory:_files -/' \
86+
'(-o --output-dir)'{-o,--output-dir}'[Output directory]:dir:_files -/' \
87+
'(-v --verbose)'{-v,--verbose}'[Enable verbose output]'
88+
;;
89+
esac
8490
;;
8591
esac
8692
}
8793

88-
_argus "$@"
89-
9094
# Register when sourced directly (not via fpath)
9195
compdef _argus argus 2>/dev/null

0 commit comments

Comments
 (0)