Skip to content

Commit ce311cd

Browse files
committed
feat(completion): add missing flags and dynamic experimental feature detection
1 parent 1c86066 commit ce311cd

File tree

4 files changed

+110
-64
lines changed

4 files changed

+110
-64
lines changed

completion/bash/task.bash

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
_GO_TASK_COMPLETION_LIST_OPTION='--list-all'
44

5+
function _task_experiment_flags()
6+
{
7+
local flags=""
8+
local experiments=$(task --experiments 2>/dev/null)
9+
10+
if echo "$experiments" | grep -q "^\* GENTLE_FORCE:.*on"; then
11+
flags="$flags --force-all"
12+
fi
13+
14+
if echo "$experiments" | grep -q "^\* REMOTE_TASKFILES:.*on"; then
15+
flags="$flags --download --offline --timeout --clear-cache --expiry"
16+
fi
17+
18+
echo "$flags"
19+
}
20+
521
function _task()
622
{
723
local cur prev words cword
@@ -39,7 +55,7 @@ function _task()
3955
# Handle normal options.
4056
case "$cur" in
4157
-*)
42-
COMPREPLY=( $( compgen -W "$(_parse_help $1)" -- $cur ) )
58+
COMPREPLY=( $( compgen -W "$(_parse_help $1) $(_task_experiment_flags)" -- $cur ) )
4359
return 0
4460
;;
4561
esac

completion/fish/task.fish

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
set -l GO_TASK_PROGNAME task
22

3+
# Helper function to check if an experiment is enabled
4+
function __task_is_experiment_enabled
5+
set -l experiment $argv[1]
6+
task --experiments 2>/dev/null | string match -qr "^\* $experiment:.*on"
7+
end
8+
39
function __task_get_tasks --description "Prints all available tasks with their description" --inherit-variable GO_TASK_PROGNAME
410
# Check if the global task is requested
511
set -l global_task false
@@ -70,12 +76,15 @@ complete -c $GO_TASK_PROGNAME -l version -d 'show version
7076
complete -c $GO_TASK_PROGNAME -s w -l watch -d 'watch mode, re-run on changes'
7177
complete -c $GO_TASK_PROGNAME -s y -l yes -d 'assume yes to all prompts'
7278

73-
# Experimental flags (require experiments to be enabled)
74-
# GentleForce experiment:
75-
# complete -c $GO_TASK_PROGNAME -l force-all -d 'force execution of task and all dependencies'
76-
# RemoteTaskfiles experiment:
77-
# complete -c $GO_TASK_PROGNAME -l download -d 'download remote Taskfile'
78-
# complete -c $GO_TASK_PROGNAME -l offline -d 'use only local or cached Taskfiles'
79-
# complete -c $GO_TASK_PROGNAME -l timeout -d 'timeout for remote Taskfile downloads'
80-
# complete -c $GO_TASK_PROGNAME -l clear-cache -d 'clear remote Taskfile cache'
81-
# complete -c $GO_TASK_PROGNAME -l expiry -d 'cache expiry duration'
79+
# Experimental flags (dynamically added based on enabled experiments)
80+
if __task_is_experiment_enabled GENTLE_FORCE
81+
complete -c $GO_TASK_PROGNAME -l force-all -d 'force execution of task and all dependencies'
82+
end
83+
84+
if __task_is_experiment_enabled REMOTE_TASKFILES
85+
complete -c $GO_TASK_PROGNAME -l download -d 'download remote Taskfile'
86+
complete -c $GO_TASK_PROGNAME -l offline -d 'use only local or cached Taskfiles'
87+
complete -c $GO_TASK_PROGNAME -l timeout -d 'timeout for remote Taskfile downloads'
88+
complete -c $GO_TASK_PROGNAME -l clear-cache -d 'clear remote Taskfile cache'
89+
complete -c $GO_TASK_PROGNAME -l expiry -d 'cache expiry duration'
90+
end

completion/ps/task.ps1

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,23 @@ Register-ArgumentCompleter -CommandName task -ScriptBlock {
5858
[CompletionResult]::new('--watch', '--watch', [CompletionResultType]::ParameterName, 'watch mode'),
5959
[CompletionResult]::new('-y', '-y', [CompletionResultType]::ParameterName, 'assume yes'),
6060
[CompletionResult]::new('--yes', '--yes', [CompletionResultType]::ParameterName, 'assume yes')
61-
62-
# Experimental flags (uncomment when using experiments)
63-
# GentleForce experiment:
64-
# [CompletionResult]::new('--force-all', '--force-all', [CompletionResultType]::ParameterName, 'force all dependencies'),
65-
# RemoteTaskfiles experiment:
66-
# [CompletionResult]::new('--download', '--download', [CompletionResultType]::ParameterName, 'download remote Taskfile'),
67-
# [CompletionResult]::new('--offline', '--offline', [CompletionResultType]::ParameterName, 'use cached Taskfiles'),
68-
# [CompletionResult]::new('--timeout', '--timeout', [CompletionResultType]::ParameterName, 'download timeout'),
69-
# [CompletionResult]::new('--clear-cache', '--clear-cache', [CompletionResultType]::ParameterName, 'clear cache'),
70-
# [CompletionResult]::new('--expiry', '--expiry', [CompletionResultType]::ParameterName, 'cache expiry')
7161
)
7262

63+
# Experimental flags (dynamically added based on enabled experiments)
64+
$experiments = & task --experiments 2>$null | Out-String
65+
66+
if ($experiments -match '\* GENTLE_FORCE:.*on') {
67+
$completions += [CompletionResult]::new('--force-all', '--force-all', [CompletionResultType]::ParameterName, 'force all dependencies')
68+
}
69+
70+
if ($experiments -match '\* REMOTE_TASKFILES:.*on') {
71+
$completions += [CompletionResult]::new('--download', '--download', [CompletionResultType]::ParameterName, 'download remote Taskfile')
72+
$completions += [CompletionResult]::new('--offline', '--offline', [CompletionResultType]::ParameterName, 'use cached Taskfiles')
73+
$completions += [CompletionResult]::new('--timeout', '--timeout', [CompletionResultType]::ParameterName, 'download timeout')
74+
$completions += [CompletionResult]::new('--clear-cache', '--clear-cache', [CompletionResultType]::ParameterName, 'clear cache')
75+
$completions += [CompletionResult]::new('--expiry', '--expiry', [CompletionResultType]::ParameterName, 'cache expiry')
76+
}
77+
7378
return $completions.Where{ $_.CompletionText.StartsWith($commandName) }
7479
}
7580

completion/zsh/_task

Lines changed: 60 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ typeset -A opt_args
44

55
_GO_TASK_COMPLETION_LIST_OPTION="${GO_TASK_COMPLETION_LIST_OPTION:---list-all}"
66

7+
# Check if an experiment is enabled
8+
function __task_is_experiment_enabled() {
9+
local experiment=$1
10+
task --experiments 2>/dev/null | grep -q "^\* ${experiment}:.*on"
11+
}
12+
713
# Listing commands from Taskfile.yml
814
function __task_list() {
915
local -a scripts cmd
@@ -36,51 +42,61 @@ function __task_list() {
3642
}
3743

3844
_task() {
39-
_arguments \
40-
'(-C --concurrency)'{-C,--concurrency}'[limit number of concurrent tasks]: ' \
41-
'(-p --parallel)'{-p,--parallel}'[run command-line tasks in parallel]' \
42-
'(-f --force)'{-f,--force}'[run even if task is up-to-date]' \
43-
'(-c --color)'{-c,--color}'[colored output]' \
44-
'(--completion)--completion[generate shell completion script]:shell:(bash zsh fish powershell)' \
45-
'(-d --dir)'{-d,--dir}'[dir to run in]:execution dir:_dirs' \
46-
'(-n --dry)'{-n,--dry}'[compiles and prints tasks without executing]' \
47-
'(--dry)--dry[dry-run mode, compile and print tasks only]' \
48-
'(-x --exit-code)'{-x,--exit-code}'[pass-through exit code of task command]' \
49-
'(--experiments)--experiments[list available experiments]' \
50-
'(-g --global)'{-g,--global}'[run global Taskfile from home directory]' \
51-
'(--insecure)--insecure[allow insecure Taskfile downloads]' \
52-
'(-I --interval)'{-I,--interval}'[interval to watch for changes]:duration: ' \
53-
'(-j --json)'{-j,--json}'[format task list as JSON]' \
54-
'(--nested)--nested[nest namespaces when listing as JSON]' \
55-
'(--no-status)--no-status[ignore status when listing as JSON]' \
56-
'(-o --output)'{-o,--output}'[set output style]:style:(interleaved group prefixed)' \
57-
'(--output-group-begin)--output-group-begin[message template before grouped output]:template text: ' \
58-
'(--output-group-end)--output-group-end[message template after grouped output]:template text: ' \
59-
'(--output-group-error-only)--output-group-error-only[hide output from successful tasks]' \
60-
'(-s --silent)'{-s,--silent}'[disable echoing]' \
61-
'(--sort)--sort[set task sorting order]:order:(default alphanumeric none)' \
62-
'(--status)--status[exit non-zero if supplied tasks not up-to-date]' \
63-
'(--summary)--summary[show summary\: field from tasks instead of running them]' \
64-
'(-t --taskfile)'{-t,--taskfile}'[specify a different taskfile]:taskfile:_files' \
65-
'(-v --verbose)'{-v,--verbose}'[verbose mode]' \
66-
'(-w --watch)'{-w,--watch}'[watch-mode for given tasks, re-run when inputs change]' \
67-
'(-y --yes)'{-y,--yes}'[assume yes to all prompts]' \
68-
+ '(operation)' \
69-
{-l,--list}'[list describable tasks]' \
70-
{-a,--list-all}'[list all tasks]' \
71-
{-i,--init}'[create new Taskfile.yml]' \
72-
'(-*)'{-h,--help}'[show help]' \
73-
'(-*)--version[show version and exit]' \
45+
local -a args
46+
args=(
47+
'(-C --concurrency)'{-C,--concurrency}'[limit number of concurrent tasks]: '
48+
'(-p --parallel)'{-p,--parallel}'[run command-line tasks in parallel]'
49+
'(-f --force)'{-f,--force}'[run even if task is up-to-date]'
50+
'(-c --color)'{-c,--color}'[colored output]'
51+
'(--completion)--completion[generate shell completion script]:shell:(bash zsh fish powershell)'
52+
'(-d --dir)'{-d,--dir}'[dir to run in]:execution dir:_dirs'
53+
'(-n --dry)'{-n,--dry}'[compiles and prints tasks without executing]'
54+
'(--dry)--dry[dry-run mode, compile and print tasks only]'
55+
'(-x --exit-code)'{-x,--exit-code}'[pass-through exit code of task command]'
56+
'(--experiments)--experiments[list available experiments]'
57+
'(-g --global)'{-g,--global}'[run global Taskfile from home directory]'
58+
'(--insecure)--insecure[allow insecure Taskfile downloads]'
59+
'(-I --interval)'{-I,--interval}'[interval to watch for changes]:duration: '
60+
'(-j --json)'{-j,--json}'[format task list as JSON]'
61+
'(--nested)--nested[nest namespaces when listing as JSON]'
62+
'(--no-status)--no-status[ignore status when listing as JSON]'
63+
'(-o --output)'{-o,--output}'[set output style]:style:(interleaved group prefixed)'
64+
'(--output-group-begin)--output-group-begin[message template before grouped output]:template text: '
65+
'(--output-group-end)--output-group-end[message template after grouped output]:template text: '
66+
'(--output-group-error-only)--output-group-error-only[hide output from successful tasks]'
67+
'(-s --silent)'{-s,--silent}'[disable echoing]'
68+
'(--sort)--sort[set task sorting order]:order:(default alphanumeric none)'
69+
'(--status)--status[exit non-zero if supplied tasks not up-to-date]'
70+
'(--summary)--summary[show summary\: field from tasks instead of running them]'
71+
'(-t --taskfile)'{-t,--taskfile}'[specify a different taskfile]:taskfile:_files'
72+
'(-v --verbose)'{-v,--verbose}'[verbose mode]'
73+
'(-w --watch)'{-w,--watch}'[watch-mode for given tasks, re-run when inputs change]'
74+
'(-y --yes)'{-y,--yes}'[assume yes to all prompts]'
75+
+ '(operation)'
76+
{-l,--list}'[list describable tasks]'
77+
{-a,--list-all}'[list all tasks]'
78+
{-i,--init}'[create new Taskfile.yml]'
79+
'(-*)'{-h,--help}'[show help]'
80+
'(-*)--version[show version and exit]'
7481
'*: :__task_list'
75-
# Experimental flags (require experiments to be enabled)
76-
# Uncomment when using GentleForce experiment:
77-
# '(--force-all)--force-all[force execution of task and all dependencies]'
78-
# Uncomment when using RemoteTaskfiles experiment:
79-
# '(--download)--download[download remote Taskfile]'
80-
# '(--offline)--offline[use only local or cached Taskfiles]'
81-
# '(--timeout)--timeout[timeout for remote Taskfile downloads]:duration: '
82-
# '(--clear-cache)--clear-cache[clear remote Taskfile cache]'
83-
# '(--expiry)--expiry[cache expiry duration]:duration: '
82+
)
83+
84+
# Experimental flags (dynamically added based on enabled experiments)
85+
if __task_is_experiment_enabled "GENTLE_FORCE"; then
86+
args+=('(--force-all)--force-all[force execution of task and all dependencies]')
87+
fi
88+
89+
if __task_is_experiment_enabled "REMOTE_TASKFILES"; then
90+
args+=(
91+
'(--download)--download[download remote Taskfile]'
92+
'(--offline)--offline[use only local or cached Taskfiles]'
93+
'(--timeout)--timeout[timeout for remote Taskfile downloads]:duration: '
94+
'(--clear-cache)--clear-cache[clear remote Taskfile cache]'
95+
'(--expiry)--expiry[cache expiry duration]:duration: '
96+
)
97+
fi
98+
99+
_arguments $args
84100
}
85101

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

0 commit comments

Comments
 (0)