style(clap): rustfmt run

This commit is contained in:
Kevin K 2015-05-01 14:44:20 -04:00
parent 08635e6b5e
commit 22aef2ab45
14 changed files with 947 additions and 948 deletions

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@ use usageparser::{UsageParser, UsageToken};
/// The abstract representation of a command line argument used by the consumer of the library.
/// Used to set all the options and relationships that define a valid argument for the program.
///
/// This struct is used by the library consumer and describes the command line arguments for
/// This struct is used by the library consumer and describes the command line arguments for
/// their program. Then evaluates the settings the consumer provided and determines the concret
/// argument type to use when parsing.
///
@ -60,18 +60,18 @@ pub struct Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// and `multiple`
#[doc(hidden)]
pub index: Option<u8>,
/// Determines if multiple instances of the same flag are allowed. `multiple`
/// Determines if multiple instances of the same flag are allowed. `multiple`
/// is mutually exclusive with `index` and `takes_value`.
/// I.e. `-v -v -v` or `-vvv`
#[doc(hidden)]
pub multiple: bool,
/// A list of names for other arguments that *may not* be used with this flag
#[doc(hidden)]
pub blacklist: Option<Vec<&'r str>>,
pub blacklist: Option<Vec<&'r str>>,
/// A list of possible values for an option or positional argument
#[doc(hidden)]
pub possible_vals: Option<Vec<&'p str>>,
/// A list of names of other arguments that are *required* to be used when
/// A list of names of other arguments that are *required* to be used when
/// this flag is used
#[doc(hidden)]
pub requires: Option<Vec<&'r str>>,
@ -89,12 +89,12 @@ pub struct Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// Creates a new instace of `Arg` using a unique string name.
/// Creates a new instace of `Arg` using a unique string name.
/// The name will be used by the library consumer to get information about
/// whether or not the argument was used at runtime.
/// whether or not the argument was used at runtime.
///
/// **NOTE:** in the case of arguments that take values (i.e. `takes_value(true)`)
/// and positional arguments (i.e. those without a `-` or `--`) the name will also
/// and positional arguments (i.e. those without a `-` or `--`) the name will also
/// be displayed when the user prints the usage/help information of the program.
///
/// **NOTE:** this function is deprecated in favor of Arg::with_name() to stay consistant with
@ -131,12 +131,12 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
}
/// Creates a new instace of `Arg` using a unique string name.
/// Creates a new instace of `Arg` using a unique string name.
/// The name will be used by the library consumer to get information about
/// whether or not the argument was used at runtime.
/// whether or not the argument was used at runtime.
///
/// **NOTE:** in the case of arguments that take values (i.e. `takes_value(true)`)
/// and positional arguments (i.e. those without a `-` or `--`) the name will also
/// and positional arguments (i.e. those without a `-` or `--`) the name will also
/// be displayed when the user prints the usage/help information of the program.
///
///
@ -182,18 +182,18 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// 3. Long preceded by a `--` (this may be used as the name, if the name is omitted. If the
/// name is *not* omittied, the name takes precedence over the `long`)
/// 4. Value (this can be used as the name if the name is not manually specified. If the name
/// is manually specified, it takes precedence. If this value is used as the name, it uses
/// is manually specified, it takes precedence. If this value is used as the name, it uses
/// the same `[]` and `<>` requirement specification rules. If it is *not* used as the name,
/// it still needs to be surrounded by either `[]` or `<>` but there is no requirement
/// effect, as the requirement rule is determined by the real name. This value may follow
/// it still needs to be surrounded by either `[]` or `<>` but there is no requirement
/// effect, as the requirement rule is determined by the real name. This value may follow
/// the `short` or `long`, it doesn't matter. If it follows the `long`, it may follow either
/// a `=` or ` ` there is no difference, just personal preference. If this follows a `short`
/// it can only be after a ` `) i.e. `-c [name]`, `--config [name]`, `--config=[name]`, etc.
/// 5. Multiple specifier `...` (the `...` may follow the name, `short`, `long`, or value
/// 5. Multiple specifier `...` (the `...` may follow the name, `short`, `long`, or value
/// *without* a ` ` space) i.e. `<name>... -c`, `--config <name>...`, `[name] -c...`, etc.
/// 6. The help info surrounded by `'`s (single quotes)
/// 7. The index of a positional argument will be the next available index (you don't need to
/// specify one) i.e. all arguments without a `short` or `long` will be treated as
/// specify one) i.e. all arguments without a `short` or `long` will be treated as
/// positional
///
/// # Example
@ -205,8 +205,8 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
///
/// // A option argument with a long, named "conf" (note: because the name was specified
/// // the portion after the long can be called anything, only the first name will be displayed
/// // to the user. Also, requirement is set with the *name*, so the portion after the long
/// // could be either <> or [] and it wouldn't matter, so long as it's one of them. Had the
/// // to the user. Also, requirement is set with the *name*, so the portion after the long
/// // could be either <> or [] and it wouldn't matter, so long as it's one of them. Had the
/// // name been omitted, the name would have been derived from the portion after the long and
/// // those rules would have mattered)
/// Arg::from_usage("[conf] --config=[c] 'a required file for the configuration'"),
@ -229,7 +229,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
let mut required = false;
let mut takes_value = false;
let mut multiple = false;
let parser = UsageParser::with_usage(u);
for_match!{ parser,
UsageToken::Name(n, req) => {
@ -242,7 +242,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
if l == name.unwrap() {
if let Some(r) = req {
required = r;
}
}
name = Some(n);
} else if n != l {
name = Some(n);
@ -253,11 +253,11 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
takes_value = true;
}
},
UsageToken::Short(s) => {
short = Some(s);
UsageToken::Short(s) => {
short = Some(s);
},
UsageToken::Long(l) => {
long = Some(l);
UsageToken::Long(l) => {
long = Some(l);
if name.is_none() {
name = Some(l);
}
@ -293,7 +293,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// Sets the short version of the argument without the preceding `-`.
///
///
/// By default `clap` automatically assigns `v` and `h` to display version and help information
/// By default `clap` automatically assigns `v` and `h` to display version and help information
/// respectivly. You may use `v` or `h` for your own purposes, in which case `clap` simply
/// will not asign those to the displaying of version or help.
///
@ -317,8 +317,8 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// Sets the long version of the argument without the preceding `--`.
///
/// By default `clap` automatically assigns `version` and `help` to display version and help
/// information respectivly. You may use `version` or `help` for your own purposes, in which
/// By default `clap` automatically assigns `version` and `help` to display version and help
/// information respectivly. You may use `version` or `help` for your own purposes, in which
/// case `clap` simply will not asign those to the displaying of version or help automatically,
/// and you will have to do so manually.
///
@ -340,7 +340,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
/// Sets the help text of the argument that will be displayed to the user
/// when they print the usage/help information.
/// when they print the usage/help information.
///
///
/// # Example
@ -364,7 +364,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
///
/// **NOTE:** Flags (i.e. not positional, or arguments that take values)
/// cannot be required by default.
/// when they print the usage/help information.
/// when they print the usage/help information.
///
///
/// #Example
@ -381,7 +381,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
self
}
/// Sets a mutually exclusive argument by name. I.e. when using this argument,
/// Sets a mutually exclusive argument by name. I.e. when using this argument,
/// the following argument can't be present.
///
/// **NOTE:** Mutually exclusive rules take precedence over being required
@ -408,7 +408,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
self
}
/// Sets a mutually exclusive arguments by names. I.e. when using this argument,
/// Sets a mutually exclusive arguments by names. I.e. when using this argument,
/// the following argument can't be present.
///
/// **NOTE:** Mutually exclusive rules take precedence over being required
@ -438,7 +438,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
self
}
/// Sets a mutually exclusive argument by name. I.e. when using this argument,
/// Sets a mutually exclusive argument by name. I.e. when using this argument,
/// the following argument can't be present.
///
/// **NOTE:** Mutually exclusive rules take precedence over being required
@ -462,7 +462,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
self
}
/// Sets mutually exclusive arguments by names. I.e. when using this argument,
/// Sets mutually exclusive arguments by names. I.e. when using this argument,
/// the following argument can't be present.
///
/// **NOTE:** Mutually exclusive rules take precedence over being required
@ -479,7 +479,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// .conflicts_with_all(&config_conflicts)
/// # ).get_matches();
pub fn conflicts_with_all<T, I>(mut self, names: I)
-> Arg<'n, 'l, 'h, 'g, 'p, 'r>
-> Arg<'n, 'l, 'h, 'g, 'p, 'r>
where T: AsRef<str> + 'r,
I: IntoIterator<Item=&'r T> {
if let Some(ref mut vec) = self.blacklist {
@ -516,7 +516,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// using this argument, the following arguments *must* be present.
///
/// **NOTE:** Mutually exclusive rules take precedence over being required
/// by default.
/// by default.
///
///
/// # Example
@ -528,7 +528,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// .requires_all(&config_reqs)
/// # ).get_matches();
pub fn requires_all<T, I>(mut self, names: I)
-> Arg<'n, 'l, 'h, 'g, 'p, 'r>
-> Arg<'n, 'l, 'h, 'g, 'p, 'r>
where T: AsRef<str> + 'r,
I: IntoIterator<Item=&'r T> {
if let Some(ref mut vec) = self.requires {
@ -540,9 +540,9 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
/// Specifies that the argument takes an additional value at run time.
///
///
/// **NOTE:** When setting this to `true` the `name` of the argument
/// will be used when printing the help/usage information to the user.
/// will be used when printing the help/usage information to the user.
///
///
/// # Example
@ -560,11 +560,11 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
/// Specifies the index of a positional argument starting at 1.
///
///
/// **NOTE:** When setting this, any `short` or `long` values you set
/// are ignored as positional arguments cannot have a `short` or `long`.
/// Also, the name will be used when printing the help/usage information
/// to the user.
/// Also, the name will be used when printing the help/usage information
/// to the user.
///
///
/// # Example
@ -582,10 +582,10 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
/// Specifies if the flag may appear more than once such as for multiple debugging
/// levels (as an example). `-ddd` for three levels of debugging, or `-d -d -d`.
/// levels (as an example). `-ddd` for three levels of debugging, or `-d -d -d`.
/// When this is set to `true` you recieve the number of occurances the user supplied
/// of a particular flag at runtime.
///
///
/// **NOTE:** When setting this, any `takes_value` or `index` values you set
/// are ignored as flags cannot have a values or an `index`.
///
@ -606,8 +606,8 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// Specifies a list of possible values for this argument. At runtime, clap verifies that only
/// one of the specified values was used, or fails with a usage string.
///
/// **NOTE:** This setting only applies to options and positional arguments
///
/// **NOTE:** This setting only applies to options and positional arguments
///
///
/// # Example
@ -621,7 +621,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// .possible_values(&mode_vals)
/// # ).get_matches();
pub fn possible_values<T, I>(mut self, names: I)
-> Arg<'n, 'l, 'h, 'g, 'p, 'r>
-> Arg<'n, 'l, 'h, 'g, 'p, 'r>
where T: AsRef<str> + 'p,
I: IntoIterator<Item=&'p T> {
if let Some(ref mut vec) = self.possible_vals {
@ -650,12 +650,12 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
/// Specifies how many values are required to satisfy this argument. For example, if you had a
/// `-f <file>` argument where you wanted exactly 3 'files' you would set
/// `-f <file>` argument where you wanted exactly 3 'files' you would set
/// `.number_of_values(3)`, and this argument wouldn't be satisfied unless the user provided
/// 3 and only 3 values.
///
/// **NOTE:** The argument *must* have `.multiple(true)` or `...` to use this setting. Which
/// implies that `qty` must be > 1 (i.e. setting `.number_of_values(1)` would be unnecessary)
/// implies that `qty` must be > 1 (i.e. setting `.number_of_values(1)` would be unnecessary)
///
///
/// # Example
@ -673,12 +673,12 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
/// Specifies the *maximum* number of values are for this argument. For example, if you had a
/// `-f <file>` argument where you wanted up to 3 'files' you would set
/// `-f <file>` argument where you wanted up to 3 'files' you would set
/// `.max_values(3)`, and this argument would be satisfied if the user provided, 1, 2, or 3
/// values.
///
/// **NOTE:** The argument *must* have `.multiple(true)` or `...` to use this setting. Which
/// implies that `qty` must be > 1 (i.e. setting `.max_values(1)` would be unnecessary)
/// implies that `qty` must be > 1 (i.e. setting `.max_values(1)` would be unnecessary)
///
/// # Example
///
@ -695,8 +695,8 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
}
/// Specifies the *minimum* number of values are for this argument. For example, if you had a
/// `-f <file>` argument where you wanted at least 2 'files' you would set
/// `.min_values(2)`, and this argument would be satisfied if the user provided, 2 or more
/// `-f <file>` argument where you wanted at least 2 'files' you would set
/// `.min_values(2)`, and this argument would be satisfied if the user provided, 2 or more
/// values.
///
/// **NOTE:** The argument *must* have `.multiple(true)` or `...` to use this setting.
@ -739,7 +739,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
/// .value_names(&val_names)
/// # ).get_matches();
pub fn value_names<T, I>(mut self, names: I)
-> Arg<'n, 'l, 'h, 'g, 'p, 'r>
-> Arg<'n, 'l, 'h, 'g, 'p, 'r>
where T: AsRef<str> + 'p,
I: IntoIterator<Item=&'p T> {
if let Some(ref mut vec) = self.val_names {

View file

@ -6,8 +6,8 @@ pub struct FlagBuilder<'n> {
/// The long version of the flag (i.e. word)
/// without the preceding `--`
pub long: Option<&'n str>,
/// The string of text that will displayed to
/// the user when the application's `help`
/// The string of text that will displayed to
/// the user when the application's `help`
/// text is displayed
pub help: Option<&'n str>,
/// Determines if multiple instances of the same
@ -17,7 +17,7 @@ pub struct FlagBuilder<'n> {
/// A list of names for other arguments that
/// *may not* be used with this flag
pub blacklist: Option<HashSet<&'n str>>,
/// A list of names of other arguments that
/// A list of names of other arguments that
/// are *required* to be used when this
/// flag is used
pub requires: Option<HashSet<&'n str>>,
@ -28,10 +28,10 @@ pub struct FlagBuilder<'n> {
impl<'n> Display for FlagBuilder<'n> {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "{}", if self.long.is_some() {
write!(f, "{}", if self.long.is_some() {
format!("--{}", self.long.unwrap())
} else {
format!("-{}", self.short.unwrap())
})
}
}
}

View file

@ -4,4 +4,4 @@ pub use self::positional::PosBuilder;
mod flag;
mod positional;
mod option;
mod option;

View file

@ -22,7 +22,7 @@ pub struct OptBuilder<'n> {
pub required: bool,
/// A list of possible values for this argument
pub possible_vals: Option<BTreeSet<&'n str>>,
/// A list of names of other arguments that are *required* to be used when
/// A list of names of other arguments that are *required* to be used when
/// this flag is used
pub requires: Option<HashSet<&'n str>>,
pub num_vals: Option<u8>,
@ -33,24 +33,24 @@ pub struct OptBuilder<'n> {
impl<'n> Display for OptBuilder<'n> {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "{}",
write!(f, "{}",
if let Some(ref vec) = self.val_names {
format!("[ {} {}]",
if self.long.is_some() {
if self.long.is_some() {
format!("--{}", self.long.unwrap())
} else {
format!("-{}", self.short.unwrap())
},
},
vec.iter().fold(String::new(),|acc, i| acc + &format!("<{}> ",i)[..]) )
} else {
} else {
format!("{} <{}>{}",
if self.long.is_some() {
if self.long.is_some() {
format!("--{}", self.long.unwrap())
} else {
format!("-{}", self.short.unwrap())
},
self.name,
},
self.name,
if self.multiple{"..."}else{""})
})
}
}
}

View file

@ -14,7 +14,7 @@ pub struct PosBuilder<'n> {
pub required: bool,
/// Allow multiple occurrences of an option argument such as "-c some -c other"
pub multiple: bool,
/// A list of names of other arguments that are *required* to be used when
/// A list of names of other arguments that are *required* to be used when
/// this flag is used
pub requires: Option<HashSet<&'n str>>,
/// A list of names for other arguments that *may not* be used with this flag
@ -31,9 +31,9 @@ pub struct PosBuilder<'n> {
impl<'n> Display for PosBuilder<'n> {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "{}{}{}{}",
if self.required { "<" } else {"["},
if self.required { "<" } else {"["},
self.name,
if self.required { ">" } else {"]"},
if self.required { ">" } else {"]"},
if self.multiple {"..."}else{""})
}
}
}

View file

@ -21,7 +21,7 @@ use args::MatchedArg;
/// # .short("d")
/// # .multiple(true))
/// .get_matches();
/// // if you had an argument named "output" that takes a value
/// // if you had an argument named "output" that takes a value
/// if let Some(o) = matches.value_of("output") {
/// println!("Value for output: {}", o);
/// }
@ -82,7 +82,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
/// Gets the value of a specific option or positional argument (i.e. an argument that takes
/// an additional value at runtime). If the option wasn't present at runtime
/// it returns `None`.
/// it returns `None`.
///
/// *NOTE:* If getting a value for an option or positional argument that allows multiples,
/// prefer `values_of()` as `value_of()` will only return the _*first*_ value.
@ -134,7 +134,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
None
}
/// Returns if an argument was present at runtime.
/// Returns if an argument was present at runtime.
///
///
/// # Example
@ -148,13 +148,13 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
/// ```
pub fn is_present<'na>(&self, name: &'na str) -> bool {
if let Some(ref sc) = self.subcommand {
if sc.name == name { return true; }
if sc.name == name { return true; }
}
if self.args.contains_key(name) {return true;}
false
}
/// Returns the number of occurrences of an option, flag, or positional argument at runtime.
/// Returns the number of occurrences of an option, flag, or positional argument at runtime.
/// If an argument isn't present it will return `0`. Can be used on arguments which *don't*
/// allow multiple occurrences, but will obviously only return `0` or `1`.
///
@ -262,4 +262,4 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
// Should be un-reachable
""
}
}
}

View file

@ -4,24 +4,24 @@ use std::fmt::{Debug, Formatter, Result};
/// `ArgGroup`s are a family of related arguments and way for you to say, "Any of these arguments".
/// By placing arguments in a logical group, you can make easier requirement and exclusion rules
/// intead of having to list each individually, or when you want a rule to apply "any but not all"
/// arguments.
/// arguments.
///
/// For instance, you can make an entire ArgGroup required, this means that one (and *only* one)
/// argument. from that group must be present. Using more than one argument from an ArgGroup causes
/// a failure (graceful exit).
///
/// You can also do things such as name an ArgGroup as a confliction or requirement, meaning any
///
/// You can also do things such as name an ArgGroup as a confliction or requirement, meaning any
/// of the arguments that belong to that group will cause a failure if present, or must present
/// respectively.
///
/// Perhaps the most common use of `ArgGroup`s is to require one and *only* one argument to be
/// present out of a given set. Imagine that you had multiple arguments, and you want one of them
/// to be required, but making all of them required isn't feasible because perhaps they conflict
/// with each other. For example, lets say that you were building an application where one could
/// set a given version number by supplying a string with an option argument, i.e.
/// `--set-ver v1.2.3`, you also wanted to support automatically using a previous version number
/// and simply incrementing one of the three numbers. So you create three flags `--major`,
/// `--minor`, and `--patch`. All of these arguments shouldn't be used at one time but you want to
/// Perhaps the most common use of `ArgGroup`s is to require one and *only* one argument to be
/// present out of a given set. Imagine that you had multiple arguments, and you want one of them
/// to be required, but making all of them required isn't feasible because perhaps they conflict
/// with each other. For example, lets say that you were building an application where one could
/// set a given version number by supplying a string with an option argument, i.e.
/// `--set-ver v1.2.3`, you also wanted to support automatically using a previous version number
/// and simply incrementing one of the three numbers. So you create three flags `--major`,
/// `--minor`, and `--patch`. All of these arguments shouldn't be used at one time but you want to
/// specify that *at least one* of them is used. For this, you can create a group.
///
/// # Example
@ -51,7 +51,7 @@ pub struct ArgGroup<'n, 'ar> {
}
impl<'n, 'ar> ArgGroup<'n, 'ar> {
/// Creates a new instace of `ArgGroup` using a unique string name.
/// Creates a new instace of `ArgGroup` using a unique string name.
/// The name will only be used by the library consumer and not displayed to the use.
///
/// # Example
@ -178,7 +178,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
self
}
/// Sets the exclusion rules of this group. Exclusion rules function just like argument
/// Sets the exclusion rules of this group. Exclusion rules function just like argument
/// exclusion rules, you can name other arguments or groups that must not be present when one
/// of the arguments from this group are used.
///
@ -240,4 +240,3 @@ impl<'n, 'ar> Debug for ArgGroup<'n, 'ar> {
}}", self.name, self.args, self.required, self.requires, self.conflicts)
}
}

View file

@ -7,5 +7,5 @@ pub struct MatchedArg {
#[doc(hidden)]
pub occurrences: u8,
#[doc(hidden)]
pub values: Option<BTreeMap<u8, String>>
}
pub values: Option<BTreeMap<u8, String>>
}

View file

@ -10,4 +10,4 @@ mod argmatches;
mod subcommand;
mod argbuilder;
mod matchedarg;
mod group;
mod group;

View file

@ -2,9 +2,9 @@ use App;
use ArgMatches;
/// The abstract representation of a command line subcommand used by the consumer of the library.
///
///
/// This struct is used by the library consumer and describes all the valid options of the
///
/// This struct is used by the library consumer and describes all the valid options of the
/// subcommand for their program. SubCommands are treated like "sub apps" and contain all the same
/// possibilities (such as their own arguments and subcommands).
///
@ -42,4 +42,4 @@ impl<'n, 'a> SubCommand<'n, 'a> {
pub fn new<'au, 'v, 'ab, 'u, 'h, 'ar>(name: &'ar str) -> App<'au, 'v, 'ab, 'u, 'h, 'ar> {
App::new(name)
}
}
}

1204
src/lib.rs

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,7 @@ macro_rules! get_help {
}else{"".to_owned()})
} else {
" ".to_owned()
}
}
};
}
@ -44,7 +44,7 @@ macro_rules! parse_group_reqs {
$me.required.remove(name);
$me.blacklist.insert(name);
}
}
}
}
};
}
@ -65,7 +65,7 @@ macro_rules! validate_reqs {
}
}
}
}
}
}
}
};
@ -89,10 +89,10 @@ macro_rules! for_match {
/// Convenience macro getting a typed value `T` where `T` implements `std::str::FromStr`
/// This macro returns a `Result<T,String>` which allows you as the developer to decide
/// what you'd like to do on a failed parse. There are two types of errors, parse failures
/// and those where the argument wasn't present (such as a non-required argument).
/// and those where the argument wasn't present (such as a non-required argument).
///
/// You can use it to get a single value, or a `Vec<T>` with the `values_of()`
///
///
/// **NOTE:** Be cautious, as since this a macro invocation it's not exactly like
/// standard syntax.
///
@ -109,7 +109,7 @@ macro_rules! for_match {
/// .get_matches();
/// let len = value_t!(matches.value_of("length"), u32)
/// .unwrap_or_else(|e|{
/// println!("{}",e);
/// println!("{}",e);
/// std::process::exit(1)
/// });
///
@ -130,7 +130,7 @@ macro_rules! for_match {
/// .get_matches();
/// for v in value_t!(matches.values_of("seq"), u32)
/// .unwrap_or_else(|e|{
/// println!("{}",e);
/// println!("{}",e);
/// std::process::exit(1)
/// }) {
/// println!("{} + 2: {}", v, v + 2);
@ -176,10 +176,10 @@ macro_rules! value_t {
/// Convenience macro getting a typed value `T` where `T` implements `std::str::FromStr`
/// This macro returns a `T` or `Vec<T>` or exits with a usage string upon failure. This
/// removes some of the boiler plate to handle failures from value_t! above.
/// removes some of the boiler plate to handle failures from value_t! above.
///
/// You can use it to get a single value `T`, or a `Vec<T>` with the `values_of()`
///
///
/// **NOTE:** This should only be used on required arguments, as it can be confusing to the user
/// why they are getting error messages when it appears they're entering all required argumetns.
///
@ -230,7 +230,7 @@ macro_rules! value_t_or_exit {
println!("{} isn't a valid {}\n{}\n{}\nPlease re-run with --help for \
more information",
v,
stringify!($t),
stringify!($t),
e,
$m.usage());
::std::process::exit(1);
@ -240,7 +240,7 @@ macro_rules! value_t_or_exit {
None => {
println!("Argument \"{}\" not found or is not valid\n{}\nPlease re-run with \
--help for more information",
$v,
$v,
$m.usage());
::std::process::exit(1);
}
@ -257,8 +257,8 @@ macro_rules! value_t_or_exit {
println!("{} isn't a valid {}\n{}\nPlease re-run with --help for more \
information",
pv,
stringify!($t),
$m.usage());
stringify!($t),
$m.usage());
::std::process::exit(1);
}
}
@ -268,7 +268,7 @@ macro_rules! value_t_or_exit {
None => {
println!("Argument \"{}\" not found or is not valid\n{}\nPlease re-run with \
--help for more information",
$v,
$v,
$m.usage());
::std::process::exit(1);
}
@ -307,7 +307,7 @@ macro_rules! simple_enum {
}
impl ::std::str::FromStr for $e {
type Err = String;
type Err = String;
fn from_str(s: &str) -> Result<Self,Self::Err> {
match s {
@ -316,7 +316,7 @@ macro_rules! simple_enum {
let v = vec![
$(stringify!($v),)+
];
format!("valid:{}",
format!("valid:{}",
v.iter().fold(String::new(), |a, i| {
a + &format!(" {}", i)[..]
}))
@ -375,7 +375,7 @@ macro_rules! arg_enum {
let v = vec![
$(stringify!($v),)+
];
format!("valid:{}",
format!("valid:{}",
v.iter().fold(String::new(), |a, i| {
a + &format!(" {}", i)[..]
}))
@ -399,7 +399,7 @@ macro_rules! arg_enum {
let v = vec![
$(stringify!($v),)+
];
format!("valid:{}",
format!("valid:{}",
v.iter().fold(String::new(), |a, i| {
a + &format!(" {}", i)[..]
}))
@ -424,7 +424,7 @@ macro_rules! arg_enum {
let v = vec![
$(stringify!($v),)+
];
format!("valid:{}",
format!("valid:{}",
v.iter().fold(String::new(), |a, i| {
a + &format!(" {}", i)[..]
}))
@ -449,7 +449,7 @@ macro_rules! arg_enum {
let v = vec![
$(stringify!($v),)+
];
format!("valid:{}",
format!("valid:{}",
v.iter().fold(String::new(), |a, i| {
a + &format!(" {}", i)[..]
}))

View file

@ -25,7 +25,7 @@ impl<'u> UsageParser<'u> {
}
}
}
impl<'u> Iterator for UsageParser<'u> {
@ -48,20 +48,20 @@ impl<'u> Iterator for UsageParser<'u> {
while let Some(c) = self.chars.next() {
self.e += 1;
if c == closing { break }
}
}
if self.e > self.usage.len() { return None }
// self.e += 1;
let name = &self.usage[self.s..self.e];
return Some(UsageToken::Name(name, if c == '<' { Some(true) } else { None }));
},
Some('\'') => {
self.s = self.e + 2;
self.e = self.usage.len() - 1;
while let Some(_) = self.chars.next() { continue }
return Some(UsageToken::Help(&self.usage[self.s..self.e]));
@ -73,13 +73,13 @@ impl<'u> Iterator for UsageParser<'u> {
if self.e != 1 {
self.e += 1;
}
self.s = self.e + 1;
while let Some(c) = self.chars.next() {
self.e += 1;
if c == ' ' || c == '=' || c == '.' { break }
}
}
if self.e > self.usage.len() { return None }
if self.e == self.usage.len() - 1 {
@ -109,15 +109,15 @@ impl<'u> Iterator for UsageParser<'u> {
for _ in 0..2 {
self.e += 1;
match self.chars.next() {
// longs consume one '.' so they match '.. ' whereas shorts can
// longs consume one '.' so they match '.. ' whereas shorts can
// match '...'
Some('.') | Some(' ') => { mult = true; },
_ => {
_ => {
// if there is no help or following space all we can match is '..'
if self.e == self.usage.len() - 1 {
mult = true;
}
break;
break;
}
}
}
@ -126,7 +126,7 @@ impl<'u> Iterator for UsageParser<'u> {
Some(' ') | Some('=') | Some(']') | Some('>') | Some('\t') => {
self.e += 1;
continue
},
},
_ => {
return None
}