Skip to content

Commit 5aa8b4b

Browse files
committed
keep the runtime completions generation
1 parent 3c35879 commit 5aa8b4b

File tree

9 files changed

+271
-36
lines changed

9 files changed

+271
-36
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ license = "Unlicense"
1313
[dependencies]
1414
anyhow = "1.*"
1515
clap = { version = "4.0.26", features = ["derive"] }
16+
clap_complete = "4.0.5"
17+
clap_complete_nushell = "0.1.10"
1618
crossterm = "0.25.0"
1719
diff = "0.1.*"
1820
handlebars = { version = "4.*", features = ["script_helper"] }

completions/_dotter

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,30 @@ _arguments "${_arguments_options[@]}" \
139139
'--help[Print help information]' \
140140
&& ret=0
141141
;;
142+
(gen-completions)
143+
_arguments "${_arguments_options[@]}" \
144+
'-s+[Set the shell for generating completions \[values: bash, elvish, fish, powershell, zsh, nushell\]]:SHELL:(bash elvish fish powershell zsh nushell)' \
145+
'--shell=[Set the shell for generating completions \[values: bash, elvish, fish, powershell, zsh, nushell\]]:SHELL:(bash elvish fish powershell zsh nushell)' \
146+
'-g+[Location of the global configuration]:GLOBAL_CONFIG:_files' \
147+
'--global-config=[Location of the global configuration]:GLOBAL_CONFIG:_files' \
148+
'-l+[Location of the local configuration]:LOCAL_CONFIG:_files' \
149+
'--local-config=[Location of the local configuration]:LOCAL_CONFIG:_files' \
150+
'-d[Dry run - don'\''t do anything, only print information. Implies -v at least once]' \
151+
'--dry-run[Dry run - don'\''t do anything, only print information. Implies -v at least once]' \
152+
'*-v[Verbosity level - specify up to 3 times to get more detailed output. Specifying at least once prints the differences between what was before and after Dotter'\''s run]' \
153+
'*--verbose[Verbosity level - specify up to 3 times to get more detailed output. Specifying at least once prints the differences between what was before and after Dotter'\''s run]' \
154+
'-q[Quiet - only print errors]' \
155+
'--quiet[Quiet - only print errors]' \
156+
'-f[Force - instead of skipping, overwrite target files if their content is unexpected. Overrides --dry-run]' \
157+
'--force[Force - instead of skipping, overwrite target files if their content is unexpected. Overrides --dry-run]' \
158+
'-y[Assume "yes" instead of prompting when removing empty directories]' \
159+
'--noconfirm[Assume "yes" instead of prompting when removing empty directories]' \
160+
'-p[Take standard input as an additional files/variables patch, added after evaluating `local.toml`. Assumes --noconfirm flag because all of stdin is taken as the patch]' \
161+
'--patch[Take standard input as an additional files/variables patch, added after evaluating `local.toml`. Assumes --noconfirm flag because all of stdin is taken as the patch]' \
162+
'-h[Print help information]' \
163+
'--help[Print help information]' \
164+
&& ret=0
165+
;;
142166
(help)
143167
_arguments "${_arguments_options[@]}" \
144168
":: :_dotter__help_commands" \
@@ -167,6 +191,10 @@ _arguments "${_arguments_options[@]}" \
167191
_arguments "${_arguments_options[@]}" \
168192
&& ret=0
169193
;;
194+
(gen-completions)
195+
_arguments "${_arguments_options[@]}" \
196+
&& ret=0
197+
;;
170198
(help)
171199
_arguments "${_arguments_options[@]}" \
172200
&& ret=0
@@ -187,6 +215,7 @@ _dotter_commands() {
187215
'undeploy:Delete all deployed files from their target locations. Note that this operates on all files that are currently in cache' \
188216
'init:Initialize global.toml with a single package containing all the files in the current directory pointing to a dummy value and a local.toml that selects that package' \
189217
'watch:Run continuously, watching the repository for changes and deploying as soon as they happen. Can be ran with `--dry-run`' \
218+
'gen-completions:Generate shell completions' \
190219
'help:Print this message or the help of the given subcommand(s)' \
191220
)
192221
_describe -t commands 'dotter commands' commands "$@"
@@ -201,13 +230,24 @@ _dotter__help__deploy_commands() {
201230
local commands; commands=()
202231
_describe -t commands 'dotter help deploy commands' commands "$@"
203232
}
233+
(( $+functions[_dotter__gen-completions_commands] )) ||
234+
_dotter__gen-completions_commands() {
235+
local commands; commands=()
236+
_describe -t commands 'dotter gen-completions commands' commands "$@"
237+
}
238+
(( $+functions[_dotter__help__gen-completions_commands] )) ||
239+
_dotter__help__gen-completions_commands() {
240+
local commands; commands=()
241+
_describe -t commands 'dotter help gen-completions commands' commands "$@"
242+
}
204243
(( $+functions[_dotter__help_commands] )) ||
205244
_dotter__help_commands() {
206245
local commands; commands=(
207246
'deploy:Deploy the files to their respective targets. This is the default subcommand' \
208247
'undeploy:Delete all deployed files from their target locations. Note that this operates on all files that are currently in cache' \
209248
'init:Initialize global.toml with a single package containing all the files in the current directory pointing to a dummy value and a local.toml that selects that package' \
210249
'watch:Run continuously, watching the repository for changes and deploying as soon as they happen. Can be ran with `--dry-run`' \
250+
'gen-completions:Generate shell completions' \
211251
'help:Print this message or the help of the given subcommand(s)' \
212252
)
213253
_describe -t commands 'dotter help commands' commands "$@"

completions/_dotter.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Register-ArgumentCompleter -Native -CommandName 'dotter' -ScriptBlock {
5252
[CompletionResult]::new('undeploy', 'undeploy', [CompletionResultType]::ParameterValue, 'Delete all deployed files from their target locations. Note that this operates on all files that are currently in cache')
5353
[CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Initialize global.toml with a single package containing all the files in the current directory pointing to a dummy value and a local.toml that selects that package')
5454
[CompletionResult]::new('watch', 'watch', [CompletionResultType]::ParameterValue, 'Run continuously, watching the repository for changes and deploying as soon as they happen. Can be ran with `--dry-run`')
55+
[CompletionResult]::new('gen-completions', 'gen-completions', [CompletionResultType]::ParameterValue, 'Generate shell completions')
5556
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
5657
break
5758
}
@@ -139,11 +140,35 @@ Register-ArgumentCompleter -Native -CommandName 'dotter' -ScriptBlock {
139140
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information')
140141
break
141142
}
143+
'dotter;gen-completions' {
144+
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Set the shell for generating completions [values: bash, elvish, fish, powershell, zsh, nushell]')
145+
[CompletionResult]::new('--shell', 'shell', [CompletionResultType]::ParameterName, 'Set the shell for generating completions [values: bash, elvish, fish, powershell, zsh, nushell]')
146+
[CompletionResult]::new('-g', 'g', [CompletionResultType]::ParameterName, 'Location of the global configuration')
147+
[CompletionResult]::new('--global-config', 'global-config', [CompletionResultType]::ParameterName, 'Location of the global configuration')
148+
[CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'Location of the local configuration')
149+
[CompletionResult]::new('--local-config', 'local-config', [CompletionResultType]::ParameterName, 'Location of the local configuration')
150+
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Dry run - don''t do anything, only print information. Implies -v at least once')
151+
[CompletionResult]::new('--dry-run', 'dry-run', [CompletionResultType]::ParameterName, 'Dry run - don''t do anything, only print information. Implies -v at least once')
152+
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Verbosity level - specify up to 3 times to get more detailed output. Specifying at least once prints the differences between what was before and after Dotter''s run')
153+
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Verbosity level - specify up to 3 times to get more detailed output. Specifying at least once prints the differences between what was before and after Dotter''s run')
154+
[CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Quiet - only print errors')
155+
[CompletionResult]::new('--quiet', 'quiet', [CompletionResultType]::ParameterName, 'Quiet - only print errors')
156+
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Force - instead of skipping, overwrite target files if their content is unexpected. Overrides --dry-run')
157+
[CompletionResult]::new('--force', 'force', [CompletionResultType]::ParameterName, 'Force - instead of skipping, overwrite target files if their content is unexpected. Overrides --dry-run')
158+
[CompletionResult]::new('-y', 'y', [CompletionResultType]::ParameterName, 'Assume "yes" instead of prompting when removing empty directories')
159+
[CompletionResult]::new('--noconfirm', 'noconfirm', [CompletionResultType]::ParameterName, 'Assume "yes" instead of prompting when removing empty directories')
160+
[CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Take standard input as an additional files/variables patch, added after evaluating `local.toml`. Assumes --noconfirm flag because all of stdin is taken as the patch')
161+
[CompletionResult]::new('--patch', 'patch', [CompletionResultType]::ParameterName, 'Take standard input as an additional files/variables patch, added after evaluating `local.toml`. Assumes --noconfirm flag because all of stdin is taken as the patch')
162+
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information')
163+
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information')
164+
break
165+
}
142166
'dotter;help' {
143167
[CompletionResult]::new('deploy', 'deploy', [CompletionResultType]::ParameterValue, 'Deploy the files to their respective targets. This is the default subcommand')
144168
[CompletionResult]::new('undeploy', 'undeploy', [CompletionResultType]::ParameterValue, 'Delete all deployed files from their target locations. Note that this operates on all files that are currently in cache')
145169
[CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Initialize global.toml with a single package containing all the files in the current directory pointing to a dummy value and a local.toml that selects that package')
146170
[CompletionResult]::new('watch', 'watch', [CompletionResultType]::ParameterValue, 'Run continuously, watching the repository for changes and deploying as soon as they happen. Can be ran with `--dry-run`')
171+
[CompletionResult]::new('gen-completions', 'gen-completions', [CompletionResultType]::ParameterValue, 'Generate shell completions')
147172
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
148173
break
149174
}
@@ -159,6 +184,9 @@ Register-ArgumentCompleter -Native -CommandName 'dotter' -ScriptBlock {
159184
'dotter;help;watch' {
160185
break
161186
}
187+
'dotter;help;gen-completions' {
188+
break
189+
}
162190
'dotter;help;help' {
163191
break
164192
}

completions/dotter.bash

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ _dotter() {
1515
dotter,deploy)
1616
cmd="dotter__deploy"
1717
;;
18+
dotter,gen-completions)
19+
cmd="dotter__gen__completions"
20+
;;
1821
dotter,help)
1922
cmd="dotter__help"
2023
;;
@@ -30,6 +33,9 @@ _dotter() {
3033
dotter__help,deploy)
3134
cmd="dotter__help__deploy"
3235
;;
36+
dotter__help,gen-completions)
37+
cmd="dotter__help__gen__completions"
38+
;;
3339
dotter__help,help)
3440
cmd="dotter__help__help"
3541
;;
@@ -49,7 +55,7 @@ _dotter() {
4955

5056
case "${cmd}" in
5157
dotter)
52-
opts="-g -l -d -v -q -f -y -p -h -V --global-config --local-config --cache-file --cache-directory --pre-deploy --post-deploy --pre-undeploy --post-undeploy --dry-run --verbose --quiet --force --noconfirm --patch --diff-context-lines --help --version deploy undeploy init watch help"
58+
opts="-g -l -d -v -q -f -y -p -h -V --global-config --local-config --cache-file --cache-directory --pre-deploy --post-deploy --pre-undeploy --post-undeploy --dry-run --verbose --quiet --force --noconfirm --patch --diff-context-lines --help --version deploy undeploy init watch gen-completions help"
5359
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
5460
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
5561
return 0
@@ -136,8 +142,46 @@ _dotter() {
136142
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
137143
return 0
138144
;;
145+
dotter__gen__completions)
146+
opts="-s -g -l -d -v -q -f -y -p -h --shell --global-config --local-config --dry-run --verbose --quiet --force --noconfirm --patch --help"
147+
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
148+
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
149+
return 0
150+
fi
151+
case "${prev}" in
152+
--shell)
153+
COMPREPLY=($(compgen -W "bash elvish fish powershell zsh nushell" -- "${cur}"))
154+
return 0
155+
;;
156+
-s)
157+
COMPREPLY=($(compgen -W "bash elvish fish powershell zsh nushell" -- "${cur}"))
158+
return 0
159+
;;
160+
--global-config)
161+
COMPREPLY=($(compgen -f "${cur}"))
162+
return 0
163+
;;
164+
-g)
165+
COMPREPLY=($(compgen -f "${cur}"))
166+
return 0
167+
;;
168+
--local-config)
169+
COMPREPLY=($(compgen -f "${cur}"))
170+
return 0
171+
;;
172+
-l)
173+
COMPREPLY=($(compgen -f "${cur}"))
174+
return 0
175+
;;
176+
*)
177+
COMPREPLY=()
178+
;;
179+
esac
180+
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
181+
return 0
182+
;;
139183
dotter__help)
140-
opts="deploy undeploy init watch help"
184+
opts="deploy undeploy init watch gen-completions help"
141185
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
142186
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
143187
return 0
@@ -164,6 +208,20 @@ _dotter() {
164208
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
165209
return 0
166210
;;
211+
dotter__help__gen__completions)
212+
opts=""
213+
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
214+
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
215+
return 0
216+
fi
217+
case "${prev}" in
218+
*)
219+
COMPREPLY=()
220+
;;
221+
esac
222+
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
223+
return 0
224+
;;
167225
dotter__help__help)
168226
opts=""
169227
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then

completions/dotter.elv

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set edit:completion:arg-completer[dotter] = {|@words|
4949
cand undeploy 'Delete all deployed files from their target locations. Note that this operates on all files that are currently in cache'
5050
cand init 'Initialize global.toml with a single package containing all the files in the current directory pointing to a dummy value and a local.toml that selects that package'
5151
cand watch 'Run continuously, watching the repository for changes and deploying as soon as they happen. Can be ran with `--dry-run`'
52+
cand gen-completions 'Generate shell completions'
5253
cand help 'Print this message or the help of the given subcommand(s)'
5354
}
5455
&'dotter;deploy'= {
@@ -131,11 +132,34 @@ set edit:completion:arg-completer[dotter] = {|@words|
131132
cand -h 'Print help information'
132133
cand --help 'Print help information'
133134
}
135+
&'dotter;gen-completions'= {
136+
cand -s 'Set the shell for generating completions [values: bash, elvish, fish, powershell, zsh, nushell]'
137+
cand --shell 'Set the shell for generating completions [values: bash, elvish, fish, powershell, zsh, nushell]'
138+
cand -g 'Location of the global configuration'
139+
cand --global-config 'Location of the global configuration'
140+
cand -l 'Location of the local configuration'
141+
cand --local-config 'Location of the local configuration'
142+
cand -d 'Dry run - don''t do anything, only print information. Implies -v at least once'
143+
cand --dry-run 'Dry run - don''t do anything, only print information. Implies -v at least once'
144+
cand -v 'Verbosity level - specify up to 3 times to get more detailed output. Specifying at least once prints the differences between what was before and after Dotter''s run'
145+
cand --verbose 'Verbosity level - specify up to 3 times to get more detailed output. Specifying at least once prints the differences between what was before and after Dotter''s run'
146+
cand -q 'Quiet - only print errors'
147+
cand --quiet 'Quiet - only print errors'
148+
cand -f 'Force - instead of skipping, overwrite target files if their content is unexpected. Overrides --dry-run'
149+
cand --force 'Force - instead of skipping, overwrite target files if their content is unexpected. Overrides --dry-run'
150+
cand -y 'Assume "yes" instead of prompting when removing empty directories'
151+
cand --noconfirm 'Assume "yes" instead of prompting when removing empty directories'
152+
cand -p 'Take standard input as an additional files/variables patch, added after evaluating `local.toml`. Assumes --noconfirm flag because all of stdin is taken as the patch'
153+
cand --patch 'Take standard input as an additional files/variables patch, added after evaluating `local.toml`. Assumes --noconfirm flag because all of stdin is taken as the patch'
154+
cand -h 'Print help information'
155+
cand --help 'Print help information'
156+
}
134157
&'dotter;help'= {
135158
cand deploy 'Deploy the files to their respective targets. This is the default subcommand'
136159
cand undeploy 'Delete all deployed files from their target locations. Note that this operates on all files that are currently in cache'
137160
cand init 'Initialize global.toml with a single package containing all the files in the current directory pointing to a dummy value and a local.toml that selects that package'
138161
cand watch 'Run continuously, watching the repository for changes and deploying as soon as they happen. Can be ran with `--dry-run`'
162+
cand gen-completions 'Generate shell completions'
139163
cand help 'Print this message or the help of the given subcommand(s)'
140164
}
141165
&'dotter;help;deploy'= {
@@ -146,6 +170,8 @@ set edit:completion:arg-completer[dotter] = {|@words|
146170
}
147171
&'dotter;help;watch'= {
148172
}
173+
&'dotter;help;gen-completions'= {
174+
}
149175
&'dotter;help;help'= {
150176
}
151177
]

0 commit comments

Comments
 (0)