mirror of
https://github.com/clap-rs/clap
synced 2025-01-22 17:34:59 +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
|
return 0
|
||||||
;;
|
;;
|
||||||
my__app__help__help)
|
my__app__help__help)
|
||||||
opts=""
|
opts="-c"
|
||||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||||
return 0
|
return 0
|
||||||
|
@ -67,7 +67,7 @@ _my-app() {
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
my__app__help__test)
|
my__app__help__test)
|
||||||
opts=""
|
opts="-c"
|
||||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||||
return 0
|
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)'
|
cand help 'Print this message or the help of the given subcommand(s)'
|
||||||
}
|
}
|
||||||
&'my-app;help;test'= {
|
&'my-app;help;test'= {
|
||||||
|
cand -c 'c'
|
||||||
}
|
}
|
||||||
&'my-app;help;help'= {
|
&'my-app;help;help'= {
|
||||||
|
cand -c 'c'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
$completions[$command]
|
$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" -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 "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 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
|
break
|
||||||
}
|
}
|
||||||
'my-app;help;test' {
|
'my-app;help;test' {
|
||||||
|
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'c')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
'my-app;help;help' {
|
'my-app;help;help' {
|
||||||
|
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'c')
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -51,10 +51,12 @@ _arguments "${_arguments_options[@]}" /
|
||||||
case $line[1] in
|
case $line[1] in
|
||||||
(test)
|
(test)
|
||||||
_arguments "${_arguments_options[@]}" /
|
_arguments "${_arguments_options[@]}" /
|
||||||
|
'*-c[]' /
|
||||||
&& ret=0
|
&& ret=0
|
||||||
;;
|
;;
|
||||||
(help)
|
(help)
|
||||||
_arguments "${_arguments_options[@]}" /
|
_arguments "${_arguments_options[@]}" /
|
||||||
|
'*-c[]' /
|
||||||
&& ret=0
|
&& ret=0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -26,10 +26,20 @@ const completion: Fig.Spec = {
|
||||||
{
|
{
|
||||||
name: "test",
|
name: "test",
|
||||||
description: "Subcommand",
|
description: "Subcommand",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "-c",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "help",
|
name: "help",
|
||||||
description: "Print this message or the help of the given subcommand(s)",
|
description: "Print this message or the help of the given subcommand(s)",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "-c",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
options: [
|
options: [
|
||||||
|
|
|
@ -99,6 +99,7 @@ const completion: Fig.Spec = {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "some-hidden-cmd",
|
name: "some-hidden-cmd",
|
||||||
|
hidden: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "help",
|
name: "help",
|
||||||
|
|
|
@ -50,7 +50,6 @@ pub(crate) enum AppSettings {
|
||||||
DisableHelpSubcommand,
|
DisableHelpSubcommand,
|
||||||
DisableVersionFlag,
|
DisableVersionFlag,
|
||||||
PropagateVersion,
|
PropagateVersion,
|
||||||
DisablePropagatedArgs,
|
|
||||||
Hidden,
|
Hidden,
|
||||||
HidePossibleValues,
|
HidePossibleValues,
|
||||||
HelpExpected,
|
HelpExpected,
|
||||||
|
@ -104,7 +103,6 @@ bitflags! {
|
||||||
const IGNORE_ERRORS = 1 << 44;
|
const IGNORE_ERRORS = 1 << 44;
|
||||||
const MULTICALL = 1 << 45;
|
const MULTICALL = 1 << 45;
|
||||||
const EXPAND_HELP_SUBCOMMAND_TREES = 1 << 46;
|
const EXPAND_HELP_SUBCOMMAND_TREES = 1 << 46;
|
||||||
const DISABLE_PROPAGATED_ARGS = 1 << 47;
|
|
||||||
const NO_OP = 0;
|
const NO_OP = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,8 +142,6 @@ impl_settings! { AppSettings, AppFlags,
|
||||||
=> Flags::DISABLE_VERSION_FLAG,
|
=> Flags::DISABLE_VERSION_FLAG,
|
||||||
PropagateVersion
|
PropagateVersion
|
||||||
=> Flags::PROPAGATE_VERSION,
|
=> Flags::PROPAGATE_VERSION,
|
||||||
DisablePropagatedArgs
|
|
||||||
=> Flags::DISABLE_PROPAGATED_ARGS,
|
|
||||||
HidePossibleValues
|
HidePossibleValues
|
||||||
=> Flags::NO_POS_VALUES,
|
=> Flags::NO_POS_VALUES,
|
||||||
HelpExpected
|
HelpExpected
|
||||||
|
|
|
@ -4067,13 +4067,6 @@ impl Command {
|
||||||
debug!("Command::_propagate_global_args:{}", self.name);
|
debug!("Command::_propagate_global_args:{}", self.name);
|
||||||
|
|
||||||
for sc in &mut self.subcommands {
|
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()) {
|
for a in self.args.args().filter(|a| a.is_global_set()) {
|
||||||
if sc.find(&a.id).is_some() {
|
if sc.find(&a.id).is_some() {
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -4165,7 +4158,6 @@ impl Command {
|
||||||
help_help_subcmd.version = None;
|
help_help_subcmd.version = None;
|
||||||
help_help_subcmd.long_version = None;
|
help_help_subcmd.long_version = None;
|
||||||
help_help_subcmd = help_help_subcmd
|
help_help_subcmd = help_help_subcmd
|
||||||
.setting(AppSettings::DisablePropagatedArgs)
|
|
||||||
.setting(AppSettings::DisableHelpFlag)
|
.setting(AppSettings::DisableHelpFlag)
|
||||||
.setting(AppSettings::DisableVersionFlag);
|
.setting(AppSettings::DisableVersionFlag);
|
||||||
|
|
||||||
|
@ -4196,7 +4188,7 @@ impl Command {
|
||||||
|
|
||||||
fn _copy_subtree_for_help(&self) -> Command {
|
fn _copy_subtree_for_help(&self) -> Command {
|
||||||
let mut cmd = Command::new(self.get_name().to_string())
|
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::DisableHelpFlag)
|
||||||
.global_setting(AppSettings::DisableVersionFlag)
|
.global_setting(AppSettings::DisableVersionFlag)
|
||||||
.subcommands(self.get_subcommands().map(Command::_copy_subtree_for_help));
|
.subcommands(self.get_subcommands().map(Command::_copy_subtree_for_help));
|
||||||
|
|
Loading…
Reference in a new issue