Skip to content

Commit

Permalink
get_possible_values
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepySkeleton committed Apr 10, 2020
1 parent e6bdd7f commit 9278923
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion clap_generate/src/generators/shells/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn option_details_for_path(app: &App, path: &str) -> String {
fn vals_for(o: &Arg) -> String {
debugln!("Bash::vals_for: o={}", o.name);

if let Some(ref vals) = o.possible_vals {
if let Some(ref vals) = o.get_possible_values() {
format!("$(compgen -W \"{}\" -- ${{cur}})", vals.join(" "))
} else {
String::from("$(compgen -f ${cur})")
Expand Down
2 changes: 1 addition & 1 deletion clap_generate/src/generators/shells/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn gen_fish_inner(root_command: &str, app: &App, buffer: &mut String) {
template.push_str(format!(" -d '{}'", escape_string(data)).as_str());
}

if let Some(ref data) = option.possible_vals {
if let Some(ref data) = option.get_possible_values() {
template.push_str(format!(" -r -f -a \"{}\"", data.join(" ")).as_str());
}

Expand Down
5 changes: 2 additions & 3 deletions clap_generate/src/generators/shells/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn write_opts_of(p: &App) -> String {
""
};

let pv = if let Some(ref pv_vec) = o.possible_vals {
let pv = if let Some(ref pv_vec) = o.get_possible_values() {
format!(
": :({})",
pv_vec
Expand Down Expand Up @@ -504,8 +504,7 @@ fn write_positionals_of(p: &App) -> String {
.replace("]", "\\]")
.replace(":", "\\:"),
action = arg
.possible_vals
.as_ref()
.get_possible_values()
.map_or("_files".to_owned(), |values| {
format!(
"({})",
Expand Down
12 changes: 8 additions & 4 deletions src/build/arg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ pub struct Arg<'help> {
pub(crate) aliases: Option<Vec<(&'help str, bool)>>, // (name, visible)
pub(crate) disp_ord: usize,
pub(crate) unified_ord: usize,
#[doc(hidden)]
pub possible_vals: Option<Vec<&'help str>>,
pub(crate) possible_vals: Option<Vec<&'help str>>,
pub(crate) val_names: Option<VecMap<&'help str>>,
pub(crate) num_vals: Option<u64>,
pub(crate) max_vals: Option<u64>,
Expand Down Expand Up @@ -105,15 +104,20 @@ impl<'help> Arg<'help> {
self.help.clone()
}

/// Get the short option for this argument, if any
/// Get the short option name for this argument, if any
pub fn get_short(&self) -> Option<char> {
self.short.clone()
}

/// Get the long option for this argument, if any
/// Get the long option name for this argument, if any
pub fn get_long(&self) -> Option<&str> {
self.long.clone()
}

/// Get the list of the possible values for this argument, if any
pub fn get_possible_values(&self) -> Option<&[&str]> {
self.possible_vals.as_deref()
}
}

impl<'help> Arg<'help> {
Expand Down

1 comment on commit 9278923

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 9278923 Previous: 9060e3e Ratio
build_empty 88 ns/iter (± 2) 95 ns/iter (± 2) 0.93
parse_empty 915 ns/iter (± 26) 923 ns/iter (± 27) 0.99
parse_simple_with_complex 3488 ns/iter (± 117) 3585 ns/iter (± 95) 0.97
parse_simple_with_pos 2645 ns/iter (± 70) 2898 ns/iter (± 71) 0.91
parse_simple_with_opt 2980 ns/iter (± 99) 3137 ns/iter (± 78) 0.95
parse_simple_with_flag 2549 ns/iter (± 76) 2783 ns/iter (± 105) 0.92
build_with_pos_ref 206 ns/iter (± 6) 202 ns/iter (± 5) 1.02
build_with_pos 163 ns/iter (± 4) 159 ns/iter (± 4) 1.03
build_with_opt_ref 314 ns/iter (± 9) 311 ns/iter (± 10) 1.01
build_with_opt 243 ns/iter (± 8) 254 ns/iter (± 7) 0.96
build_with_flag_ref 257 ns/iter (± 7) 258 ns/iter (± 8) 1.00
build_with_flag 212 ns/iter (± 6) 218 ns/iter (± 7) 0.97
build_simple 734 ns/iter (± 26) 666 ns/iter (± 22) 1.10
build_from_usage 4022 ns/iter (± 112) 4192 ns/iter (± 141) 0.96
build_from_builder 2930 ns/iter (± 75) 2371 ns/iter (± 82) 1.24
build_from_macros 2549 ns/iter (± 97) 2453 ns/iter (± 77) 1.04
parse_complex 7427 ns/iter (± 325) 6637 ns/iter (± 179) 1.12
parse_complex_with_flag 8245 ns/iter (± 278) 7728 ns/iter (± 211) 1.07
parse_complex_with_opt 8065 ns/iter (± 336) 7970 ns/iter (± 238) 1.01
parse_complex_with_pos 8516 ns/iter (± 336) 8133 ns/iter (± 346) 1.05
parse_complex_with_sc 9706 ns/iter (± 423) 9559 ns/iter (± 267) 1.02
parse_complex_with_sc_flag 10433 ns/iter (± 247) 10469 ns/iter (± 296) 1.00
parse_complex_with_sc_opt 11094 ns/iter (± 310) 10297 ns/iter (± 331) 1.08
parse_complex_with_sc_pos 10393 ns/iter (± 374) 10108 ns/iter (± 307) 1.03
parse_complex1 13459 ns/iter (± 359) 13202 ns/iter (± 459) 1.02
parse_complex2 14573 ns/iter (± 491) 14534 ns/iter (± 404) 1.00
parse_args_negate_scs 14243 ns/iter (± 324) 14492 ns/iter (± 469) 0.98
parse_complex_with_sc_complex 11571 ns/iter (± 286) 11708 ns/iter (± 414) 0.99
example1 17494 ns/iter (± 720) 17296 ns/iter (± 559) 1.01
example2 355432 ns/iter (± 38739) 350395 ns/iter (± 38472) 1.01
example3 16273 ns/iter (± 410) 16832 ns/iter (± 468) 0.97
example4 11854 ns/iter (± 312) 11421 ns/iter (± 420) 1.04
example5 456024 ns/iter (± 38631) 450528 ns/iter (± 39188) 1.01
example6 9042 ns/iter (± 336) 9273 ns/iter (± 303) 0.98
example7 12701 ns/iter (± 318) 12613 ns/iter (± 426) 1.01
example8 12862 ns/iter (± 335) 12757 ns/iter (± 578) 1.01
example10 407037 ns/iter (± 37546) 402324 ns/iter (± 35959) 1.01
example4_template 10584 ns/iter (± 229) 10630 ns/iter (± 403) 1.00
build_rg_with_short_help 11115 ns/iter (± 368) 11495 ns/iter (± 331) 0.97
build_rg_with_long_help 11408 ns/iter (± 329) 12433 ns/iter (± 381) 0.92
write_rg_short_help 108874 ns/iter (± 3427) 97346 ns/iter (± 2365) 1.12
write_rg_long_help 237770 ns/iter (± 7991) 230822 ns/iter (± 9664) 1.03
parse_rg 24248 ns/iter (± 615) 25726 ns/iter (± 757) 0.94
parse_rg_with_complex 36809 ns/iter (± 1261) 37060 ns/iter (± 1093) 0.99
parse_rg_with_lots 824540 ns/iter (± 19906) 785800 ns/iter (± 22947) 1.05
build_rustup 14592 ns/iter (± 396) 12816 ns/iter (± 383) 1.14
parse_rustup 19148 ns/iter (± 707) 17758 ns/iter (± 540) 1.08
parse_rustup_with_sc 19645 ns/iter (± 775) 17672 ns/iter (± 336) 1.11

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.