mirror of
https://github.com/clap-rs/clap
synced 2024-12-12 13:52:34 +00:00
fix(complete): Fix help completion issues
* Copy hide flag * Revert global args special handling. Another commit will address the issue of whether global args should be included in help subtrees.
This commit is contained in:
parent
729406661c
commit
0d0be51606
9 changed files with 22 additions and 15 deletions
|
@ -53,7 +53,7 @@ _my-app() {
|
|||
return 0
|
||||
;;
|
||||
my__app__help__help)
|
||||
opts=""
|
||||
opts="-c"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
@ -67,7 +67,7 @@ _my-app() {
|
|||
return 0
|
||||
;;
|
||||
my__app__help__test)
|
||||
opts=""
|
||||
opts="-c"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
|
|
|
@ -37,8 +37,10 @@ set edit:completion:arg-completer[my-app] = {|@words|
|
|||
cand help 'Print this message or the help of the given subcommand(s)'
|
||||
}
|
||||
&'my-app;help;test'= {
|
||||
cand -c 'c'
|
||||
}
|
||||
&'my-app;help;help'= {
|
||||
cand -c 'c'
|
||||
}
|
||||
]
|
||||
$completions[$command]
|
||||
|
|
|
@ -9,3 +9,5 @@ complete -c my-app -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print
|
|||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -s c
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "test" -d 'Subcommand'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from test" -s c
|
||||
complete -c my-app -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from help" -s c
|
||||
|
|
|
@ -43,9 +43,11 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
|
|||
break
|
||||
}
|
||||
'my-app;help;test' {
|
||||
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'c')
|
||||
break
|
||||
}
|
||||
'my-app;help;help' {
|
||||
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'c')
|
||||
break
|
||||
}
|
||||
})
|
||||
|
|
|
@ -51,10 +51,12 @@ _arguments "${_arguments_options[@]}" /
|
|||
case $line[1] in
|
||||
(test)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
'*-c[]' /
|
||||
&& ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" /
|
||||
'*-c[]' /
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -26,10 +26,20 @@ const completion: Fig.Spec = {
|
|||
{
|
||||
name: "test",
|
||||
description: "Subcommand",
|
||||
options: [
|
||||
{
|
||||
name: "-c",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
description: "Print this message or the help of the given subcommand(s)",
|
||||
options: [
|
||||
{
|
||||
name: "-c",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
options: [
|
||||
|
|
|
@ -99,6 +99,7 @@ const completion: Fig.Spec = {
|
|||
},
|
||||
{
|
||||
name: "some-hidden-cmd",
|
||||
hidden: true,
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
|
|
|
@ -50,7 +50,6 @@ pub(crate) enum AppSettings {
|
|||
DisableHelpSubcommand,
|
||||
DisableVersionFlag,
|
||||
PropagateVersion,
|
||||
DisablePropagatedArgs,
|
||||
Hidden,
|
||||
HidePossibleValues,
|
||||
HelpExpected,
|
||||
|
@ -104,7 +103,6 @@ bitflags! {
|
|||
const IGNORE_ERRORS = 1 << 44;
|
||||
const MULTICALL = 1 << 45;
|
||||
const EXPAND_HELP_SUBCOMMAND_TREES = 1 << 46;
|
||||
const DISABLE_PROPAGATED_ARGS = 1 << 47;
|
||||
const NO_OP = 0;
|
||||
}
|
||||
}
|
||||
|
@ -144,8 +142,6 @@ impl_settings! { AppSettings, AppFlags,
|
|||
=> Flags::DISABLE_VERSION_FLAG,
|
||||
PropagateVersion
|
||||
=> Flags::PROPAGATE_VERSION,
|
||||
DisablePropagatedArgs
|
||||
=> Flags::DISABLE_PROPAGATED_ARGS,
|
||||
HidePossibleValues
|
||||
=> Flags::NO_POS_VALUES,
|
||||
HelpExpected
|
||||
|
|
|
@ -4067,13 +4067,6 @@ impl Command {
|
|||
debug!("Command::_propagate_global_args:{}", self.name);
|
||||
|
||||
for sc in &mut self.subcommands {
|
||||
if sc.is_set(AppSettings::DisablePropagatedArgs) {
|
||||
debug!(
|
||||
"Command::_propagate skipping {}, has DisablePropagatedArgs",
|
||||
sc.get_name()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
for a in self.args.args().filter(|a| a.is_global_set()) {
|
||||
if sc.find(&a.id).is_some() {
|
||||
debug!(
|
||||
|
@ -4165,7 +4158,6 @@ impl Command {
|
|||
help_help_subcmd.version = None;
|
||||
help_help_subcmd.long_version = None;
|
||||
help_help_subcmd = help_help_subcmd
|
||||
.setting(AppSettings::DisablePropagatedArgs)
|
||||
.setting(AppSettings::DisableHelpFlag)
|
||||
.setting(AppSettings::DisableVersionFlag);
|
||||
|
||||
|
@ -4196,7 +4188,7 @@ impl Command {
|
|||
|
||||
fn _copy_subtree_for_help(&self) -> Command {
|
||||
let mut cmd = Command::new(self.get_name().to_string())
|
||||
.global_setting(AppSettings::DisablePropagatedArgs)
|
||||
.hide(self.is_hide_set())
|
||||
.global_setting(AppSettings::DisableHelpFlag)
|
||||
.global_setting(AppSettings::DisableVersionFlag)
|
||||
.subcommands(self.get_subcommands().map(Command::_copy_subtree_for_help));
|
||||
|
|
Loading…
Reference in a new issue