Merge pull request #1048 from kbknapp/issues-1046,1047

Issues 1046,1047
This commit is contained in:
Kevin K 2017-09-15 11:09:20 -07:00 committed by GitHub
commit 6e948994a6
7 changed files with 72 additions and 8 deletions

View file

@ -1,3 +1,17 @@
<a name="v2.26.2"></a>
### v2.26.2 (2017-09-14)
#### Improvements
* if all subcommands are hidden, the subcommands section of the help message is no longer displayed ([4ae7b046](https://github.com/kbknapp/clap-rs/commit/4ae7b0464750bc07ec80ece38e43f003fdd1b8ae), closes [#1046](https://github.com/kbknapp/clap-rs/issues/1046))
#### Bug Fixes
* fixes a bug where default values are not applied if the option supports zero values ([9c248cbf](https://github.com/kbknapp/clap-rs/commit/9c248cbf7d8a825119bc387c23e9a1d1989682b0), closes [#1047](https://github.com/kbknapp/clap-rs/issues/1047))
<a name="v2.26.1"></a>
### v2.26.1 (2017-09-14)

View file

@ -1,7 +1,7 @@
[package]
name = "clap"
version = "2.26.1"
version = "2.26.2"
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

@ -45,8 +45,10 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
## What's New
Here's what's new in 2.26.1:
Here's what's new in 2.26.2:
* if all subcommands are hidden, the subcommands section of the help message is no longer displayed
* fixes a bug where default values are not applied if the option supports zero values
* fixes using require_equals(true) and min_values(0) together
* escape special characters in zsh and fish completions
* avoid panic generating default help msg if term width set to 0 due to bug in textwrap 0.7.0

View file

@ -521,7 +521,7 @@ impl<'a> Help<'a> {
.filter(|arg| !arg.is_set(ArgSettings::Hidden))
.count() > 0;
let opts = parser.has_opts();
let subcmds = parser.has_subcommands();
let subcmds = parser.has_visible_subcommands();
let unified_help = parser.is_set(AppSettings::UnifiedHelpMessage);

View file

@ -475,10 +475,7 @@ impl<'a, 'b> Parser<'a, 'b>
#[inline]
pub fn has_visible_subcommands(&self) -> bool {
if self.subcommands.is_empty() {
return false;
}
self.subcommands.iter().any(|s| !s.p.is_set(AS::Hidden))
self.has_subcommands() && self.subcommands.iter().filter(|sc| sc.p.meta.name != "help").any(|sc| !sc.p.is_set(AS::Hidden))
}
#[inline]
@ -1734,7 +1731,14 @@ impl<'a, 'b> Parser<'a, 'b>
macro_rules! add_val {
(@default $_self:ident, $a:ident, $m:ident) => {
if let Some(ref val) = $a.v.default_val {
if $m.get($a.b.name).is_none() {
if $m.get($a.b.name).map(|ma| ma.vals.len()).map(|len| len == 0).unwrap_or(false) {
$_self.add_val_to_arg($a, OsStr::new(val), $m)?;
if $_self.cache.map_or(true, |name| name != $a.name()) {
arg_post_processing!($_self, $a, $m);
$_self.cache = Some($a.name());
}
} else {
$_self.add_val_to_arg($a, OsStr::new(val), $m)?;
if $_self.cache.map_or(true, |name| name != $a.name()) {

View file

@ -124,6 +124,22 @@ OPTIONS:
ARGS:
<scpositional> tests positionals";
static ISSUE_1046_HIDDEN_SCS: &'static str = "prog 1.0
USAGE:
prog [FLAGS] [OPTIONS] [PATH]
FLAGS:
-f, --flag testing flags
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-o, --opt <FILE> tests options
ARGS:
<PATH> some";
// Using number_of_values(1) with multiple(true) misaligns help message
static ISSUE_760: &'static str = "ctest 0.1
@ -899,6 +915,17 @@ fn args_negate_sc() {
assert!(test::compare_output(app, "prog --help", ARGS_NEGATE_SC, false));
}
#[test]
fn issue_1046_hidden_scs() {
let app = App::new("prog")
.version("1.0")
.args_from_usage("-f, --flag 'testing flags'
-o, --opt [FILE] 'tests options'")
.arg(Arg::with_name("PATH").help("some"))
.subcommand(SubCommand::with_name("test").setting(AppSettings::Hidden));
assert!(test::compare_output(app, "prog --help", ISSUE_1046_HIDDEN_SCS, false));
}
#[test]
fn issue_777_wrap_all_things() {
let app = App::new("A app with a crazy very long long long name hahaha")

View file

@ -392,4 +392,21 @@ fn issue_665() {
assert!(res.is_err());
assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
}
#[test]
fn issue_1047_min_zero_vals_default_val() {
let m = App::new("foo")
.arg(
Arg::with_name("del")
.short("d")
.long("del")
.takes_value(true)
.require_equals(true)
.min_values(0)
.default_value("default"),
)
.get_matches_from(vec!["foo", "-d"]);
assert_eq!(m.occurrences_of("del"), 1);
assert_eq!(m.value_of("del"), Some("default"));
}