Merge pull request #5359 from poliorcetics/ab/push-szymvyzpmnqx

fix(clap_complete_nushell): correctly handle commands whose short description is more than one line
This commit is contained in:
Ed Page 2024-02-16 16:32:14 -06:00 committed by GitHub
commit f2c4e6ec74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 90 additions and 83 deletions

View file

@ -57,9 +57,9 @@ fn escape_string(string: &str) -> String {
string.replace('\'', "''")
}
fn get_tooltip<T: ToString>(help: Option<&StyledStr>, data: T) -> String {
fn escape_help<T: ToString>(help: Option<&StyledStr>, data: T) -> String {
match help {
Some(help) => escape_string(&help.to_string()),
Some(help) => escape_string(&help.to_string().replace('\n', " ")),
_ => data.to_string(),
}
}
@ -78,7 +78,7 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
for option in p.get_opts() {
if let Some(shorts) = option.get_short_and_visible_aliases() {
let tooltip = get_tooltip(option.get_help(), shorts[0]);
let tooltip = escape_help(option.get_help(), shorts[0]);
for short in shorts {
completions.push_str(&preamble);
completions.push_str(format!("-{short} '{tooltip}'").as_str());
@ -86,7 +86,7 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
}
if let Some(longs) = option.get_long_and_visible_aliases() {
let tooltip = get_tooltip(option.get_help(), longs[0]);
let tooltip = escape_help(option.get_help(), longs[0]);
for long in longs {
completions.push_str(&preamble);
completions.push_str(format!("--{long} '{tooltip}'").as_str());
@ -96,7 +96,7 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
for flag in utils::flags(p) {
if let Some(shorts) = flag.get_short_and_visible_aliases() {
let tooltip = get_tooltip(flag.get_help(), shorts[0]);
let tooltip = escape_help(flag.get_help(), shorts[0]);
for short in shorts {
completions.push_str(&preamble);
completions.push_str(format!("-{short} '{tooltip}'").as_str());
@ -104,7 +104,7 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
}
if let Some(longs) = flag.get_long_and_visible_aliases() {
let tooltip = get_tooltip(flag.get_help(), longs[0]);
let tooltip = escape_help(flag.get_help(), longs[0]);
for long in longs {
completions.push_str(&preamble);
completions.push_str(format!("--{long} '{tooltip}'").as_str());
@ -114,7 +114,7 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
for subcommand in p.get_subcommands() {
let data = &subcommand.get_name();
let tooltip = get_tooltip(subcommand.get_about(), data);
let tooltip = escape_help(subcommand.get_about(), data);
completions.push_str(&preamble);
completions.push_str(format!("{data} '{tooltip}'").as_str());

View file

@ -36,6 +36,10 @@ fn escape_string(string: &str, escape_comma: bool) -> String {
}
}
fn escape_help(help: &clap::builder::StyledStr) -> String {
escape_string(&help.to_string().replace('\n', " "), false)
}
fn gen_fish_inner(
root_command: &str,
parent_commands: &[&str],
@ -98,8 +102,7 @@ fn gen_fish_inner(
}
if let Some(data) = option.get_help() {
template
.push_str(format!(" -d '{}'", escape_string(&data.to_string(), false)).as_str());
template.push_str(&format!(" -d '{}'", escape_help(data)));
}
template.push_str(value_completion(option).as_str());
@ -124,8 +127,7 @@ fn gen_fish_inner(
}
if let Some(data) = flag.get_help() {
template
.push_str(format!(" -d '{}'", escape_string(&data.to_string(), false)).as_str());
template.push_str(&format!(" -d '{}'", escape_help(data)));
}
buffer.push_str(template.as_str());
@ -139,7 +141,7 @@ fn gen_fish_inner(
template.push_str(format!(" -a \"{}\"", &subcommand.get_name()).as_str());
if let Some(data) = subcommand.get_about() {
template.push_str(format!(" -d '{}'", escape_string(&data.to_string(), false)).as_str())
template.push_str(format!(" -d '{}'", escape_help(data)).as_str())
}
buffer.push_str(template.as_str());
@ -173,7 +175,7 @@ fn value_completion(option: &Arg) -> String {
Some(format!(
"{}\t'{}'",
escape_string(value.get_name(), true).as_str(),
escape_string(&value.get_help().unwrap_or_default().to_string(), false)
escape_help(value.get_help().unwrap_or_default())
))
})
.collect::<Vec<_>>()

View file

@ -62,9 +62,9 @@ fn escape_string(string: &str) -> String {
string.replace('\'', "''")
}
fn get_tooltip<T: ToString>(help: Option<&StyledStr>, data: T) -> String {
fn escape_help<T: ToString>(help: Option<&StyledStr>, data: T) -> String {
match help {
Some(help) => escape_string(&help.to_string()),
Some(help) => escape_string(&help.to_string().replace('\n', " ")),
_ => data.to_string(),
}
}
@ -91,7 +91,7 @@ fn generate_inner(p: &Command, previous_command_name: &str) -> String {
for subcommand in p.get_subcommands() {
let data = &subcommand.get_name();
let tooltip = get_tooltip(subcommand.get_about(), data);
let tooltip = escape_help(subcommand.get_about(), data);
completions.push_str(&preamble);
completions.push_str(
@ -120,7 +120,7 @@ fn generate_aliases(completions: &mut String, preamble: &String, arg: &Arg) {
use std::fmt::Write as _;
if let Some(aliases) = arg.get_short_and_visible_aliases() {
let tooltip = get_tooltip(arg.get_help(), aliases[0]);
let tooltip = escape_help(arg.get_help(), aliases[0]);
for alias in aliases {
let _ = write!(
completions,
@ -131,7 +131,7 @@ fn generate_aliases(completions: &mut String, preamble: &String, arg: &Arg) {
}
}
if let Some(aliases) = arg.get_long_and_visible_aliases() {
let tooltip = get_tooltip(arg.get_help(), aliases[0]);
let tooltip = escape_help(arg.get_help(), aliases[0]);
for alias in aliases {
let _ = write!(
completions,

View file

@ -429,6 +429,7 @@ fn escape_help(string: &str) -> String {
.replace(':', "\\:")
.replace('$', "\\$")
.replace('`', "\\`")
.replace('\n', " ")
}
/// Escape value string inside single quotes and parentheses

View file

@ -22,7 +22,7 @@ set edit:completion:arg-completer[my-app] = {|@words|
cand -v 'v'
cand -h 'Print help'
cand --help 'Print help'
cand test 'Subcommand'
cand test 'Subcommand with a second line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'my-app;test'= {
@ -32,7 +32,7 @@ set edit:completion:arg-completer[my-app] = {|@words|
cand --help 'Print help'
}
&'my-app;help'= {
cand test 'Subcommand'
cand test 'Subcommand with a second line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'my-app;help;test'= {

View file

@ -1,10 +1,10 @@
complete -c my-app -n "__fish_use_subcommand" -s c
complete -c my-app -n "__fish_use_subcommand" -s v
complete -c my-app -n "__fish_use_subcommand" -s h -l help -d 'Print help'
complete -c my-app -n "__fish_use_subcommand" -f -a "test" -d 'Subcommand'
complete -c my-app -n "__fish_use_subcommand" -f -a "test" -d 'Subcommand with a second line'
complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c my-app -n "__fish_seen_subcommand_from test" -s d
complete -c my-app -n "__fish_seen_subcommand_from test" -s c
complete -c my-app -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help'
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 with a second line'
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)'

View file

@ -25,7 +25,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'v')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'Subcommand')
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'Subcommand with a second line')
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
break
}
@ -37,7 +37,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
break
}
'my-app;help' {
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'Subcommand')
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'Subcommand with a second line')
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
break
}

View file

@ -68,7 +68,7 @@ esac
(( $+functions[_my-app_commands] )) ||
_my-app_commands() {
local commands; commands=(
'test:Subcommand' \
'test:Subcommand with a second line' \
'help:Print this message or the help of the given subcommand(s)' \
)
_describe -t commands 'my-app commands' commands "$@"
@ -76,7 +76,7 @@ _my-app_commands() {
(( $+functions[_my-app__help_commands] )) ||
_my-app__help_commands() {
local commands; commands=(
'test:Subcommand' \
'test:Subcommand with a second line' \
'help:Print this message or the help of the given subcommand(s)' \
)
_describe -t commands 'my-app help commands' commands "$@"

View file

@ -22,7 +22,7 @@ set edit:completion:arg-completer[bin-name] = {|@words|
cand -v 'v'
cand -h 'Print help'
cand --help 'Print help'
cand test 'Subcommand'
cand test 'Subcommand with a second line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'bin-name;test'= {
@ -32,7 +32,7 @@ set edit:completion:arg-completer[bin-name] = {|@words|
cand --help 'Print help'
}
&'bin-name;help'= {
cand test 'Subcommand'
cand test 'Subcommand with a second line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'bin-name;help;test'= {

View file

@ -1,10 +1,10 @@
complete -c bin-name -n "__fish_use_subcommand" -s c
complete -c bin-name -n "__fish_use_subcommand" -s v
complete -c bin-name -n "__fish_use_subcommand" -s h -l help -d 'Print help'
complete -c bin-name -n "__fish_use_subcommand" -f -a "test" -d 'Subcommand'
complete -c bin-name -n "__fish_use_subcommand" -f -a "test" -d 'Subcommand with a second line'
complete -c bin-name -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c bin-name -n "__fish_seen_subcommand_from test" -s d
complete -c bin-name -n "__fish_seen_subcommand_from test" -s c
complete -c bin-name -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help'
complete -c bin-name -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 bin-name -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 with a second line'
complete -c bin-name -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)'

View file

@ -25,7 +25,7 @@ Register-ArgumentCompleter -Native -CommandName 'bin-name' -ScriptBlock {
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'v')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'Subcommand')
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'Subcommand with a second line')
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
break
}
@ -37,7 +37,7 @@ Register-ArgumentCompleter -Native -CommandName 'bin-name' -ScriptBlock {
break
}
'bin-name;help' {
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'Subcommand')
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'Subcommand with a second line')
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
break
}

View file

@ -68,7 +68,7 @@ esac
(( $+functions[_bin-name_commands] )) ||
_bin-name_commands() {
local commands; commands=(
'test:Subcommand' \
'test:Subcommand with a second line' \
'help:Print this message or the help of the given subcommand(s)' \
)
_describe -t commands 'bin-name commands' commands "$@"
@ -76,7 +76,7 @@ _bin-name_commands() {
(( $+functions[_bin-name__help_commands] )) ||
_bin-name__help_commands() {
local commands; commands=(
'test:Subcommand' \
'test:Subcommand with a second line' \
'help:Print this message or the help of the given subcommand(s)' \
)
_describe -t commands 'bin-name help commands' commands "$@"

View file

@ -66,8 +66,7 @@ set edit:completion:arg-completer[exhaustive] = {|@words|
cand cmd-backslash 'Avoid ''\n'''
cand cmd-brackets 'List packages [filter]'
cand cmd-expansions 'Execute the shell command with $SHELL'
cand escape-help '\tab "''
New Line'
cand escape-help '\tab "'' New Line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'exhaustive;quote;cmd-single-quotes'= {
@ -126,8 +125,7 @@ New Line'
cand cmd-backslash 'Avoid ''\n'''
cand cmd-brackets 'List packages [filter]'
cand cmd-expansions 'Execute the shell command with $SHELL'
cand escape-help '\tab "''
New Line'
cand escape-help '\tab "'' New Line'
cand help 'Print this message or the help of the given subcommand(s)'
}
&'exhaustive;quote;help;cmd-single-quotes'= {
@ -269,8 +267,7 @@ New Line'
cand cmd-backslash 'Avoid ''\n'''
cand cmd-brackets 'List packages [filter]'
cand cmd-expansions 'Execute the shell command with $SHELL'
cand escape-help '\tab "''
New Line'
cand escape-help '\tab "'' New Line'
}
&'exhaustive;help;quote;cmd-single-quotes'= {
}

View file

@ -34,8 +34,7 @@ complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_see
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "cmd-backslash" -d 'Avoid \'\\n\''
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "cmd-brackets" -d 'List packages [filter]'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "cmd-expansions" -d 'Execute the shell command with $SHELL'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "escape-help" -d '\\tab "\'
New Line'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "escape-help" -d '\\tab "\' New Line'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-single-quotes" -l global -d 'everywhere'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-single-quotes" -s h -l help -d 'Print help'
@ -64,8 +63,7 @@ complete -c exhaustive -n "__fish_seen_subcommand_from quote; and __fish_seen_su
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "cmd-backslash" -d 'Avoid \'\\n\''
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "cmd-brackets" -d 'List packages [filter]'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "cmd-expansions" -d 'Execute the shell command with $SHELL'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "escape-help" -d '\\tab "\'
New Line'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "escape-help" -d '\\tab "\' New Line'
complete -c exhaustive -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c exhaustive -n "__fish_seen_subcommand_from value" -l delim -r
complete -c exhaustive -n "__fish_seen_subcommand_from value" -l tuple -r
@ -132,7 +130,6 @@ complete -c exhaustive -n "__fish_seen_subcommand_from help; and __fish_seen_sub
complete -c exhaustive -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help" -f -a "cmd-backslash" -d 'Avoid \'\\n\''
complete -c exhaustive -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help" -f -a "cmd-brackets" -d 'List packages [filter]'
complete -c exhaustive -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help" -f -a "cmd-expansions" -d 'Execute the shell command with $SHELL'
complete -c exhaustive -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help" -f -a "escape-help" -d '\\tab "\'
New Line'
complete -c exhaustive -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from escape-help" -f -a "escape-help" -d '\\tab "\' New Line'
complete -c exhaustive -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two" -f -a "one"
complete -c exhaustive -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two" -f -a "two"

View file

@ -645,8 +645,7 @@ _exhaustive__quote__help_commands() {
'cmd-backslash:Avoid '\''\\n'\''' \
'cmd-brackets:List packages \[filter\]' \
'cmd-expansions:Execute the shell command with \$SHELL' \
'escape-help:\\tab "'\''
New Line' \
'escape-help:\\tab "'\'' New Line' \
'help:Print this message or the help of the given subcommand(s)' \
)
_describe -t commands 'exhaustive quote help commands' commands "$@"
@ -717,8 +716,7 @@ _exhaustive__help__quote_commands() {
'cmd-backslash:Avoid '\''\\n'\''' \
'cmd-brackets:List packages \[filter\]' \
'cmd-expansions:Execute the shell command with \$SHELL' \
'escape-help:\\tab "'\''
New Line' \
'escape-help:\\tab "'\'' New Line' \
)
_describe -t commands 'exhaustive help quote commands' commands "$@"
}
@ -731,8 +729,7 @@ _exhaustive__quote_commands() {
'cmd-backslash:Avoid '\''\\n'\''' \
'cmd-brackets:List packages \[filter\]' \
'cmd-expansions:Execute the shell command with \$SHELL' \
'escape-help:\\tab "'\''
New Line' \
'escape-help:\\tab "'\'' New Line' \
'help:Print this message or the help of the given subcommand(s)' \
)
_describe -t commands 'exhaustive quote commands' commands "$@"

View file

@ -15,11 +15,13 @@ pub fn basic_command(name: &'static str) -> clap::Command {
.action(clap::ArgAction::SetTrue),
)
.subcommand(
clap::Command::new("test").about("Subcommand").arg(
clap::Arg::new("debug")
.short('d')
.action(clap::ArgAction::Count),
),
clap::Command::new("test")
.about("Subcommand\nwith a second line")
.arg(
clap::Arg::new("debug")
.short('d')
.action(clap::ArgAction::Count),
),
)
}

View file

@ -13,11 +13,13 @@ pub fn basic_command(name: &'static str) -> clap::Command {
.action(clap::ArgAction::SetTrue),
)
.subcommand(
clap::Command::new("test").about("Subcommand").arg(
clap::Arg::new("debug")
.short('d')
.action(clap::ArgAction::Count),
),
clap::Command::new("test")
.about("Subcommand\nwith a second line")
.arg(
clap::Arg::new("debug")
.short('d')
.action(clap::ArgAction::Count),
),
)
}

View file

@ -4,7 +4,7 @@ const completion: Fig.Spec = {
subcommands: [
{
name: "test",
description: "Subcommand",
description: "Subcommand with a second line",
options: [
{
name: "-d",
@ -25,7 +25,7 @@ const completion: Fig.Spec = {
subcommands: [
{
name: "test",
description: "Subcommand",
description: "Subcommand with a second line",
},
{
name: "help",

View file

@ -19,6 +19,7 @@
#![warn(missing_docs, trivial_casts, unused_allocation, trivial_numeric_casts)]
#![forbid(unsafe_code)]
use clap::builder::StyledStr;
use clap::{builder::PossibleValue, Arg, ArgAction, Command};
use clap_complete::Generator;
@ -75,7 +76,7 @@ fn append_value_completion_and_help(
None => 0,
};
s.push_str(format!("{:>width$}# {}", ' ', help).as_str());
s.push_str(format!("{:>width$}# {}", ' ', single_line_styled_str(help)).as_str());
}
s.push('\n');
@ -180,6 +181,7 @@ fn generate_completion(completions: &mut String, cmd: &Command, is_subcommand: b
}
if let Some(about) = cmd.get_about() {
let about = single_line_styled_str(about);
completions.push_str(format!(" # {about}\n").as_str());
}
@ -201,3 +203,7 @@ fn generate_completion(completions: &mut String, cmd: &Command, is_subcommand: b
}
}
}
fn single_line_styled_str(text: &StyledStr) -> String {
text.to_string().replace('\n', " ")
}

View file

@ -18,7 +18,7 @@ pub fn basic_command(name: &'static str) -> Command {
)
.subcommand(
Command::new("test")
.about("Subcommand")
.about("Subcommand\nwith a second line")
.arg(Arg::new("debug").short('d').action(ArgAction::Count)),
)
}
@ -36,7 +36,7 @@ pub fn feature_sample_command(name: &'static str) -> Command {
.arg(
Arg::new("config")
.action(ArgAction::Count)
.help("some config file")
.help("some config file\nwith another line")
.short('c')
.visible_short_alias('C')
.long("config")

View file

@ -6,7 +6,7 @@ module completions {
--help(-h) # Print help
]
# Subcommand
# Subcommand with a second line
export extern "my-app test" [
-d
-c
@ -17,7 +17,7 @@ module completions {
export extern "my-app help" [
]
# Subcommand
# Subcommand with a second line
export extern "my-app help test" [
]

View file

@ -7,9 +7,9 @@ module completions {
# Tests completions
export extern my-app [
file?: string # some input file
--config(-c) # some config file
--conf # some config file
-C # some config file
--config(-c) # some config file with another line
--conf # some config file with another line
-C # some config file with another line
choice?: string@"nu-complete my-app choice"
--help(-h) # Print help
--version(-V) # Print version

View file

@ -7,9 +7,9 @@ module completions {
# Tests completions
export extern my-app [
file?: string # some input file
--config(-c) # some config file
--conf # some config file
-C # some config file
--config(-c) # some config file with another line
--conf # some config file with another line
-C # some config file with another line
choice?: string@"nu-complete my-app choice"
--help(-h) # Print help
--version(-V) # Print version

View file

@ -7,9 +7,9 @@ module completions {
# Tests completions
export extern my-app [
file?: string # some input file
--config(-c) # some config file
--conf # some config file
-C # some config file
--config(-c) # some config file with another line
--conf # some config file with another line
-C # some config file with another line
choice?: string@"nu-complete my-app choice"
--help(-h) # Print help
--version(-V) # Print version

View file

@ -15,11 +15,13 @@ pub fn basic_command(name: &'static str) -> clap::Command {
.action(clap::ArgAction::SetTrue),
)
.subcommand(
clap::Command::new("test").about("Subcommand").arg(
clap::Arg::new("debug")
.short('d')
.action(clap::ArgAction::Count),
),
clap::Command::new("test")
.about("Subcommand\nwith a second line")
.arg(
clap::Arg::new("debug")
.short('d')
.action(clap::ArgAction::Count),
),
)
}

View file

@ -20,6 +20,7 @@ Print help
.TP
my\-app\-test(1)
Subcommand
with a second line
.TP
my\-app\-help(1)
Print this message or the help of the given subcommand(s)