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

Issues 740,742,744,753,754 #755

Merged
merged 19 commits into from
Nov 21, 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
4 changes: 3 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Contributions are always welcome! Please use the following guidelines when contr
- `chore` - Catch all or things that have to do with the build system, etc
- `examples` - Changes to existing example, or a new example
* The `COMPONENT` is optional, and may be a single file, directory, or logical component. Can be omitted if commit applies globally
5. Run the tests (`cargo test --no-std-features && cargo test --features yaml`)
5. Run the tests (`cargo test --features "yaml unstable"`)
5. Run the lints (`cargo build --features lints`) (requires a nightly compiler)
6. `git rebase` into concise commits and remove `--fixup`s (`git rebase -i HEAD~NUM` where `NUM` is number of commits back)
7. Push your changes back to your fork (`git push origin $your-branch`)
8. Create a pull request! (You can also create the pull request first, and we'll merge when ready. This a good way to discuss proposed changes.)
Expand All @@ -35,6 +36,7 @@ There are a few goals of `clap` that I'd like to maintain throughout contributio
* Remain backwards compatible when possible
- If backwards compatibility *must* be broken, use deprecation warnings if at all possible before removing legacy code
- This does not apply for security concerns
- `clap` officially supports the current stable version of Rust, minus two releases (i.e. if 1.13.0 is current, `clap` must support 1.11.0 and beyond)
* Parse arguments quickly
- Parsing of arguments shouldn't slow down usage of the main program
- This is also true of generating help and usage information (although *slightly* less stringent, as the program is about to exit)
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ language: rust
cache: cargo
rust:
- nightly
- nightly-2016-11-06
- nightly-2016-11-20
- beta
- stable
- 1.11.0
matrix:
allow_failures:
- rust: nightly
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
<a name="v2.19.0"></a>
## v2.19.0 (2016-11-21)

#### Features

* allows specifying AllowLeadingHyphen style values, but only for specific args vice command wide ([c0d70feb](https://github.com/kbknapp/clap-rs/commit/c0d70febad9996a77a54107054daf1914c50d4ef), closes [#742](https://github.com/kbknapp/clap-rs/issues/742))

#### Bug Fixes

* **Required Unless:** fixes a bug where having required_unless set doesn't work when conflicts are also set ([d20331b6](https://github.com/kbknapp/clap-rs/commit/d20331b6f7940ac3a4e919999f8bb4780875125d), closes [#753](https://github.com/kbknapp/clap-rs/issues/753))
* **ZSH Completions:** fixes an issue where zsh completions caused panics if there were no subcommands ([49e7cdab](https://github.com/kbknapp/clap-rs/commit/49e7cdab76dd1ccc07221e360f07808ec62648aa), closes [#754](https://github.com/kbknapp/clap-rs/issues/754))

#### Improvements

* **Validators:** improves the error messages for validators ([65eb3385](https://github.com/kbknapp/clap-rs/commit/65eb33859d3ff53e7d3277f02a9d3fd9038a9dfb), closes [#744](https://github.com/kbknapp/clap-rs/issues/744))

#### Documentation

* updates the docs landing page ([01e1e33f](https://github.com/kbknapp/clap-rs/commit/01e1e33f377934099a4a725fab5cd6c5ff50eaa2))
* adds the macro version back to the readme ([45eb9bf1](https://github.com/kbknapp/clap-rs/commit/45eb9bf130329c3f3853aba0342c2fe3c64ff80f))
* fix broken docs links ([808e7cee](https://github.com/kbknapp/clap-rs/commit/808e7ceeb86d4a319bdc270f51c23a64621dbfb3))
* **Compatibility Policy:** adds an official compatibility policy to ([760d66dc](https://github.com/kbknapp/clap-rs/commit/760d66dc17310b357f257776624151da933cd25d), closes [#740](https://github.com/kbknapp/clap-rs/issues/740))
* **Contributing:** updates the readme to improve the readability and contributing sections ([eb51316c](https://github.com/kbknapp/clap-rs/commit/eb51316cdfdc7258d287ba13b67ef2f42bd2b8f6))

<a name="v2.18.0"></a>
## v2.18.0 (2016-11-05)

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ ansi_term = { version = "~0.9.0", optional = true }
term_size = { version = "~0.2.0", optional = true }
libc = { version = "~0.2.9", optional = true }
yaml-rust = { version = "~0.3.2", optional = true }
clippy = { version = "~0.0.98", optional = true }
clippy = { version = "~0.0.100", optional = true }

[dev-dependencies]
regex = "~0.1.69"
regex = "~0.1.80"

[features]
default = ["suggestions", "color", "wrap_help"]
Expand Down
393 changes: 150 additions & 243 deletions README.md

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,26 @@
run-test TEST:
cargo test --test {{TEST}}

debug TEST:
cargo test --test {{TEST}} --features debug

run-tests:
cargo test --features "yaml unstable"

lint:
@bench: nightly
cargo bench && just remove-nightly

nightly:
rustup override add nightly
cargo build --features lints && rustup override remove

remove-nightly:
rustup override remove

@lint: nightly
cargo build --features lints && just remove-nightly

clean:
cargo clean
find . -type f -name "*.orig" -exec rm {} \;
find . -type f -name "*.bk" -exec rm {} \;
find . -type f -name ".*~" -exec rm {} \;
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
format_strings = false
chain_overflow_last = false
same_line_if_else = true
fn_single_line = true
20 changes: 5 additions & 15 deletions src/app/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ use vec_map::VecMap;

#[cfg(not(feature = "wrap_help"))]
mod term_size {
pub fn dimensions() -> Option<(usize, usize)> {
None
}
pub fn dimensions() -> Option<(usize, usize)> { None }
}

fn str_width(s: &str) -> usize {
UnicodeWidthStr::width(s)
}
fn str_width(s: &str) -> usize { UnicodeWidthStr::width(s) }

const TAB: &'static str = " ";

Expand All @@ -42,19 +38,13 @@ trait ArgWithOrder<'b, 'c>: ArgWithDisplay<'b, 'c> + DispOrder {
impl<'b, 'c, T> ArgWithOrder<'b, 'c> for T
where T: ArgWithDisplay<'b, 'c> + DispOrder
{
fn as_base(&self) -> &ArgWithDisplay<'b, 'c> {
self
}
fn as_base(&self) -> &ArgWithDisplay<'b, 'c> { self }
}

fn as_arg_trait<'a, 'b, T: ArgWithOrder<'a, 'b>>(x: &T) -> &ArgWithOrder<'a, 'b> {
x
}
fn as_arg_trait<'a, 'b, T: ArgWithOrder<'a, 'b>>(x: &T) -> &ArgWithOrder<'a, 'b> { x }

impl<'b, 'c> DispOrder for App<'b, 'c> {
fn disp_ord(&self) -> usize {
999
}
fn disp_ord(&self) -> usize { 999 }
}

macro_rules! color {
Expand Down
95 changes: 53 additions & 42 deletions src/app/macros.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
macro_rules! remove_overriden {
(@remove $_self:ident, $v:ident, $a:ident.$ov:ident) => {
if let Some(ref ora) = $a.$ov {
if let Some(ref ora) = $a.$ov() {
vec_remove_all!($_self.$v, ora);
}
};
Expand All @@ -11,11 +11,11 @@ macro_rules! remove_overriden {
};
($_self:ident, $name:expr) => {
debugln!("macro=remove_overriden!;");
if let Some(ref o) = $_self.opts.iter().filter(|o| o.name == *$name).next() {
if let Some(ref o) = $_self.opts.iter().filter(|o| o.b.name == *$name).next() {
remove_overriden!(@arg $_self, o);
} else if let Some(ref f) = $_self.flags.iter().filter(|f| f.name == *$name).next() {
} else if let Some(ref f) = $_self.flags.iter().filter(|f| f.b.name == *$name).next() {
remove_overriden!(@arg $_self, f);
} else if let Some(p) = $_self.positionals.values().filter(|p| p.name == *$name).next() {
} else if let Some(p) = $_self.positionals.values().filter(|p| p.b.name == *$name).next() {
remove_overriden!(@arg $_self, p);
}
};
Expand Down Expand Up @@ -55,20 +55,7 @@ macro_rules! arg_post_processing {
if $matcher.contains(c) {
sdebugln!("Yes");
// find who blacklisted us...
$me.blacklist.push(&$arg.name);
// if let Some(f) = $me.find_flag_mut(c) {
// if let Some(ref mut bl) = f.blacklist {
// bl.push(&$arg.name);
// }
// } else if let Some(o) = $me.find_option_mut(c) {
// if let Some(ref mut bl) = o.blacklist {
// bl.push(&$arg.name);
// }
// } else if let Some(p) = $me.find_positional_mut(c) {
// if let Some(ref mut bl) = p.blacklist {
// bl.push(&$arg.name);
// }
// }
$me.blacklist.push(&$arg.b.name);
} else {
sdebugln!("No");
}
Expand Down Expand Up @@ -130,7 +117,7 @@ macro_rules! _handle_group_reqs{
macro_rules! validate_multiples {
($_self:ident, $a:ident, $m:ident) => {
debugln!("macro=validate_multiples!;");
if $m.contains(&$a.name) && !$a.settings.is_set(ArgSettings::Multiple) {
if $m.contains(&$a.b.name) && !$a.b.settings.is_set(ArgSettings::Multiple) {
// Not the first time, and we don't allow multiples
return Err(Error::unexpected_multiple_usage($a,
&*$_self.create_current_usage($m),
Expand All @@ -155,16 +142,14 @@ macro_rules! parse_positional {
$pos_counter == $_self.positionals.len()) {
$_self.trailing_vals = true;
}
if let Err(e) = $_self.add_val_to_arg($p, &$arg_os, $matcher) {
return Err(e);
}
let _ = try!($_self.add_val_to_arg($p, &$arg_os, $matcher));

$matcher.inc_occurrence_of($p.name);
let _ = $_self.groups_for_arg($p.name)
$matcher.inc_occurrence_of($p.b.name);
let _ = $_self.groups_for_arg($p.b.name)
.and_then(|vec| Some($matcher.inc_occurrences_of(&*vec)));
arg_post_processing!($_self, $p, $matcher);
// Only increment the positional counter if it doesn't allow multiples
if !$p.settings.is_set(ArgSettings::Multiple) {
if !$p.b.settings.is_set(ArgSettings::Multiple) {
$pos_counter += 1;
}
};
Expand All @@ -174,24 +159,24 @@ macro_rules! find_from {
($_self:ident, $arg_name:expr, $from:ident, $matcher:expr) => {{
let mut ret = None;
for k in $matcher.arg_names() {
if let Some(f) = $_self.find_flag(k) {
if let Some(ref v) = f.$from {
if let Some(f) = find_by_name!($_self, &k, flags, iter) {
if let Some(ref v) = f.$from() {
if v.contains($arg_name) {
ret = Some(f.to_string());
}
}
}
if let Some(o) = $_self.find_option(k) {
if let Some(ref v) = o.$from {
if let Some(o) = find_by_name!($_self, &k, opts, iter) {
if let Some(ref v) = o.$from() {
if v.contains(&$arg_name) {
ret = Some(o.to_string());
}
}
}
if let Some(pos) = $_self.find_positional(k) {
if let Some(ref v) = pos.$from {
if let Some(pos) = find_by_name!($_self, &k, positionals, values) {
if let Some(ref v) = pos.$from() {
if v.contains($arg_name) {
ret = Some(pos.name.to_owned());
ret = Some(pos.b.name.to_owned());
}
}
}
Expand All @@ -204,28 +189,54 @@ macro_rules! find_name_from {
($_self:ident, $arg_name:expr, $from:ident, $matcher:expr) => {{
let mut ret = None;
for k in $matcher.arg_names() {
if let Some(f) = $_self.find_flag(k) {
if let Some(ref v) = f.$from {
if let Some(f) = find_by_name!($_self, &k, flags, iter) {
if let Some(ref v) = f.$from() {
if v.contains($arg_name) {
ret = Some(f.name);
ret = Some(f.b.name);
}
}
}
if let Some(o) = $_self.find_option(k) {
if let Some(ref v) = o.$from {
if let Some(o) = find_by_name!($_self, &k, opts, iter) {
if let Some(ref v) = o.$from() {
if v.contains(&$arg_name) {
ret = Some(o.name);
ret = Some(o.b.name);
}
}
}
if let Some(pos) = $_self.find_positional(k) {
if let Some(ref v) = pos.$from {
if let Some(pos) = find_by_name!($_self, &k, positionals, values) {
if let Some(ref v) = pos.$from() {
if v.contains($arg_name) {
ret = Some(pos.name);
ret = Some(pos.b.name);
}
}
}
}
ret
}};
}
}

// Finds an arg by name
macro_rules! find_by_name {
($_self:ident, $name:expr, $what:ident, $how:ident) => {
$_self.$what.$how().find(|o| &o.b.name == $name)
}
}

// Finds an option including if it's aliasesed
macro_rules! find_by_long {
($_self:ident, $long:expr, $what:ident) => {
$_self.$what
.iter()
.filter(|o| o.s.long.is_some())
.find(|o| {
&&o.s.long.unwrap() == &$long ||
(o.s.aliases.is_some() &&
o.s
.aliases
.as_ref()
.unwrap()
.iter()
.any(|&(alias, _)| &&alias == &$long))
})
}
}
8 changes: 2 additions & 6 deletions src/app/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ impl<'b> Default for AppMeta<'b> {
}

impl<'b> AppMeta<'b> {
pub fn new() -> Self {
Default::default()
}
pub fn with_name(s: String) -> Self {
AppMeta { name: s, ..Default::default() }
}
pub fn new() -> Self { Default::default() }
pub fn with_name(s: String) -> Self { AppMeta { name: s, ..Default::default() } }
}

impl<'b> Clone for AppMeta<'b> {
Expand Down
Loading