diff --git a/completion/fish/task.fish b/completion/fish/task.fish index 3b7683fe02..a6797ed8be 100644 --- a/completion/fish/task.fish +++ b/completion/fish/task.fish @@ -60,8 +60,10 @@ function __task_get_tasks --description "Prints all available tasks with their d end end -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 -specified.' -xa "(__task_get_tasks)" +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 specified.' \ + -xa "(__task_get_tasks)" \ + -n "not __fish_seen_subcommand_from --" # Standard flags complete -c $GO_TASK_PROGNAME -s a -l list-all -d 'list all tasks' diff --git a/completion/zsh/_task b/completion/zsh/_task index 08670531a9..d6e0aa61da 100755 --- a/completion/zsh/_task +++ b/completion/zsh/_task @@ -20,6 +20,13 @@ function __task_list() { taskfile=${(Qv)opt_args[(i)-t|--taskfile]} taskfile=${taskfile//\~/$HOME} + for arg in "${words[@]:0:$CURRENT}"; do + if [[ "$arg" = "--" ]]; then + # Use default completion for words after `--` as they are CLI_ARGS. + _default + return 0 + fi + done if [[ -n "$taskfile" && -f "$taskfile" ]]; then cmd+=(--taskfile "$taskfile") @@ -83,33 +90,35 @@ _task() { if __task_is_experiment_enabled "REMOTE_TASKFILES"; then standard_args+=( - '(--offline)--offline[use only local or cached Taskfiles]' + '(--offline --download)--offline[use only local or cached Taskfiles]' '(--timeout)--timeout[timeout for remote Taskfile downloads]:duration: ' '(--expiry)--expiry[cache expiry duration]:duration: ' ) fi operation_args=( + # Task names completion (can be specified multiple times) + '(operation)*: :__task_list' + # Operational args completion (mutually exclusive) + '(operation)' - {-l,--list}'[list describable tasks]' - {-a,--list-all}'[list all tasks]' - {-i,--init}'[create new Taskfile.yml]' - '(-*)'{-h,--help}'[show help]' - '(-*)--version[show version and exit]' + '(*)'{-l,--list}'[list describable tasks]' + '(*)'{-a,--list-all}'[list all tasks]' + '(*)'{-i,--init}'[create new Taskfile.yml]' + '(- *)'{-h,--help}'[show help]' + '(- *)--version[show version and exit]' ) # Experimental operations (dynamically added based on enabled experiments) if __task_is_experiment_enabled "REMOTE_TASKFILES"; then + standard_args+=( + '(--offline --clear-cache)--download[download remote Taskfile]' + ) operation_args+=( - '--download[download remote Taskfile]' - '--clear-cache[clear remote Taskfile cache]' + '(* --download)--clear-cache[clear remote Taskfile cache]' ) fi - # Task names completion (must be last) - operation_args+=('*: :__task_list') - - _arguments $standard_args $operation_args + _arguments -S $standard_args $operation_args } # don't run the completion function when being source-ed or eval-ed