mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
Apply @pksunkara review
This commit is contained in:
parent
22b5d34693
commit
f74af655ce
7 changed files with 154 additions and 233 deletions
|
@ -147,7 +147,8 @@ fn option_details_for_path(app: &App, path: &str) -> String {
|
|||
let mut opts = String::new();
|
||||
|
||||
for o in p.get_opts() {
|
||||
if let Some(l) = o.get_long() {
|
||||
if let Some(longs) = o.get_long_and_visible_aliases() {
|
||||
for long in longs {
|
||||
opts = format!(
|
||||
"{}
|
||||
--{})
|
||||
|
@ -155,12 +156,14 @@ fn option_details_for_path(app: &App, path: &str) -> String {
|
|||
return 0
|
||||
;;",
|
||||
opts,
|
||||
l,
|
||||
long,
|
||||
vals_for(o)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(s) = o.get_short() {
|
||||
if let Some(shorts) = o.get_short_and_visible_aliases() {
|
||||
for short in shorts {
|
||||
opts = format!(
|
||||
"{}
|
||||
-{})
|
||||
|
@ -168,11 +171,12 @@ fn option_details_for_path(app: &App, path: &str) -> String {
|
|||
return 0
|
||||
;;",
|
||||
opts,
|
||||
s,
|
||||
short,
|
||||
vals_for(o)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
opts
|
||||
}
|
||||
|
|
|
@ -78,61 +78,37 @@ fn generate_inner<'help>(
|
|||
let preamble = String::from("\n cand ");
|
||||
|
||||
for option in p.get_opts() {
|
||||
if let Some(data) = option.get_short() {
|
||||
let tooltip = get_tooltip(option.get_about(), data);
|
||||
|
||||
if let Some(shorts) = option.get_short_and_visible_aliases() {
|
||||
let tooltip = get_tooltip(option.get_about(), shorts[0]);
|
||||
for short in shorts {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(format!("-{} '{}'", data, tooltip).as_str());
|
||||
|
||||
if let Some(short_aliases) = option.get_visible_short_aliases() {
|
||||
for data in short_aliases {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(format!("-{} '{}'", data, tooltip).as_str());
|
||||
}
|
||||
completions.push_str(format!("-{} '{}'", short, tooltip).as_str());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(data) = option.get_long() {
|
||||
let tooltip = get_tooltip(option.get_about(), data);
|
||||
|
||||
if let Some(longs) = option.get_long_and_visible_aliases() {
|
||||
let tooltip = get_tooltip(option.get_about(), longs[0]);
|
||||
for long in longs {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(format!("--{} '{}'", data, tooltip).as_str());
|
||||
|
||||
if let Some(aliases) = option.get_visible_aliases() {
|
||||
for data in aliases {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(format!("--{} '{}'", data, tooltip).as_str());
|
||||
}
|
||||
completions.push_str(format!("--{} '{}'", long, tooltip).as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for flag in Elvish::flags(p) {
|
||||
if let Some(data) = flag.get_short() {
|
||||
let tooltip = get_tooltip(flag.get_about(), data);
|
||||
|
||||
if let Some(shorts) = flag.get_short_and_visible_aliases() {
|
||||
let tooltip = get_tooltip(flag.get_about(), shorts[0]);
|
||||
for short in shorts {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(format!("-{} '{}'", data, tooltip).as_str());
|
||||
|
||||
if let Some(short_aliases) = flag.get_visible_short_aliases() {
|
||||
for data in short_aliases {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(format!("-{} '{}'", data, tooltip).as_str());
|
||||
}
|
||||
completions.push_str(format!("-{} '{}'", short, tooltip).as_str());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(data) = flag.get_long() {
|
||||
let tooltip = get_tooltip(flag.get_about(), data);
|
||||
|
||||
if let Some(longs) = flag.get_long_and_visible_aliases() {
|
||||
let tooltip = get_tooltip(flag.get_about(), longs[0]);
|
||||
for long in longs {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(format!("--{} '{}'", data, tooltip).as_str());
|
||||
|
||||
if let Some(aliases) = flag.get_visible_aliases() {
|
||||
for data in aliases {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(format!("--{} '{}'", data, tooltip).as_str());
|
||||
}
|
||||
completions.push_str(format!("--{} '{}'", long, tooltip).as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,23 +59,15 @@ fn gen_fish_inner(root_command: &str, app: &App, buffer: &mut String) {
|
|||
for option in app.get_opts() {
|
||||
let mut template = basic_template.clone();
|
||||
|
||||
if let Some(data) = option.get_short() {
|
||||
template.push_str(format!(" -s {}", data).as_str());
|
||||
|
||||
if let Some(short_aliases) = option.get_visible_short_aliases() {
|
||||
for data in short_aliases {
|
||||
template.push_str(format!(" -s {}", data).as_str());
|
||||
}
|
||||
if let Some(shorts) = option.get_short_and_visible_aliases() {
|
||||
for short in shorts {
|
||||
template.push_str(format!(" -s {}", short).as_str());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(data) = option.get_long() {
|
||||
template.push_str(format!(" -l {}", data).as_str());
|
||||
|
||||
if let Some(aliases) = option.get_visible_aliases() {
|
||||
for data in aliases {
|
||||
template.push_str(format!(" -l {}", data).as_str());
|
||||
}
|
||||
if let Some(longs) = option.get_long_and_visible_aliases() {
|
||||
for long in longs {
|
||||
template.push_str(format!(" -l {}", escape_string(long)).as_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,23 +84,15 @@ fn gen_fish_inner(root_command: &str, app: &App, buffer: &mut String) {
|
|||
for flag in Fish::flags(app) {
|
||||
let mut template = basic_template.clone();
|
||||
|
||||
if let Some(data) = flag.get_short() {
|
||||
template.push_str(format!(" -s {}", data).as_str());
|
||||
|
||||
if let Some(short_aliases) = flag.get_visible_short_aliases() {
|
||||
for data in short_aliases {
|
||||
template.push_str(format!(" -s {}", data).as_str());
|
||||
}
|
||||
if let Some(shorts) = flag.get_short_and_visible_aliases() {
|
||||
for short in shorts {
|
||||
template.push_str(format!(" -s {}", short).as_str());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(data) = flag.get_long() {
|
||||
template.push_str(format!(" -l {}", data).as_str());
|
||||
|
||||
if let Some(aliases) = flag.get_visible_aliases() {
|
||||
for data in aliases {
|
||||
template.push_str(format!(" -l {}", data).as_str());
|
||||
}
|
||||
if let Some(longs) = flag.get_long_and_visible_aliases() {
|
||||
for long in longs {
|
||||
template.push_str(format!(" -l {}", escape_string(long)).as_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,109 +85,61 @@ fn generate_inner<'help>(
|
|||
let preamble = String::from("\n [CompletionResult]::new(");
|
||||
|
||||
for option in p.get_opts() {
|
||||
if let Some(data) = option.get_short() {
|
||||
let tooltip = get_tooltip(option.get_about(), data);
|
||||
|
||||
if let Some(shorts) = option.get_short_and_visible_aliases() {
|
||||
let tooltip = get_tooltip(option.get_about(), shorts[0]);
|
||||
for short in shorts {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(
|
||||
format!(
|
||||
"'-{}', '{}', {}, '{}')",
|
||||
data, data, "[CompletionResultType]::ParameterName", tooltip
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
|
||||
if let Some(short_aliases) = option.get_visible_short_aliases() {
|
||||
for data in short_aliases {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(
|
||||
format!(
|
||||
"'-{}', '{}', {}, '{}')",
|
||||
data, data, "[CompletionResultType]::ParameterName", tooltip
|
||||
short, short, "[CompletionResultType]::ParameterName", tooltip
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(data) = option.get_long() {
|
||||
let tooltip = get_tooltip(option.get_about(), data);
|
||||
|
||||
if let Some(longs) = option.get_long_and_visible_aliases() {
|
||||
let tooltip = get_tooltip(option.get_about(), longs[0]);
|
||||
for long in longs {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(
|
||||
format!(
|
||||
"'--{}', '{}', {}, '{}')",
|
||||
data, data, "[CompletionResultType]::ParameterName", tooltip
|
||||
long, long, "[CompletionResultType]::ParameterName", tooltip
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
|
||||
if let Some(aliases) = option.get_visible_aliases() {
|
||||
for data in aliases {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(
|
||||
format!(
|
||||
"'--{}', '{}', {}, '{}')",
|
||||
data, data, "[CompletionResultType]::ParameterName", tooltip
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for flag in PowerShell::flags(p) {
|
||||
if let Some(data) = flag.get_short() {
|
||||
let tooltip = get_tooltip(flag.get_about(), data);
|
||||
|
||||
if let Some(shorts) = flag.get_short_and_visible_aliases() {
|
||||
let tooltip = get_tooltip(flag.get_about(), shorts[0]);
|
||||
for short in shorts {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(
|
||||
format!(
|
||||
"'-{}', '{}', {}, '{}')",
|
||||
data, data, "[CompletionResultType]::ParameterName", tooltip
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
|
||||
if let Some(short_aliases) = flag.get_visible_short_aliases() {
|
||||
for data in short_aliases {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(
|
||||
format!(
|
||||
"'-{}', '{}', {}, '{}')",
|
||||
data, data, "[CompletionResultType]::ParameterName", tooltip
|
||||
short, short, "[CompletionResultType]::ParameterName", tooltip
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(data) = flag.get_long() {
|
||||
let tooltip = get_tooltip(flag.get_about(), data);
|
||||
|
||||
if let Some(longs) = flag.get_long_and_visible_aliases() {
|
||||
let tooltip = get_tooltip(flag.get_about(), longs[0]);
|
||||
for long in longs {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(
|
||||
format!(
|
||||
"'--{}', '{}', {}, '{}')",
|
||||
data, data, "[CompletionResultType]::ParameterName", tooltip
|
||||
long, long, "[CompletionResultType]::ParameterName", tooltip
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
|
||||
if let Some(aliases) = flag.get_visible_aliases() {
|
||||
for data in aliases {
|
||||
completions.push_str(&preamble);
|
||||
completions.push_str(
|
||||
format!(
|
||||
"'--{}', '{}', {}, '{}')",
|
||||
data, data, "[CompletionResultType]::ParameterName", tooltip
|
||||
)
|
||||
.as_str(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -422,7 +422,8 @@ fn write_opts_of(p: &App, p_global: Option<&App>) -> String {
|
|||
None => "".to_string(),
|
||||
};
|
||||
|
||||
if let Some(short) = o.get_short() {
|
||||
if let Some(shorts) = o.get_short_and_visible_aliases() {
|
||||
for short in shorts {
|
||||
let s = format!(
|
||||
"'{conflicts}{multiple}-{arg}+[{help}]{value_completion}' \\",
|
||||
conflicts = conflicts,
|
||||
|
@ -434,25 +435,10 @@ fn write_opts_of(p: &App, p_global: Option<&App>) -> String {
|
|||
|
||||
debug!("write_opts_of:iter: Wrote...{}", &*s);
|
||||
ret.push(s);
|
||||
|
||||
if let Some(short_aliases) = o.get_visible_short_aliases() {
|
||||
for alias in short_aliases {
|
||||
let s = format!(
|
||||
"'{conflicts}{multiple}-{arg}+[{help}]{value_completion}' \\",
|
||||
conflicts = conflicts,
|
||||
multiple = multiple,
|
||||
arg = alias,
|
||||
value_completion = vc,
|
||||
help = help
|
||||
);
|
||||
|
||||
debug!("write_opts_of:iter: Wrote...{}", &*s);
|
||||
ret.push(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(long) = o.get_long() {
|
||||
if let Some(longs) = o.get_long_and_visible_aliases() {
|
||||
for long in longs {
|
||||
let l = format!(
|
||||
"'{conflicts}{multiple}--{arg}=[{help}]{value_completion}' \\",
|
||||
conflicts = conflicts,
|
||||
|
@ -464,21 +450,6 @@ fn write_opts_of(p: &App, p_global: Option<&App>) -> String {
|
|||
|
||||
debug!("write_opts_of:iter: Wrote...{}", &*l);
|
||||
ret.push(l);
|
||||
|
||||
if let Some(aliases) = o.get_visible_aliases() {
|
||||
for alias in aliases {
|
||||
let l = format!(
|
||||
"'{conflicts}{multiple}--{arg}=[{help}]{value_completion}' \\",
|
||||
conflicts = conflicts,
|
||||
multiple = multiple,
|
||||
arg = alias,
|
||||
value_completion = vc,
|
||||
help = help
|
||||
);
|
||||
|
||||
debug!("write_opts_of:iter: Wrote...{}", &*l);
|
||||
ret.push(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,10 +315,18 @@ static BASH_ALIASES: &str = r#"_cmd() {
|
|||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--opt)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-o)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-O)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
|
|
|
@ -160,6 +160,19 @@ impl<'help> Arg<'help> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the short option name and its visible aliases, if any
|
||||
#[inline]
|
||||
pub fn get_short_and_visible_aliases(&self) -> Option<Vec<char>> {
|
||||
let mut shorts = match self.short {
|
||||
Some(short) => vec![short],
|
||||
None => return None,
|
||||
};
|
||||
if let Some(aliases) = self.get_visible_short_aliases() {
|
||||
shorts.extend(aliases);
|
||||
}
|
||||
Some(shorts)
|
||||
}
|
||||
|
||||
/// Get the long option name for this argument, if any
|
||||
#[inline]
|
||||
pub fn get_long(&self) -> Option<&str> {
|
||||
|
@ -182,6 +195,19 @@ impl<'help> Arg<'help> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Get the long option name and its visible aliases, if any
|
||||
#[inline]
|
||||
pub fn get_long_and_visible_aliases(&self) -> Option<Vec<&str>> {
|
||||
let mut longs = match self.long {
|
||||
Some(long) => vec![long],
|
||||
None => return None,
|
||||
};
|
||||
if let Some(aliases) = self.get_visible_aliases() {
|
||||
longs.extend(aliases);
|
||||
}
|
||||
Some(longs)
|
||||
}
|
||||
|
||||
/// Get the list of the possible values for this argument, if any
|
||||
#[inline]
|
||||
pub fn get_possible_values(&self) -> Option<&[&str]> {
|
||||
|
|
Loading…
Reference in a new issue