diff --git a/src/app/help.rs b/src/app/help.rs index 7bc64d24..0831f225 100644 --- a/src/app/help.rs +++ b/src/app/help.rs @@ -461,6 +461,17 @@ impl<'a> Help<'a> { "".into() } }); + } else if let Some(ref aliases) = a.aliases() { + debugln!("Writing aliases"); + return format!(" [aliases: {}]", + if self.color { + aliases.iter() + .map(|v| format!("{}", self.cizer.good(v))) + .collect::>() + .join(", ") + } else { + aliases.join(", ") + }); } else if !self.hide_pv { debugln!("Writing values"); if let Some(ref pv) = a.possible_vals() { @@ -548,21 +559,6 @@ impl<'a> Help<'a> { let mut ord_m = VecMap::new(); for sc in parser.subcommands.iter().filter(|s| !s.p.is_set(AppSettings::Hidden)) { - let sc = if let Some(ref aliases) = sc.p.meta.aliases { - let mut a = App::new(format!("{}|{}", &*sc.p.meta.name, aliases.iter() - .filter(|&&(_, vis)| vis) - .map(|&(n, _)| n) - .collect::>() - .join("|"))); - a = if let Some(about) = sc.p.meta.about { - a.about(about) - } else { - a - }; - a - } else { - sc.clone() - }; let btm = ord_m.entry(sc.p.meta.disp_ord).or_insert(BTreeMap::new()); longest = cmp::max(longest, sc.p.meta.name.len()); btm.insert(sc.p.meta.name.clone(), sc.clone()); diff --git a/src/app/mod.rs b/src/app/mod.rs index ae68caa6..03675b4f 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1139,6 +1139,12 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> { if let Some(v) = yaml["about"].as_str() { a = a.about(v); } + if let Some(v) = yaml["before_help"].as_str() { + a = a.before_help(v); + } + if let Some(v) = yaml["template"].as_str() { + a = a.template(v); + } if let Some(v) = yaml["after_help"].as_str() { a = a.after_help(v); } @@ -1157,6 +1163,9 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> { if let Some(v) = yaml["version_short"].as_str() { a = a.version_short(v); } + if let Some(v) = yaml["setting"].as_str() { + a = a.setting(v.parse().ok().expect("unknown AppSetting found in YAML file")); + } if let Some(v) = yaml["settings"].as_vec() { for ys in v { if let Some(s) = ys.as_str() { @@ -1164,6 +1173,19 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> { } } } + if let Some(v) = yaml["global_setting"].as_str() { + a = a.setting(v.parse().ok().expect("unknown AppSetting found in YAML file")); + } + if let Some(v) = yaml["global_settings"].as_vec() { + for ys in v { + if let Some(s) = ys.as_str() { + a = a.global_setting(s.parse().ok().expect("unknown AppSetting found in YAML file")); + } + } + } + if let Some(v) = yaml["alias"].as_str() { + a = a.alias(v); + } if let Some(v) = yaml["aliases"].as_vec() { for ys in v { if let Some(s) = ys.as_str() { @@ -1171,6 +1193,16 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> { } } } + if let Some(v) = yaml["visible_alias"].as_str() { + a = a.visible_alias(v); + } + if let Some(v) = yaml["visible_aliases"].as_vec() { + for ys in v { + if let Some(s) = ys.as_str() { + a = a.visible_alias(s); + } + } + } if let Some(v) = yaml["args"].as_vec() { for arg_yaml in v { a = a.arg(Arg::from_yaml(&arg_yaml.as_hash().unwrap())); @@ -1261,6 +1293,18 @@ impl<'n, 'e> AnyArg<'n, 'e> for App<'n, 'e> { fn longest_filter(&self) -> bool { true } + fn aliases(&self) -> Option> { + if let Some(ref aliases) = self.p.meta.aliases { + let vis_aliases: Vec<_> = aliases.iter().filter_map(|&(n,v)| if v { Some(n) } else {None}).collect(); + if vis_aliases.is_empty() { + None + } else { + Some(vis_aliases) + } + } else { + None + } + } } impl<'n, 'e> fmt::Display for App<'n, 'e> { diff --git a/src/args/any_arg.rs b/src/args/any_arg.rs index 88aee178..91ffc7fa 100644 --- a/src/args/any_arg.rs +++ b/src/args/any_arg.rs @@ -8,6 +8,7 @@ use args::settings::ArgSettings; pub trait AnyArg<'n, 'e> { fn name(&self) -> &'n str; fn overrides(&self) -> Option<&[&'e str]>; + fn aliases(&self) -> Option>; fn requires(&self) -> Option<&[&'e str]>; fn blacklist(&self) -> Option<&[&'e str]>; fn required_unless(&self) -> Option<&[&'e str]>; diff --git a/src/args/arg.rs b/src/args/arg.rs index cb0e74fa..404acb4c 100644 --- a/src/args/arg.rs +++ b/src/args/arg.rs @@ -155,6 +155,8 @@ impl<'a, 'b> Arg<'a, 'b> { "index" => a.index(v.as_i64().unwrap() as u64), "global" => a.global(v.as_bool().unwrap()), "multiple" => a.multiple(v.as_bool().unwrap()), + "hidden" => a.hidden(v.as_bool().unwrap()), + "next_line_help" => a.next_line_help(v.as_bool().unwrap()), "empty_values" => a.empty_values(v.as_bool().unwrap()), "group" => a.group(v.as_str().unwrap()), "number_of_values" => a.number_of_values(v.as_i64().unwrap() as u64), @@ -165,6 +167,7 @@ impl<'a, 'b> Arg<'a, 'b> { "value_delimiter" => a.value_delimiter(v.as_str().unwrap()), "required_unless" => a.required_unless(v.as_str().unwrap()), "display_order" => a.display_order(v.as_i64().unwrap() as usize), + "default_value" => a.default_value(v.as_str().unwrap()), "value_names" => { for ys in v.as_vec().unwrap() { if let Some(s) = ys.as_str() { diff --git a/src/args/arg_builder/flag.rs b/src/args/arg_builder/flag.rs index 8d998342..fef958fd 100644 --- a/src/args/arg_builder/flag.rs +++ b/src/args/arg_builder/flag.rs @@ -166,6 +166,9 @@ impl<'n, 'e> AnyArg<'n, 'e> for FlagBuilder<'n, 'e> { fn longest_filter(&self) -> bool { self.long.is_some() } + fn aliases(&self) -> Option> { + None + } } impl<'n, 'e> DispOrder for FlagBuilder<'n, 'e> { diff --git a/src/args/arg_builder/option.rs b/src/args/arg_builder/option.rs index 5e93233d..4b7c4195 100644 --- a/src/args/arg_builder/option.rs +++ b/src/args/arg_builder/option.rs @@ -248,6 +248,9 @@ impl<'n, 'e> AnyArg<'n, 'e> for OptBuilder<'n, 'e> { fn longest_filter(&self) -> bool { true } + fn aliases(&self) -> Option> { + None + } } impl<'n, 'e> DispOrder for OptBuilder<'n, 'e> { diff --git a/src/args/arg_builder/positional.rs b/src/args/arg_builder/positional.rs index 6524e600..8ea881d6 100644 --- a/src/args/arg_builder/positional.rs +++ b/src/args/arg_builder/positional.rs @@ -238,6 +238,9 @@ impl<'n, 'e> AnyArg<'n, 'e> for PosBuilder<'n, 'e> { fn longest_filter(&self) -> bool { true } + fn aliases(&self) -> Option> { + None + } } impl<'n, 'e> DispOrder for PosBuilder<'n, 'e> { diff --git a/tests/subcommands.rs b/tests/subcommands.rs index 757e5c13..8592ee96 100644 --- a/tests/subcommands.rs +++ b/tests/subcommands.rs @@ -15,8 +15,21 @@ FLAGS: -V, --version Prints version information SUBCOMMANDS: - help Prints this message or the help of the given subcommand(s) - vim|vi Some help"; + help Prints this message or the help of the given subcommand(s) + test Some help [aliases: dongle, done]"; + +static INVISIBLE_ALIAS_HELP: &'static str = "clap-test 2.6 + +USAGE: + clap-test [FLAGS] [SUBCOMMAND] + +FLAGS: + -h, --help Prints help information + -V, --version Prints version information + +SUBCOMMANDS: + help Prints this message or the help of the given subcommand(s) + test Some help"; #[test] fn subcommand() { @@ -121,9 +134,20 @@ fn alias_help() { fn visible_aliases_help_output() { let app = App::new("clap-test") .version("2.6") - .subcommand(SubCommand::with_name("vim") + .subcommand(SubCommand::with_name("test") .about("Some help") .alias("invisible") - .visible_alias("vi")); + .visible_alias("dongle") + .visible_alias("done")); test::check_help(app, VISIBLE_ALIAS_HELP); } + +#[test] +fn invisible_aliases_help_output() { + let app = App::new("clap-test") + .version("2.6") + .subcommand(SubCommand::with_name("test") + .about("Some help") + .alias("invisible")); + test::check_help(app, INVISIBLE_ALIAS_HELP); +} \ No newline at end of file