Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes, new setting, code clean up, and added support u64::max values per arg #408

Merged
merged 13 commits into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
<a name="v2.0.3"></a>
### v2.0.3 (2016-02-02)


#### Improvements

* **values:** adds support for up to u64::max values per arg ([c7abf7d7](https://github.com/kbknapp/clap-rs/commit/c7abf7d7611e317b0d31d97632e3d2e13570947c))
* **occurrences:** Allow for more than 256 occurrences of an argument. ([3731ddb3](https://github.com/kbknapp/clap-rs/commit/3731ddb361163f3d6b86844362871e48c80fa530))

#### Features

* **AppSettings:** adds HidePossibleValuesInHelp to skip writing those values ([cdee7a0e](https://github.com/kbknapp/clap-rs/commit/cdee7a0eb2beeec723cb98acfacf03bf629c1da3))

#### Bug Fixes

* **value_t_or_exit:** fixes typo which causes value_t_or_exit to return a Result ([ee96baff](https://github.com/kbknapp/clap-rs/commit/ee96baffd306cb8d20ddc5575cf739bb1a6354e8))


<a name="v2.0.2"></a>
### v2.0.2 (2016-01-31)

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

name = "clap"
version = "2.0.2"
version = "2.0.3"
authors = ["Kevin K. <kbknapp@gmail.com>"]
exclude = ["examples/*", "clap-tests/*", "tests/*", "benches/*", "*.png", "clap-perf/*"]
description = "A simple to use, efficient, and full featured Command Line Argument Parser"
Expand All @@ -17,7 +17,7 @@ vec_map = "~0.4"
ansi_term = { version = "~0.7", optional = true }
strsim = { version = "~0.4.0", optional = true }
yaml-rust = { version = "~0.3", optional = true }
clippy = { version = "~0.0.35", optional = true }
clippy = { version = "~0.0.37", optional = true }

[features]
default = ["suggestions", "color"]
Expand Down
4 changes: 2 additions & 2 deletions clap-tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
-V, --version Prints version information

OPTIONS:
-O, --Option <option3> tests options with specific value sets [values: fast slow]
-O, --Option <option3> tests options with specific value sets [values: fast, slow]
--long-option-2 <option2> tests long options with exclusions
--maxvals3 <maxvals>... Tests 3 max vals
--minvals2 <minvals>... Tests 2 min vals
Expand All @@ -33,7 +33,7 @@
ARGS:
positional tests positionals
positional2 tests positionals with exclusions
positional3... tests positionals with specific values
positional3... tests positionals with specific values [values: vi, emacs]

SUBCOMMANDS:
help Prints this message
Expand Down
118 changes: 37 additions & 81 deletions src/app/macros.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,28 @@
macro_rules! remove_overriden {
($me:ident, $name:expr) => ({
(@remove $_self:ident, $v:ident, $a:ident.$ov:ident) => {
if let Some(ref ora) = $a.$ov {
vec_remove_all!($_self.$v, ora);
}
};
(@arg $_self:ident, $arg:ident) => {
remove_overriden!(@remove $_self, required, $arg.requires);
remove_overriden!(@remove $_self, blacklist, $arg.blacklist);
remove_overriden!(@remove $_self, overrides, $arg.overrides);
};
($_self:ident, $name:expr) => {
debugln!("macro=remove_overriden!;");
if let Some(ref o) = $me.opts.iter().filter(|o| o.name == *$name).next() {
if let Some(ref ora) = o.requires {
for a in ora {
vec_remove!($me.required, a);
}
}
if let Some(ref ora) = o.blacklist {
for a in ora {
vec_remove!($me.blacklist, a);
}
}
if let Some(ref ora) = o.overrides {
for a in ora {
vec_remove!($me.overrides, a);
}
}
} else if let Some(ref o) = $me.flags.iter().filter(|f| f.name == *$name).next() {
if let Some(ref ora) = o.requires {
for a in ora {
vec_remove!($me.required, a);
}
}
if let Some(ref ora) = o.blacklist {
for a in ora {
vec_remove!($me.blacklist, a);
}
}
if let Some(ref ora) = o.overrides {
for a in ora {
vec_remove!($me.overrides, a);
}
}
} else if let Some(p) = $me.positionals.values().filter(|p| p.name == *$name).next() {
if let Some(ref ora) = p.requires {
for a in ora {
vec_remove!($me.required, a);
}
}
if let Some(ref ora) = p.blacklist {
for a in ora {
vec_remove!($me.blacklist, a);
}
}
if let Some(ref ora) = p.overrides {
for a in ora {
vec_remove!($me.overrides, a);
}
}
if let Some(ref o) = $_self.opts.iter().filter(|o| o.name == *$name).next() {
remove_overriden!(@arg $_self, o);
} else if let Some(ref f) = $_self.flags.iter().filter(|f| f.name == *$name).next() {
remove_overriden!(@arg $_self, f);
} else if let Some(p) = $_self.positionals.values().filter(|p| p.name == *$name).next() {
remove_overriden!(@arg $_self, p);
}
})
};
}

macro_rules! arg_post_processing(
($me:ident, $arg:ident, $matcher:ident) => ({
use args::AnyArg;
macro_rules! arg_post_processing {
($me:ident, $arg:ident, $matcher:ident) => {
debugln!("macro=arg_post_processing!;");
// Handle POSIX overrides
debug!("Is '{}' in overrides...", $arg.to_string());
Expand All @@ -70,24 +37,20 @@ macro_rules! arg_post_processing(
// Add overrides
debug!("Does '{}' have overrides...", $arg.to_string());
if let Some(or) = $arg.overrides() {
for pa in or {
sdebugln!("\tYes '{}'", pa);
$matcher.remove(&*pa);
remove_overriden!($me, pa);
$me.overrides.push(pa);
vec_remove!($me.required, pa);
}
sdebugln!("Yes");
$matcher.remove_all(or);
for pa in or { remove_overriden!($me, pa); }
$me.overrides.extend(or);
vec_remove_all!($me.required, or);
} else { sdebugln!("No"); }

// Handle conflicts
debug!("Does '{}' have conflicts...", $arg.to_string());
if let Some(bl) = $arg.blacklist() {
for name in bl {
sdebugln!("\n\tYes '{}'", name);
$me.blacklist.push(name);
vec_remove!($me.overrides, name);
vec_remove!($me.required, name);
}
sdebugln!("Yes");
$me.blacklist.extend(bl);
vec_remove_all!($me.overrides, bl);
vec_remove_all!($me.required, bl);
} else { sdebugln!("No"); }

// Add all required args which aren't already found in matcher to the master
Expand All @@ -105,8 +68,8 @@ macro_rules! arg_post_processing(
} else { sdebugln!("No"); }

_handle_group_reqs!($me, $arg);
})
);
};
}

macro_rules! _handle_group_reqs{
($me:ident, $arg:ident) => ({
Expand All @@ -118,26 +81,19 @@ macro_rules! _handle_group_reqs{
if name == &$arg.name() {
vec_remove!($me.required, name);
if let Some(ref reqs) = grp.requires {
for r in reqs {
$me.required.push(r);
}
$me.required.extend(reqs);
}
if let Some(ref bl) = grp.conflicts {
for &b in bl {
$me.blacklist.push(b);
}
$me.blacklist.extend(bl);
}
found = true;
found = true; // What if arg is in more than one group with different reqs?
break;
}
}
if found {
for name in &grp.args {
if name == &$arg.name() { continue }
vec_remove!($me.required, name);

$me.blacklist.push(name);
}
vec_remove_all!($me.required, &grp.args);
$me.blacklist.extend(&grp.args);
vec_remove!($me.blacklist, &$arg.name());
}
}
})
Expand Down
1 change: 1 addition & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ impl<'a, 'b> App<'a, 'b> {
/// ```
pub fn args_from_usage(mut self, usage: &'a str) -> Self {
for l in usage.lines() {
if l.len() == 0 { continue; }
self.0.add_arg(&Arg::from_usage(l.trim()));
}
self
Expand Down
Loading