Auto merge of #703 - kbknapp:issue-702, r=kbknapp

Issue 702
This commit is contained in:
Homu 2016-10-24 23:50:19 +09:00
commit 9b32a5aa26
8 changed files with 78 additions and 6 deletions

View file

@ -1,3 +1,13 @@
<a name="v2.16.1"></a>
### v2.16.1 (2016-10-24)
#### Bug Fixes
* **Help Message:** fixes a regression bug where args with multiple(true) threw off alignment ([ebddac79](https://github.com/kbknapp/clap-rs/commit/ebddac791f3ceac193d5ad833b4b734b9643a7af), closes [#702](https://github.com/kbknapp/clap-rs/issues/702))
<a name="v2.16.0"></a>
## v2.16.0 (2016-10-23)

View file

@ -1,7 +1,7 @@
[package]
name = "clap"
version = "2.16.0"
version = "2.16.1"
authors = ["Kevin K. <kbknapp@gmail.com>"]
exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"]
repository = "https://github.com/kbknapp/clap-rs.git"

View file

@ -41,10 +41,16 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
## What's New
* **Help Message:** fixes a regression bug where args with multiple(true) threw off alignment
Here's the highlights for v2.16.0
* **Completions:** adds automatic ZSH completion script generation support! :tada: :tada:
Here's a gif of them in action!
![zsh-comppletions](http://i.imgur.com/rwlMbAv.gif)
Here's the highlights for v2.15.0
* **AppSettings:** adds new setting `AppSettings::AllowNegativeNumbers` which functions like `AllowLeadingHyphen` except only allows undefined negative numbers to pass parsing.

View file

@ -307,8 +307,14 @@ impl<'a> Help<'a> {
try!(write!(self.writer, " "));
}
}
if arg.is_set(ArgSettings::Multiple) && num == 1 {
try!(color!(self, "...", good));
}
} else if arg.has_switch() {
try!(color!(self, "<{}>", arg.name(), good));
if arg.is_set(ArgSettings::Multiple) {
try!(color!(self, "...", good));
}
} else {
try!(color!(self, "{}", arg, good));
}

View file

@ -1989,6 +1989,7 @@ impl<'a, 'b> Parser<'a, 'b>
None
}
#[cfg_attr(feature = "lints", allow(explicit_iter_loop))]
pub fn find_subcommand(&'b self, sc: &str) -> Option<&'b App<'a, 'b>> {
debugln!("fn=find_subcommand;");
debugln!("Looking for sc...{}", sc);

View file

@ -83,7 +83,7 @@ pub fn subcommands_of(p: &Parser) -> Vec<(String, String)> {
if let Some(ref aliases) = p.meta.aliases {
for &(n, _) in aliases {
debugln!("Found alias...{}", n);
let mut als_bin_name: Vec<_> = p.meta.bin_name.as_ref().unwrap().split(" ").collect();
let mut als_bin_name: Vec<_> = p.meta.bin_name.as_ref().unwrap().split(' ').collect();
als_bin_name.push(n);
let old = als_bin_name.len() - 2;
als_bin_name.swap_remove(old);
@ -100,7 +100,7 @@ pub fn subcommands_of(p: &Parser) -> Vec<(String, String)> {
if let Some(ref aliases) = sc.p.meta.aliases {
for &(n, _) in aliases {
debugln!("Found alias...{}", n);
let mut als_bin_name: Vec<_> = p.meta.bin_name.as_ref().unwrap().split(" ").collect();
let mut als_bin_name: Vec<_> = p.meta.bin_name.as_ref().unwrap().split(' ').collect();
als_bin_name.push(n);
let old = als_bin_name.len() - 2;
als_bin_name.swap_remove(old);

View file

@ -294,12 +294,11 @@ fn write_opts_of(p: &Parser) -> String {
conflicts = if conflicts.is_empty() { String::new() } else { format!("({})", conflicts) };
let multiple = if o.is_set(ArgSettings::Multiple) { "*" } else { "" };
let pv = format!("{}",
if let Some(pv_vec) = o.possible_vals() {
let pv = if let Some(pv_vec) = o.possible_vals() {
format!(": :({})", pv_vec.join(" "))
} else {
String::new()
});
};
if let Some(short) = o.short() {
let s = format!("\"{conflicts}{multiple}-{arg}+[{help}]{possible_values}\" \\",
conflicts = conflicts,

View file

@ -159,6 +159,26 @@ OPTIONS:
images. The default is Linear (Bilinear). [values: Nearest, Linear, Cubic, Gaussian,
Lanczos3]";
static ISSUE_702: &'static str = "myapp 1.0
foo
bar
USAGE:
myapp [OPTIONS] [--] [ARGS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-l, --label <label>... a label
-o, --other <other> some other option
-s, --some <some> some option
ARGS:
<arg1> some option
<arg2>... some option";
#[test]
fn help_short() {
let m = App::new("test")
@ -403,4 +423,34 @@ fn issue_688_hidden_pos_vals() {
.long("filter")
.takes_value(true));
test::check_err_output(app3, "ctest --help", ISSUE_688, false);
}
#[test]
fn issue_702_multiple_values() {
let app = App::new("myapp")
.version("1.0")
.author("foo")
.about("bar")
.arg(Arg::with_name("arg1")
.help("some option"))
.arg(Arg::with_name("arg2")
.multiple(true)
.help("some option"))
.arg(Arg::with_name("some")
.help("some option")
.short("s")
.long("some")
.takes_value(true))
.arg(Arg::with_name("other")
.help("some other option")
.short("o")
.long("other")
.takes_value(true))
.arg(Arg::with_name("label")
.help("a label")
.short("l")
.long("label")
.multiple(true)
.takes_value(true));
test::check_err_output(app, "myapp --help", ISSUE_702, false);
}