mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
f70ebe89a7
Before we introduced actions, it required specific setups to engage with claps version and help printing. With actions making that more explicit, we don't get as much benefit from our multiple, obscure, ways of users customizing help Before - Modify existing help or version with `mut_arg` which would automatically be pushed down the command tree like `global(true)` - Create an new help or version and have it treated as if it was the built-in on (I think) - Use the same flags as built-in and have the built-in flags automatically disabled - Users could explicitly disable the built-in functionality and do what they want Now - `mut_arg` no longer works as we define help and version flags at the end - If someone defines a flag that overlaps with the built-ins by id, long, or short, a debug assert will tell them to explicitly disable the built-in - Any customization has to be done by a user providing their own. To propagate through the command tree, they need to set `global(true)`. Benefits - Hopefully, this makes it less confusing on how to override help behavior. Someone creates an arg and we then tell them how to disable the built-in - This greatly simplifies the arg handling by pushing more responsibility onto the developer in what are hopefully just corner cases - This removes about 1Kb from .text Fixes #3405 Fixes #4033
61 lines
2 KiB
Text
61 lines
2 KiB
Text
|
|
use builtin;
|
|
use str;
|
|
|
|
set edit:completion:arg-completer[my-app] = {|@words|
|
|
fn spaces {|n|
|
|
builtin:repeat $n ' ' | str:join ''
|
|
}
|
|
fn cand {|text desc|
|
|
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
|
|
}
|
|
var command = 'my-app'
|
|
for word $words[1..-1] {
|
|
if (str:has-prefix $word '-') {
|
|
break
|
|
}
|
|
set command = $command';'$word
|
|
}
|
|
var completions = [
|
|
&'my-app'= {
|
|
cand -c 'some config file'
|
|
cand -C 'some config file'
|
|
cand --config 'some config file'
|
|
cand --conf 'some config file'
|
|
cand -h 'Print help information'
|
|
cand --help 'Print help information'
|
|
cand -V 'Print version information'
|
|
cand --version 'Print version information'
|
|
cand test 'tests things'
|
|
cand some_cmd 'top level subcommand'
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
}
|
|
&'my-app;test'= {
|
|
cand --case 'the case to test'
|
|
cand -h 'Print help information'
|
|
cand --help 'Print help information'
|
|
cand -V 'Print version information'
|
|
cand --version 'Print version information'
|
|
}
|
|
&'my-app;some_cmd'= {
|
|
cand -h 'Print help information'
|
|
cand --help 'Print help information'
|
|
cand -V 'Print version information'
|
|
cand --version 'Print version information'
|
|
cand sub_cmd 'sub-subcommand'
|
|
cand help 'Print this message or the help of the given subcommand(s)'
|
|
}
|
|
&'my-app;some_cmd;sub_cmd'= {
|
|
cand --config 'the other case to test'
|
|
cand -h 'Print help information'
|
|
cand --help 'Print help information'
|
|
cand -V 'Print version information'
|
|
cand --version 'Print version information'
|
|
}
|
|
&'my-app;some_cmd;help'= {
|
|
}
|
|
&'my-app;help'= {
|
|
}
|
|
]
|
|
$completions[$command]
|
|
}
|