Skip to content

Commit a353605

Browse files
committed
feat(v2): implementing the base of 2.x
This commit implements the base changes for clap 2.x
1 parent 6164a29 commit a353605

22 files changed

+2814
-2899
lines changed

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "clap"
4-
version = "1.5.5"
4+
version = "2.0.0"
55
authors = ["Kevin K. <[email protected]>"]
66
exclude = ["examples/*", "clap-tests/*", "tests/*", "benches/*", "*.png", "clap-perf/*"]
77
description = "A simple to use, efficient, and full featured Command Line Argument Parser"
@@ -28,4 +28,3 @@ lints = ["clippy", "nightly"]
2828
nightly = [] # for building with nightly and unstable features
2929
unstable = ["lints", "nightly"] # for building with travis-cargo
3030
debug = [] # for building with debug messages
31-

src/app/macros.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
macro_rules! remove_overriden {
22
($me:ident, $name:expr) => ({
3-
if let Some(ref o) = $me.opts.iter().filter(|o| &o.name == $name).next() {
3+
if let Some(ref o) = $me.opts.iter().filter(|o| o.name == *$name).next() {
44
if let Some(ref ora) = o.requires {
55
for a in ora {
66
vec_remove!($me.required, a);
@@ -16,7 +16,7 @@ macro_rules! remove_overriden {
1616
vec_remove!($me.overrides, a);
1717
}
1818
}
19-
} else if let Some(ref o) = $me.flags.iter().filter(|f| &f.name == $name).next() {
19+
} else if let Some(ref o) = $me.flags.iter().filter(|f| f.name == *$name).next() {
2020
if let Some(ref ora) = o.requires {
2121
for a in ora {
2222
vec_remove!($me.required, a);
@@ -32,7 +32,7 @@ macro_rules! remove_overriden {
3232
vec_remove!($me.overrides, a);
3333
}
3434
}
35-
} else if let Some(p) = $me.positionals.values().filter(|p| &&p.name == &$name).next() {
35+
} else if let Some(p) = $me.positionals.values().filter(|p| p.name == *$name).next() {
3636
if let Some(ref ora) = p.requires {
3737
for a in ora {
3838
vec_remove!($me.required, a);
@@ -57,14 +57,14 @@ macro_rules! arg_post_processing(
5757
use args::AnyArg;
5858
// Handle POSIX overrides
5959
if $me.overrides.contains(&$arg.name()) {
60-
if let Some(ref name) = $me.overriden_from($arg.name(), $matcher) {
60+
if let Some(ref name) = $me.overriden_from(&*$arg.name(), $matcher) {
6161
$matcher.remove(name);
6262
remove_overriden!($me, name);
6363
}
6464
}
6565
if let Some(or) = $arg.overrides() {
6666
for pa in or {
67-
$matcher.remove(pa);
67+
$matcher.remove(&*pa);
6868
remove_overriden!($me, pa);
6969
$me.overrides.push(pa);
7070
vec_remove!($me.required, pa);
@@ -83,7 +83,7 @@ macro_rules! arg_post_processing(
8383
// list
8484
if let Some(reqs) = $arg.requires() {
8585
for n in reqs {
86-
if $matcher.contains(n) {
86+
if $matcher.contains(&*n) {
8787
continue;
8888
}
8989

@@ -109,7 +109,7 @@ macro_rules! _handle_group_reqs{
109109
}
110110
}
111111
if let Some(ref bl) = grp.conflicts {
112-
for b in bl {
112+
for &b in bl {
113113
$me.blacklist.push(b);
114114
}
115115
}
@@ -118,7 +118,7 @@ macro_rules! _handle_group_reqs{
118118
}
119119
}
120120
if found {
121-
for name in grp.args.iter() {
121+
for name in &grp.args {
122122
if name == &$arg.name() { continue }
123123
vec_remove!($me.required, name);
124124

src/app/meta.rs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
pub struct AppMeta<'b> {
2+
// The name displayed to the user when showing version and help/usage information
3+
pub name: String,
4+
pub bin_name: Option<String>,
5+
// A string of author(s) if desired. Displayed when showing help/usage information
6+
pub author: Option<&'b str>,
7+
// The version displayed to the user
8+
pub version: Option<&'b str>,
9+
// A brief explanation of the program that gets displayed to the user when shown
10+
// help/usage
11+
// information
12+
pub about: Option<&'b str>,
13+
// Additional help information
14+
pub more_help: Option<&'b str>,
15+
pub usage_str: Option<&'b str>,
16+
pub usage: Option<String>,
17+
pub help_str: Option<&'b str>,
18+
}
19+
20+
impl<'b> Default for AppMeta<'b> {
21+
fn default() -> Self {
22+
AppMeta {
23+
name: String::new(),
24+
author: None,
25+
about: None,
26+
more_help: None,
27+
version: None,
28+
usage_str: None,
29+
usage: None,
30+
bin_name: None,
31+
help_str: None,
32+
}
33+
}
34+
}
35+
36+
impl<'b> AppMeta<'b> {
37+
pub fn new() -> Self { Default::default() }
38+
pub fn with_name(s: String) -> Self {
39+
AppMeta {
40+
name: s,
41+
..Default::default()
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)