Skip to content

Commit

Permalink
Auto merge of #407 - kbknapp:fixrollup, r=kbknapp
Browse files Browse the repository at this point in the history
Fixrollup
  • Loading branch information
homu committed Feb 1, 2016
2 parents f50b8db + 2564b3a commit 91cf46f
Show file tree
Hide file tree
Showing 12 changed files with 1,050 additions and 917 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<a name="v2.0.2"></a>
### v2.0.2 (2016-01-31)


#### Improvements

* **arg_enum:** enum declared with arg_enum returns [&'static str; #] instead of Vec ([9c4b8a1a](https://github.com/kbknapp/clap-rs/commit/9c4b8a1a6b12949222f17d1074578ad7676b9c0d))

#### Bug Fixes

* clap_app! should be gated by unstable, not nightly feature ([0c8b84af](https://github.com/kbknapp/clap-rs/commit/0c8b84af6161d5baf683688eafc00874846f83fa))
* **SubCommands:** fixed where subcmds weren't recognized after mult args ([c19c17a8](https://github.com/kbknapp/clap-rs/commit/c19c17a8850602990e24347aeb4427cf43316223), closes [#405](https://github.com/kbknapp/clap-rs/issues/405))
* **Usage Parser:** fixes a bug where literal single quotes weren't allowed in help strings ([0bcc7120](https://github.com/kbknapp/clap-rs/commit/0bcc71206478074769e311479b34a9f74fe80f5c), closes [#406](https://github.com/kbknapp/clap-rs/issues/406))


<a name="v2.0.1"></a>
### v2.0.1 (2016-01-30)

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

name = "clap"
version = "2.0.1"
version = "2.0.2"
authors = ["Kevin K. <[email protected]>"]
exclude = ["examples/*", "clap-tests/*", "tests/*", "benches/*", "*.png", "clap-perf/*"]
description = "A simple to use, efficient, and full featured Command Line Argument Parser"
Expand Down
2 changes: 1 addition & 1 deletion examples/13a_enum_values_automatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() {
let m = App::new("myapp")
// Use a single positional argument that is required
.arg(Arg::from_usage("<foo> 'The Foo to use'")
.possible_values(&*Foo::variants()))
.possible_values(&Foo::variants()))
.arg(Arg::from_usage("<speed> 'The speed to use'")
// You can define a list of possible values if you want the values to be
// displayed in the help information. Whether you use possible_values() or
Expand Down
9 changes: 4 additions & 5 deletions src/app/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {

// Has the user already passed '--'?
if !pos_only {
if !starts_new_arg || self.is_set(AppSettings::AllowLeadingHyphen) {
let pos_sc = self.subcommands.iter().any(|s| &s.0.meta.name[..] == &*arg_os);
if (!starts_new_arg || self.is_set(AppSettings::AllowLeadingHyphen)) && !pos_sc {
// Check to see if parsing a value from an option
if let Some(nvo) = needs_val_of {
// get the OptBuilder so we can check the settings
Expand Down Expand Up @@ -488,13 +489,11 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
}
}

// let arg_str = arg_os.to_str().expect(INVALID_UTF8);
if self.subcommands.iter().any(|s| &s.0.meta.name[..] == &*arg_os) {
if pos_sc {
if &*arg_os == "help" &&
self.settings.is_set(AppSettings::NeedsSubcommandHelp) {
return self._help();
}
// subcommands only support valid UTF-8
subcmd_name = Some(arg_os.to_str().expect(INVALID_UTF8).to_owned());
break;
} else if let Some(candidate) = suggestions::did_you_mean(
Expand Down Expand Up @@ -618,7 +617,7 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
mid_string.push_str(" ");
if let Some(ref mut sc) = self.subcommands
.iter_mut()
.filter(|s| &s.0.meta.name[..] == &sc_name)
.filter(|s| &s.0.meta.name == &sc_name)
.next() {
let mut sc_matcher = ArgMatcher::new();
// bin_name should be parent's bin_name + [<reqs>] + the sc's name separated by
Expand Down
3 changes: 3 additions & 0 deletions src/args/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ impl<'a, 'b> Arg<'a, 'b> {
/// **NOTE**: Not all settings may be set using the usage string method. Some properties are
/// only available via the builder pattern.
///
/// **NOTE**: Only ASCII values in `from_usage` strings are officially supported. Some UTF-8
/// codepoints may work just fine, but this is not guaranteed.
///
/// # Syntax
///
/// Usage strings typically following the form:
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright ⓒ 2015-2016 Kevin B. Knapp and clap-rs contributors.
// Licensed under the MIT license
// (see LICENSE or <http://opensource.org/licenses/MIT>) All files in the project carrying such
// notice may not be copied, modified, or distributed except according to those terms.

//! A simple to use, efficient, and full featured library for parsing command line arguments and subcommands when writing console, or terminal applications.
//!
//! ## About
Expand Down
33 changes: 31 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,35 @@ macro_rules! values_t_or_exit {
};
}

// _clap_count_exprs! is derived from https://github.com/DanielKeep/rust-grabbag
// commit: 82a35ca5d9a04c3b920622d542104e3310ee5b07
// License: MIT
// Copyright ⓒ 2015 grabbag contributors.
// Licensed under the MIT license (see LICENSE or <http://opensource.org
// /licenses/MIT>) or the Apache License, Version 2.0 (see LICENSE of
// <http://www.apache.org/licenses/LICENSE-2.0>), at your option. All
// files in the project carrying such notice may not be copied, modified,
// or distributed except according to those terms.
//
/// Counts the number of comma-delimited expressions passed to it. The result is a compile-time
/// evaluable expression, suitable for use as a static array size, or the value of a `const`.
///
/// # Examples
///
/// ```
/// # #[macro_use] extern crate clap;
/// # fn main() {
/// const COUNT: usize = _clap_count_exprs!(a, 5+1, "hi there!".into_string());
/// assert_eq!(COUNT, 3);
/// # }
/// ```
#[macro_export]
macro_rules! _clap_count_exprs {
() => { 0 };
($e:expr) => { 1 };
($e:expr, $($es:expr),+) => { 1 + _clap_count_exprs!($($es),*) };
}

/// Convenience macro to generate more complete enums with variants to be used as a type when
/// parsing arguments. This enum also provides a `variants()` function which can be used to
/// retrieve a `Vec<&'static str>` of the variant names, as well as implementing `FromStr` and
Expand Down Expand Up @@ -284,8 +313,8 @@ macro_rules! arg_enum {
}
impl $e {
#[allow(dead_code)]
pub fn variants() -> Vec<&'static str> {
vec![
pub fn variants() -> [&'static str; _clap_count_exprs!($(stringify!($v)),+)] {
[
$(stringify!($v),)+
]
}
Expand Down
Loading

0 comments on commit 91cf46f

Please sign in to comment.