Skip to content

Commit f0b15d3

Browse files
fix: CLI_ARGS completion for fish and zsh (#1844)
1 parent eb285fa commit f0b15d3

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

completion/fish/task.fish

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ function __task_get_tasks --description "Prints all available tasks with their d
6060
end
6161
end
6262

63-
complete -c $GO_TASK_PROGNAME -d 'Runs the specified task(s). Falls back to the "default" task if no task name was specified, or lists all tasks if an unknown task name was
64-
specified.' -xa "(__task_get_tasks)"
63+
complete -c $GO_TASK_PROGNAME \
64+
-d 'Runs the specified task(s). Falls back to the "default" task if no task name was specified, or lists all tasks if an unknown task name was specified.' \
65+
-xa "(__task_get_tasks)" \
66+
-n "not __fish_seen_subcommand_from --"
6567

6668
# Standard flags
6769
complete -c $GO_TASK_PROGNAME -s a -l list-all -d 'list all tasks'

completion/zsh/_task

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ function __task_list() {
2020
taskfile=${(Qv)opt_args[(i)-t|--taskfile]}
2121
taskfile=${taskfile//\~/$HOME}
2222

23+
for arg in "${words[@]:0:$CURRENT}"; do
24+
if [[ "$arg" = "--" ]]; then
25+
# Use default completion for words after `--` as they are CLI_ARGS.
26+
_default
27+
return 0
28+
fi
29+
done
2330

2431
if [[ -n "$taskfile" && -f "$taskfile" ]]; then
2532
cmd+=(--taskfile "$taskfile")
@@ -83,33 +90,35 @@ _task() {
8390

8491
if __task_is_experiment_enabled "REMOTE_TASKFILES"; then
8592
standard_args+=(
86-
'(--offline)--offline[use only local or cached Taskfiles]'
93+
'(--offline --download)--offline[use only local or cached Taskfiles]'
8794
'(--timeout)--timeout[timeout for remote Taskfile downloads]:duration: '
8895
'(--expiry)--expiry[cache expiry duration]:duration: '
8996
)
9097
fi
9198

9299
operation_args=(
100+
# Task names completion (can be specified multiple times)
101+
'(operation)*: :__task_list'
102+
# Operational args completion (mutually exclusive)
93103
+ '(operation)'
94-
{-l,--list}'[list describable tasks]'
95-
{-a,--list-all}'[list all tasks]'
96-
{-i,--init}'[create new Taskfile.yml]'
97-
'(-*)'{-h,--help}'[show help]'
98-
'(-*)--version[show version and exit]'
104+
'(*)'{-l,--list}'[list describable tasks]'
105+
'(*)'{-a,--list-all}'[list all tasks]'
106+
'(*)'{-i,--init}'[create new Taskfile.yml]'
107+
'(- *)'{-h,--help}'[show help]'
108+
'(- *)--version[show version and exit]'
99109
)
100110

101111
# Experimental operations (dynamically added based on enabled experiments)
102112
if __task_is_experiment_enabled "REMOTE_TASKFILES"; then
113+
standard_args+=(
114+
'(--offline --clear-cache)--download[download remote Taskfile]'
115+
)
103116
operation_args+=(
104-
'--download[download remote Taskfile]'
105-
'--clear-cache[clear remote Taskfile cache]'
117+
'(* --download)--clear-cache[clear remote Taskfile cache]'
106118
)
107119
fi
108120

109-
# Task names completion (must be last)
110-
operation_args+=('*: :__task_list')
111-
112-
_arguments $standard_args $operation_args
121+
_arguments -S $standard_args $operation_args
113122
}
114123

115124
# don't run the completion function when being source-ed or eval-ed

0 commit comments

Comments
 (0)