mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
Auto merge of #530 - kbknapp:issues-526,528,529, r=kbknapp
Issues 526,528,529
This commit is contained in:
commit
9088ade4f3
8 changed files with 96 additions and 19 deletions
|
@ -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::<Vec<_>>()
|
||||
.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::<Vec<_>>()
|
||||
.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());
|
||||
|
|
|
@ -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<Vec<&'e str>> {
|
||||
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> {
|
||||
|
|
|
@ -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<Vec<&'e str>>;
|
||||
fn requires(&self) -> Option<&[&'e str]>;
|
||||
fn blacklist(&self) -> Option<&[&'e str]>;
|
||||
fn required_unless(&self) -> Option<&[&'e str]>;
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<Vec<&'e str>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'n, 'e> DispOrder for FlagBuilder<'n, 'e> {
|
||||
|
|
|
@ -248,6 +248,9 @@ impl<'n, 'e> AnyArg<'n, 'e> for OptBuilder<'n, 'e> {
|
|||
fn longest_filter(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn aliases(&self) -> Option<Vec<&'e str>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'n, 'e> DispOrder for OptBuilder<'n, 'e> {
|
||||
|
|
|
@ -238,6 +238,9 @@ impl<'n, 'e> AnyArg<'n, 'e> for PosBuilder<'n, 'e> {
|
|||
fn longest_filter(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn aliases(&self) -> Option<Vec<&'e str>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'n, 'e> DispOrder for PosBuilder<'n, 'e> {
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue