Skip to content

Commit

Permalink
Auto merge of #500 - kbknapp:v2.4.1, r=kbknapp
Browse files Browse the repository at this point in the history
chore: increase version
  • Loading branch information
homu committed May 10, 2016
2 parents c8c20a0 + b42ca0b commit b027c65
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 256 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
<a name="v2.4.3"></a>
### v2.4.3 (2016-05-10)


#### Bug Fixes

* **Usage Strings:**
* now properly dedups args that are also in groups ([3ca0947c](https://github.com/kbknapp/clap-rs/commit/3ca0947c166b4f8525752255e3a4fa6565eb9689), closes [#498](https://github.com/kbknapp/clap-rs/issues/498))
* removes duplicate groups from usage strings ([f574fb8a](https://github.com/kbknapp/clap-rs/commit/f574fb8a7cde4d4a2fa4c4481d59be2d0f135427))

#### Improvements

* **Groups:** formats positional args in groups in a better way ([fef11154](https://github.com/kbknapp/clap-rs/commit/fef11154fb7430d1cbf04a672aabb366e456a368))
* **Help:**
* moves positionals to standard <> formatting ([03dfe5ce](https://github.com/kbknapp/clap-rs/commit/03dfe5ceff1d63f172788ff688567ddad9fe119b))
* default help subcommand string has been shortened ([5b7fe8e4](https://github.com/kbknapp/clap-rs/commit/5b7fe8e4161e43ab19e2e5fcf55fbe46791134e9), closes [#494](https://github.com/kbknapp/clap-rs/issues/494))

<a name="v2.4.2"></a>
### v2.4.3 (2016-05-10)

* Ghost Release

<a name="v2.4.1"></a>
### v2.4.3 (2016-05-10)

* Ghost Release

<a name="v2.4.0"></a>
## v2.4.0 (2016-05-02)

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]

name = "clap"
version = "2.4.0"
version = "2.4.3"
authors = ["Kevin K. <[email protected]>"]
exclude = ["examples/*", "clap-tests/*", "tests/*", "benches/*", "*.png", "clap-perf/*"]
exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"]
description = "A simple to use, efficient, and full featured Command Line Argument Parser"
repository = "https://github.com/kbknapp/clap-rs.git"
documentation = "http://kbknapp.github.io/clap-rs"
Expand All @@ -22,7 +22,7 @@ clippy = { version = "=0.0.64", optional = true }
unicode-width = { version = "~0.1.3", optional = true }

[dev-dependencies]
clap-test = { path = "clap-test/" }
regex = "~0.1.69"

[features]
default = ["suggestions", "color", "wrap_help"]
Expand Down
25 changes: 0 additions & 25 deletions Makefile

This file was deleted.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)

## What's New

Here's what's new in v2.4.3

* Bug Fixes
* Usage strings get de-deuplicated when there are args which are also part ``ArgGroup`s`
* Fixed times when `ArgGroup`s are duplicated in usage strings
* Improvements
* Positional arguments which are part of a group are now formatted in a more readable way (fewer brackets)
* Positional arguments use the standard `<>` brackets to reduce confusion
* The default help string for the `help` subcommand has been shortened to fit in 80 columns

Here's the highlights from v2.4.0

* **Before Help:** adds support for displaying info before help message
Expand Down
165 changes: 165 additions & 0 deletions clap-test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#[allow(unused_imports, dead_code)]
mod test {
use std::str;
use std::io::Write;

use regex::Regex;

use clap::{App, Arg, SubCommand, ArgGroup};

pub fn complex_app() -> App<'static, 'static> {
let args = "-o --option=[opt]... 'tests options'
[positional] 'tests positionals'";
let opt3_vals = ["fast", "slow"];
let pos3_vals = ["vi", "emacs"];
App::new("clap-test")
.version("v1.4.8")
.about("tests clap library")
.author("Kevin K. <[email protected]>")
.args_from_usage(args)
.arg(Arg::from_usage("-f --flag... 'tests flags'")
.global(true))
.args(&[
Arg::from_usage("[flag2] -F 'tests flags with exclusions'").conflicts_with("flag").requires("long-option-2"),
Arg::from_usage("--long-option-2 [option2] 'tests long options with exclusions'").conflicts_with("option").requires("positional2"),
Arg::from_usage("[positional2] 'tests positionals with exclusions'"),
Arg::from_usage("-O --Option [option3] 'specific vals'").possible_values(&opt3_vals),
Arg::from_usage("[positional3]... 'tests specific values'").possible_values(&pos3_vals),
Arg::from_usage("--multvals [one] [two] 'Tests mutliple values, not mult occs'"),
Arg::from_usage("--multvalsmo... [one] [two] 'Tests mutliple values, and mult occs'"),
Arg::from_usage("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
Arg::from_usage("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3)
])
.subcommand(SubCommand::with_name("subcmd")
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <[email protected]>")
.arg_from_usage("-o --option [scoption]... 'tests options'")
.arg_from_usage("[scpositional] 'tests positionals'"))
}

pub fn check_err_output(a: App, args: &str, out: &str, use_stderr: bool) {
let res = a.get_matches_from_safe(args.split(' ').collect::<Vec<_>>());
let re = Regex::new("\x1b[^m]*m").unwrap();

let mut w = vec![];
let err = res.unwrap_err();
err.write_to(&mut w).unwrap();
let err_s = str::from_utf8(&w).unwrap();
assert_eq!(re.replace_all(err_s, ""), out);
assert_eq!(use_stderr, err.use_stderr());
}

pub fn check_help(mut a: App, out: &str) {
// We call a get_matches method to cause --help and --version to be built
let _ = a.get_matches_from_safe_borrow(vec![""]);

// Now we check the output of print_help()
let mut help = vec![];
a.write_help(&mut help).ok().expect("failed to print help");
assert_eq!(str::from_utf8(&help).unwrap(), out);
}

pub fn check_complex_output(args: &str, out: &str) {
let mut w = vec![];
let matches = complex_app().get_matches_from(args.split(' ').collect::<Vec<_>>());
if matches.is_present("flag") {
writeln!(w, "flag present {} times", matches.occurrences_of("flag")).unwrap();
} else {
writeln!(w, "flag NOT present").unwrap();
}

if matches.is_present("option") {
if let Some(v) = matches.value_of("option") {
writeln!(w, "option present {} times with value: {}",matches.occurrences_of("option"), v).unwrap();
}
if let Some(ov) = matches.values_of("option") {
for o in ov {
writeln!(w, "An option: {}", o).unwrap();
}
}
} else {
writeln!(w, "option NOT present").unwrap();
}

if let Some(p) = matches.value_of("positional") {
writeln!(w, "positional present with value: {}", p).unwrap();
} else {
writeln!(w, "positional NOT present").unwrap();
}

if matches.is_present("flag2") {
writeln!(w, "flag2 present").unwrap();
writeln!(w, "option2 present with value of: {}", matches.value_of("long-option-2").unwrap()).unwrap();
writeln!(w, "positional2 present with value of: {}", matches.value_of("positional2").unwrap()).unwrap();
} else {
writeln!(w, "flag2 NOT present").unwrap();
writeln!(w, "option2 maybe present with value of: {}", matches.value_of("long-option-2").unwrap_or("Nothing")).unwrap();
writeln!(w, "positional2 maybe present with value of: {}", matches.value_of("positional2").unwrap_or("Nothing")).unwrap();
}

let _ = match matches.value_of("Option3").unwrap_or("") {
"fast" => writeln!(w, "option3 present quickly"),
"slow" => writeln!(w, "option3 present slowly"),
_ => writeln!(w, "option3 NOT present")
};

let _ = match matches.value_of("positional3").unwrap_or("") {
"vi" => writeln!(w, "positional3 present in vi mode"),
"emacs" => writeln!(w, "positional3 present in emacs mode"),
_ => writeln!(w, "positional3 NOT present")
};

if matches.is_present("option") {
if let Some(v) = matches.value_of("option") {
writeln!(w, "option present {} times with value: {}",matches.occurrences_of("option"), v).unwrap();
}
if let Some(ov) = matches.values_of("option") {
for o in ov {
writeln!(w, "An option: {}", o).unwrap();
}
}
} else {
writeln!(w, "option NOT present").unwrap();
}

if let Some(p) = matches.value_of("positional") {
writeln!(w, "positional present with value: {}", p).unwrap();
} else {
writeln!(w, "positional NOT present").unwrap();
}
if matches.is_present("subcmd") {
writeln!(w, "subcmd present").unwrap();
if let Some(matches) = matches.subcommand_matches("subcmd") {
if matches.is_present("flag") {
writeln!(w, "flag present {} times", matches.occurrences_of("flag")).unwrap();
} else {
writeln!(w, "flag NOT present").unwrap();
}

if matches.is_present("option") {
if let Some(v) = matches.value_of("option") {
writeln!(w, "scoption present with value: {}", v).unwrap();
}
if let Some(ov) = matches.values_of("option") {
for o in ov {
writeln!(w, "An scoption: {}", o).unwrap();
}
}
} else {
writeln!(w, "scoption NOT present").unwrap();
}

if let Some(p) = matches.value_of("scpositional") {
writeln!(w, "scpositional present with value: {}", p).unwrap();
}
}
} else {
writeln!(w, "subcmd NOT present").unwrap();
}

let res = str::from_utf8(&w).unwrap();
assert_eq!(res, out);
}

}
10 changes: 0 additions & 10 deletions clap-test/Cargo.toml

This file was deleted.

Loading

0 comments on commit b027c65

Please sign in to comment.