mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
style: rustfmt run
This commit is contained in:
parent
f161ffa470
commit
d0c13d2960
18 changed files with 1210 additions and 1171 deletions
2
rustfmt.toml
Normal file
2
rustfmt.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
format_strings = false
|
||||
reorder_imports = true
|
1475
src/app/app.rs
1475
src/app/app.rs
File diff suppressed because it is too large
Load diff
|
@ -250,7 +250,7 @@ pub enum ClapErrorType {
|
|||
/// assert!(result.is_err());
|
||||
/// assert_eq!(result.unwrap_err().error_type, ClapErrorType::VersionDisplayed);
|
||||
/// ```
|
||||
VersionDisplayed
|
||||
VersionDisplayed,
|
||||
}
|
||||
|
||||
/// Command line argument parser error
|
||||
|
@ -277,9 +277,7 @@ impl Error for ClapError {
|
|||
}
|
||||
|
||||
impl fmt::Display for ClapError {
|
||||
fn fmt(&self,
|
||||
f: &mut fmt::Formatter)
|
||||
-> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.error)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,61 +31,61 @@ impl AppFlags {
|
|||
|
||||
pub fn set(&mut self, s: &AppSettings) {
|
||||
match *s {
|
||||
AppSettings::SubcommandsNegateReqs => self.0.insert(SC_NEGATE_REQS),
|
||||
AppSettings::VersionlessSubcommands => self.0.insert(VERSIONLESS_SC),
|
||||
AppSettings::SubcommandRequired => self.0.insert(SC_REQUIRED),
|
||||
AppSettings::ArgRequiredElseHelp => self.0.insert(A_REQUIRED_ELSE_HELP),
|
||||
AppSettings::GlobalVersion => self.0.insert(GLOBAL_VERSION),
|
||||
AppSettings::UnifiedHelpMessage => self.0.insert(UNIFIED_HELP),
|
||||
AppSettings::WaitOnError => self.0.insert(WAIT_ON_ERROR),
|
||||
AppSettings::SubcommandsNegateReqs => self.0.insert(SC_NEGATE_REQS),
|
||||
AppSettings::VersionlessSubcommands => self.0.insert(VERSIONLESS_SC),
|
||||
AppSettings::SubcommandRequired => self.0.insert(SC_REQUIRED),
|
||||
AppSettings::ArgRequiredElseHelp => self.0.insert(A_REQUIRED_ELSE_HELP),
|
||||
AppSettings::GlobalVersion => self.0.insert(GLOBAL_VERSION),
|
||||
AppSettings::UnifiedHelpMessage => self.0.insert(UNIFIED_HELP),
|
||||
AppSettings::WaitOnError => self.0.insert(WAIT_ON_ERROR),
|
||||
AppSettings::SubcommandRequiredElseHelp => self.0.insert(SC_REQUIRED_ELSE_HELP),
|
||||
AppSettings::NeedsLongHelp => self.0.insert(NEEDS_LONG_HELP),
|
||||
AppSettings::NeedsLongVersion => self.0.insert(NEEDS_LONG_VERSION),
|
||||
AppSettings::NeedsSubcommandHelp => self.0.insert(NEEDS_SC_HELP),
|
||||
AppSettings::DisableVersion => self.0.insert(DISABLE_VERSION),
|
||||
AppSettings::Hidden => self.0.insert(HIDDEN),
|
||||
AppSettings::TrailingVarArg => self.0.insert(TRAILING_VARARG),
|
||||
AppSettings::NoBinaryName => self.0.insert(NO_BIN_NAME),
|
||||
AppSettings::NeedsLongHelp => self.0.insert(NEEDS_LONG_HELP),
|
||||
AppSettings::NeedsLongVersion => self.0.insert(NEEDS_LONG_VERSION),
|
||||
AppSettings::NeedsSubcommandHelp => self.0.insert(NEEDS_SC_HELP),
|
||||
AppSettings::DisableVersion => self.0.insert(DISABLE_VERSION),
|
||||
AppSettings::Hidden => self.0.insert(HIDDEN),
|
||||
AppSettings::TrailingVarArg => self.0.insert(TRAILING_VARARG),
|
||||
AppSettings::NoBinaryName => self.0.insert(NO_BIN_NAME),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unset(&mut self, s: &AppSettings) {
|
||||
match *s {
|
||||
AppSettings::SubcommandsNegateReqs => self.0.remove(SC_NEGATE_REQS),
|
||||
AppSettings::VersionlessSubcommands => self.0.remove(VERSIONLESS_SC),
|
||||
AppSettings::SubcommandRequired => self.0.remove(SC_REQUIRED),
|
||||
AppSettings::ArgRequiredElseHelp => self.0.remove(A_REQUIRED_ELSE_HELP),
|
||||
AppSettings::GlobalVersion => self.0.remove(GLOBAL_VERSION),
|
||||
AppSettings::UnifiedHelpMessage => self.0.remove(UNIFIED_HELP),
|
||||
AppSettings::WaitOnError => self.0.remove(WAIT_ON_ERROR),
|
||||
AppSettings::SubcommandsNegateReqs => self.0.remove(SC_NEGATE_REQS),
|
||||
AppSettings::VersionlessSubcommands => self.0.remove(VERSIONLESS_SC),
|
||||
AppSettings::SubcommandRequired => self.0.remove(SC_REQUIRED),
|
||||
AppSettings::ArgRequiredElseHelp => self.0.remove(A_REQUIRED_ELSE_HELP),
|
||||
AppSettings::GlobalVersion => self.0.remove(GLOBAL_VERSION),
|
||||
AppSettings::UnifiedHelpMessage => self.0.remove(UNIFIED_HELP),
|
||||
AppSettings::WaitOnError => self.0.remove(WAIT_ON_ERROR),
|
||||
AppSettings::SubcommandRequiredElseHelp => self.0.remove(SC_REQUIRED_ELSE_HELP),
|
||||
AppSettings::NeedsLongHelp => self.0.remove(NEEDS_LONG_HELP),
|
||||
AppSettings::NeedsLongVersion => self.0.remove(NEEDS_LONG_VERSION),
|
||||
AppSettings::NeedsSubcommandHelp => self.0.remove(NEEDS_SC_HELP),
|
||||
AppSettings::DisableVersion => self.0.remove(DISABLE_VERSION),
|
||||
AppSettings::Hidden => self.0.remove(HIDDEN),
|
||||
AppSettings::TrailingVarArg => self.0.remove(TRAILING_VARARG),
|
||||
AppSettings::NoBinaryName => self.0.remove(NO_BIN_NAME),
|
||||
AppSettings::NeedsLongHelp => self.0.remove(NEEDS_LONG_HELP),
|
||||
AppSettings::NeedsLongVersion => self.0.remove(NEEDS_LONG_VERSION),
|
||||
AppSettings::NeedsSubcommandHelp => self.0.remove(NEEDS_SC_HELP),
|
||||
AppSettings::DisableVersion => self.0.remove(DISABLE_VERSION),
|
||||
AppSettings::Hidden => self.0.remove(HIDDEN),
|
||||
AppSettings::TrailingVarArg => self.0.remove(TRAILING_VARARG),
|
||||
AppSettings::NoBinaryName => self.0.remove(NO_BIN_NAME),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_set(&self, s: &AppSettings) -> bool {
|
||||
match *s {
|
||||
AppSettings::SubcommandsNegateReqs => self.0.contains(SC_NEGATE_REQS),
|
||||
AppSettings::VersionlessSubcommands => self.0.contains(VERSIONLESS_SC),
|
||||
AppSettings::SubcommandRequired => self.0.contains(SC_REQUIRED),
|
||||
AppSettings::ArgRequiredElseHelp => self.0.contains(A_REQUIRED_ELSE_HELP),
|
||||
AppSettings::GlobalVersion => self.0.contains(GLOBAL_VERSION),
|
||||
AppSettings::UnifiedHelpMessage => self.0.contains(UNIFIED_HELP),
|
||||
AppSettings::WaitOnError => self.0.contains(WAIT_ON_ERROR),
|
||||
AppSettings::SubcommandsNegateReqs => self.0.contains(SC_NEGATE_REQS),
|
||||
AppSettings::VersionlessSubcommands => self.0.contains(VERSIONLESS_SC),
|
||||
AppSettings::SubcommandRequired => self.0.contains(SC_REQUIRED),
|
||||
AppSettings::ArgRequiredElseHelp => self.0.contains(A_REQUIRED_ELSE_HELP),
|
||||
AppSettings::GlobalVersion => self.0.contains(GLOBAL_VERSION),
|
||||
AppSettings::UnifiedHelpMessage => self.0.contains(UNIFIED_HELP),
|
||||
AppSettings::WaitOnError => self.0.contains(WAIT_ON_ERROR),
|
||||
AppSettings::SubcommandRequiredElseHelp => self.0.contains(SC_REQUIRED_ELSE_HELP),
|
||||
AppSettings::NeedsLongHelp => self.0.contains(NEEDS_LONG_HELP),
|
||||
AppSettings::NeedsLongVersion => self.0.contains(NEEDS_LONG_VERSION),
|
||||
AppSettings::NeedsSubcommandHelp => self.0.contains(NEEDS_SC_HELP),
|
||||
AppSettings::DisableVersion => self.0.contains(DISABLE_VERSION),
|
||||
AppSettings::Hidden => self.0.contains(HIDDEN),
|
||||
AppSettings::TrailingVarArg => self.0.contains(TRAILING_VARARG),
|
||||
AppSettings::NoBinaryName => self.0.contains(NO_BIN_NAME),
|
||||
AppSettings::NeedsLongHelp => self.0.contains(NEEDS_LONG_HELP),
|
||||
AppSettings::NeedsLongVersion => self.0.contains(NEEDS_LONG_VERSION),
|
||||
AppSettings::NeedsSubcommandHelp => self.0.contains(NEEDS_SC_HELP),
|
||||
AppSettings::DisableVersion => self.0.contains(DISABLE_VERSION),
|
||||
AppSettings::Hidden => self.0.contains(HIDDEN),
|
||||
AppSettings::TrailingVarArg => self.0.contains(TRAILING_VARARG),
|
||||
AppSettings::NoBinaryName => self.0.contains(NO_BIN_NAME),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ pub enum AppSettings {
|
|||
/// # use clap::{App, Arg, AppSettings, SubCommand};
|
||||
/// App::new("myprog")
|
||||
/// .subcommand(SubCommand::with_name("test")
|
||||
/// .setting(AppSettings::Hidden))
|
||||
/// .setting(AppSettings::Hidden))
|
||||
/// # ;
|
||||
/// ```
|
||||
Hidden,
|
||||
|
@ -294,16 +294,16 @@ impl FromStr for AppSettings {
|
|||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||
match &*s.to_ascii_lowercase() {
|
||||
"subcommandsnegatereqs" => Ok(AppSettings::SubcommandsNegateReqs),
|
||||
"subcommandsrequired" => Ok(AppSettings::SubcommandRequired),
|
||||
"argrequiredelsehelp" => Ok(AppSettings::ArgRequiredElseHelp),
|
||||
"globalversion" => Ok(AppSettings::GlobalVersion),
|
||||
"subcommandsnegatereqs" => Ok(AppSettings::SubcommandsNegateReqs),
|
||||
"subcommandsrequired" => Ok(AppSettings::SubcommandRequired),
|
||||
"argrequiredelsehelp" => Ok(AppSettings::ArgRequiredElseHelp),
|
||||
"globalversion" => Ok(AppSettings::GlobalVersion),
|
||||
"versionlesssubcommands" => Ok(AppSettings::VersionlessSubcommands),
|
||||
"unifiedhelpmessage" => Ok(AppSettings::UnifiedHelpMessage),
|
||||
"waitonerror" => Ok(AppSettings::WaitOnError),
|
||||
"unifiedhelpmessage" => Ok(AppSettings::UnifiedHelpMessage),
|
||||
"waitonerror" => Ok(AppSettings::WaitOnError),
|
||||
"subcommandrequiredelsehelp" => Ok(AppSettings::SubcommandRequiredElseHelp),
|
||||
"hidden" => Ok(AppSettings::Hidden),
|
||||
_ => Err("unknown AppSetting, cannot convert from str".to_owned())
|
||||
"hidden" => Ok(AppSettings::Hidden),
|
||||
_ => Err("unknown AppSetting, cannot convert from str".to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,7 @@ use strsim;
|
|||
/// `Some("foo")`, whereas "blark" would yield `None`.
|
||||
#[cfg(feature = "suggestions")]
|
||||
#[cfg_attr(feature = "lints", allow(needless_lifetimes))]
|
||||
pub fn did_you_mean<'a, T, I>(v: &str,
|
||||
possible_values: I)
|
||||
-> Option<&'a str>
|
||||
pub fn did_you_mean<'a, T, I>(v: &str, possible_values: I) -> Option<&'a str>
|
||||
where T: AsRef<str> + 'a,
|
||||
I: IntoIterator<Item = &'a T>
|
||||
{
|
||||
|
@ -29,9 +27,7 @@ pub fn did_you_mean<'a, T, I>(v: &str,
|
|||
}
|
||||
|
||||
#[cfg(not(feature = "suggestions"))]
|
||||
pub fn did_you_mean<'a, T, I>(_: &str,
|
||||
_: I)
|
||||
-> Option<&'a str>
|
||||
pub fn did_you_mean<'a, T, I>(_: &str, _: I) -> Option<&'a str>
|
||||
where T: AsRef<str> + 'a,
|
||||
I: IntoIterator<Item = &'a T>
|
||||
{
|
||||
|
|
159
src/args/arg.rs
159
src/args/arg.rs
|
@ -95,7 +95,7 @@ pub struct Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// A list of names for other arguments that *mutually override* this flag
|
||||
pub overrides: Option<Vec<&'r str>>,
|
||||
/// Specifies whether the argument should show up in the help message
|
||||
pub hidden: bool
|
||||
pub hidden: bool,
|
||||
}
|
||||
|
||||
impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
||||
|
@ -162,44 +162,44 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
|
||||
for (k, v) in arg_settings.iter() {
|
||||
a = match k.as_str().unwrap() {
|
||||
"short" => a.short(v.as_str().unwrap()),
|
||||
"long" => a.long(v.as_str().unwrap()),
|
||||
"help" => a.help(v.as_str().unwrap()),
|
||||
"required" => a.required(v.as_bool().unwrap()),
|
||||
"takes_value" => a.takes_value(v.as_bool().unwrap()),
|
||||
"index" => a.index(v.as_i64().unwrap() as u8),
|
||||
"global" => a.global(v.as_bool().unwrap()),
|
||||
"multiple" => a.multiple(v.as_bool().unwrap()),
|
||||
"empty_values" => a.empty_values(v.as_bool().unwrap()),
|
||||
"group" => a.group(v.as_str().unwrap()),
|
||||
"number_of_values" => a.number_of_values(v.as_i64().unwrap() as u8),
|
||||
"max_values" => a.max_values(v.as_i64().unwrap() as u8),
|
||||
"min_values" => a.min_values(v.as_i64().unwrap() as u8),
|
||||
"value_name" => a.value_name(v.as_str().unwrap()),
|
||||
"value_names" => {
|
||||
"short" => a.short(v.as_str().unwrap()),
|
||||
"long" => a.long(v.as_str().unwrap()),
|
||||
"help" => a.help(v.as_str().unwrap()),
|
||||
"required" => a.required(v.as_bool().unwrap()),
|
||||
"takes_value" => a.takes_value(v.as_bool().unwrap()),
|
||||
"index" => a.index(v.as_i64().unwrap() as u8),
|
||||
"global" => a.global(v.as_bool().unwrap()),
|
||||
"multiple" => a.multiple(v.as_bool().unwrap()),
|
||||
"empty_values" => a.empty_values(v.as_bool().unwrap()),
|
||||
"group" => a.group(v.as_str().unwrap()),
|
||||
"number_of_values" => a.number_of_values(v.as_i64().unwrap() as u8),
|
||||
"max_values" => a.max_values(v.as_i64().unwrap() as u8),
|
||||
"min_values" => a.min_values(v.as_i64().unwrap() as u8),
|
||||
"value_name" => a.value_name(v.as_str().unwrap()),
|
||||
"value_names" => {
|
||||
for ys in v.as_vec().unwrap() {
|
||||
if let Some(s) = ys.as_str() {
|
||||
a = a.value_name(s);
|
||||
}
|
||||
}
|
||||
a
|
||||
},
|
||||
"requires" => {
|
||||
}
|
||||
"requires" => {
|
||||
for ys in v.as_vec().unwrap() {
|
||||
if let Some(s) = ys.as_str() {
|
||||
a = a.requires(s);
|
||||
}
|
||||
}
|
||||
a
|
||||
},
|
||||
"conflicts_with" => {
|
||||
}
|
||||
"conflicts_with" => {
|
||||
for ys in v.as_vec().unwrap() {
|
||||
if let Some(s) = ys.as_str() {
|
||||
a = a.conflicts_with(s);
|
||||
}
|
||||
}
|
||||
a
|
||||
},
|
||||
}
|
||||
"mutually_overrides_with" => {
|
||||
for ys in v.as_vec().unwrap() {
|
||||
if let Some(s) = ys.as_str() {
|
||||
|
@ -207,16 +207,18 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
}
|
||||
}
|
||||
a
|
||||
},
|
||||
"possible_values" => {
|
||||
}
|
||||
"possible_values" => {
|
||||
for ys in v.as_vec().unwrap() {
|
||||
if let Some(s) = ys.as_str() {
|
||||
a = a.possible_value(s);
|
||||
}
|
||||
}
|
||||
a
|
||||
},
|
||||
s => panic!("Unknown Arg setting '{}' in YAML file for arg '{}'", s, name_str)
|
||||
}
|
||||
s => panic!("Unknown Arg setting '{}' in YAML file for arg '{}'",
|
||||
s,
|
||||
name_str),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,7 +278,8 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// ])
|
||||
/// # .get_matches();
|
||||
pub fn from_usage(u: &'n str) -> Arg<'n, 'n, 'n, 'g, 'p, 'r> {
|
||||
assert!(u.len() > 0, "Arg::from_usage() requires a non-zero-length usage string but none \
|
||||
assert!(u.len() > 0,
|
||||
"Arg::from_usage() requires a non-zero-length usage string but none \
|
||||
was provided");
|
||||
|
||||
let mut name = None;
|
||||
|
@ -311,7 +314,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// starting with short
|
||||
// starting with short
|
||||
if !name_first {
|
||||
use_name = true;
|
||||
use_req = true;
|
||||
|
@ -412,9 +415,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("conifg")
|
||||
/// .short("c")
|
||||
/// # ).get_matches();
|
||||
pub fn short(mut self,
|
||||
s: &str)
|
||||
-> Self {
|
||||
pub fn short(mut self, s: &str) -> Self {
|
||||
self.short = s.trim_left_matches(|c| c == '-').chars().nth(0);
|
||||
self
|
||||
}
|
||||
|
@ -438,9 +439,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("conifg")
|
||||
/// .long("config")
|
||||
/// # ).get_matches();
|
||||
pub fn long(mut self,
|
||||
l: &'l str)
|
||||
-> Self {
|
||||
pub fn long(mut self, l: &'l str) -> Self {
|
||||
self.long = Some(l.trim_left_matches(|c| c == '-'));
|
||||
self
|
||||
}
|
||||
|
@ -458,9 +457,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("conifg")
|
||||
/// .help("The config file used by the myprog")
|
||||
/// # ).get_matches();
|
||||
pub fn help(mut self,
|
||||
h: &'h str)
|
||||
-> Self {
|
||||
pub fn help(mut self, h: &'h str) -> Self {
|
||||
self.help = Some(h);
|
||||
self
|
||||
}
|
||||
|
@ -484,9 +481,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("conifg")
|
||||
/// .required(true)
|
||||
/// # ).get_matches();
|
||||
pub fn required(mut self,
|
||||
r: bool)
|
||||
-> Self {
|
||||
pub fn required(mut self, r: bool) -> Self {
|
||||
self.required = r;
|
||||
self
|
||||
}
|
||||
|
@ -506,9 +501,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # let myprog = App::new("myprog").arg(Arg::with_name("conifg")
|
||||
/// .conflicts_with("debug")
|
||||
/// # ).get_matches();
|
||||
pub fn conflicts_with(mut self,
|
||||
name: &'r str)
|
||||
-> Self {
|
||||
pub fn conflicts_with(mut self, name: &'r str) -> Self {
|
||||
if let Some(ref mut vec) = self.blacklist {
|
||||
vec.push(name);
|
||||
} else {
|
||||
|
@ -533,9 +526,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # let myprog = App::new("myprog").arg(Arg::with_name("conifg")
|
||||
/// .conflicts_with_all(&config_conflicts)
|
||||
/// # ).get_matches();
|
||||
pub fn conflicts_with_all<T, I>(mut self,
|
||||
names: I)
|
||||
-> Self
|
||||
pub fn conflicts_with_all<T, I>(mut self, names: I) -> Self
|
||||
where T: AsRef<str> + 'r,
|
||||
I: IntoIterator<Item = &'r T>
|
||||
{
|
||||
|
@ -559,9 +550,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # let myprog = App::new("myprog").arg(Arg::with_name("conifg")
|
||||
/// .mutually_overrides_with("debug")
|
||||
/// # ).get_matches();
|
||||
pub fn mutually_overrides_with(mut self,
|
||||
name: &'r str)
|
||||
-> Self {
|
||||
pub fn mutually_overrides_with(mut self, name: &'r str) -> Self {
|
||||
if let Some(ref mut vec) = self.overrides {
|
||||
vec.push(name);
|
||||
} else {
|
||||
|
@ -581,9 +570,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # let myprog = App::new("myprog").arg(Arg::with_name("conifg")
|
||||
/// .mutually_overrides_with_all(&config_overrides)
|
||||
/// # ).get_matches();
|
||||
pub fn mutually_overrides_with_all<T, I>(mut self,
|
||||
names: I)
|
||||
-> Self
|
||||
pub fn mutually_overrides_with_all<T, I>(mut self, names: I) -> Self
|
||||
where T: AsRef<str> + 'r,
|
||||
I: IntoIterator<Item = &'r T>
|
||||
{
|
||||
|
@ -610,9 +597,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # let myprog = App::new("myprog").arg(Arg::with_name("conifg")
|
||||
/// .requires("debug")
|
||||
/// # ).get_matches();
|
||||
pub fn requires(mut self,
|
||||
name: &'r str)
|
||||
-> Self {
|
||||
pub fn requires(mut self, name: &'r str) -> Self {
|
||||
if let Some(ref mut vec) = self.requires {
|
||||
vec.push(name);
|
||||
} else {
|
||||
|
@ -636,9 +621,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # let myprog = App::new("myprog").arg(Arg::with_name("conifg")
|
||||
/// .requires_all(&config_reqs)
|
||||
/// # ).get_matches();
|
||||
pub fn requires_all<T, I>(mut self,
|
||||
names: I)
|
||||
-> Self
|
||||
pub fn requires_all<T, I>(mut self, names: I) -> Self
|
||||
where T: AsRef<str> + 'r,
|
||||
I: IntoIterator<Item = &'r T>
|
||||
{
|
||||
|
@ -667,9 +650,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("conifg")
|
||||
/// .takes_value(true)
|
||||
/// # ).get_matches();
|
||||
pub fn takes_value(mut self,
|
||||
tv: bool)
|
||||
-> Self {
|
||||
pub fn takes_value(mut self, tv: bool) -> Self {
|
||||
self.takes_value = tv;
|
||||
self
|
||||
}
|
||||
|
@ -691,9 +672,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("conifg")
|
||||
/// .index(1)
|
||||
/// # ).get_matches();
|
||||
pub fn index(mut self,
|
||||
idx: u8)
|
||||
-> Self {
|
||||
pub fn index(mut self, idx: u8) -> Self {
|
||||
self.index = Some(idx);
|
||||
self
|
||||
}
|
||||
|
@ -716,9 +695,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("debug")
|
||||
/// .multiple(true)
|
||||
/// # ).get_matches();
|
||||
pub fn multiple(mut self,
|
||||
multi: bool)
|
||||
-> Self {
|
||||
pub fn multiple(mut self, multi: bool) -> Self {
|
||||
self.multiple = multi;
|
||||
self
|
||||
}
|
||||
|
@ -743,9 +720,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("debug")
|
||||
/// .global(true)
|
||||
/// # ).get_matches();
|
||||
pub fn global(mut self,
|
||||
g: bool)
|
||||
-> Self {
|
||||
pub fn global(mut self, g: bool) -> Self {
|
||||
self.global = g;
|
||||
self
|
||||
}
|
||||
|
@ -765,9 +740,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("debug")
|
||||
/// .empty_values(true)
|
||||
/// # ).get_matches();
|
||||
pub fn empty_values(mut self,
|
||||
ev: bool)
|
||||
-> Self {
|
||||
pub fn empty_values(mut self, ev: bool) -> Self {
|
||||
self.empty_vals = ev;
|
||||
self
|
||||
}
|
||||
|
@ -785,9 +758,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("debug")
|
||||
/// .hidden(true)
|
||||
/// # ).get_matches();
|
||||
pub fn hidden(mut self,
|
||||
h: bool)
|
||||
-> Self {
|
||||
pub fn hidden(mut self, h: bool) -> Self {
|
||||
self.hidden = h;
|
||||
self
|
||||
}
|
||||
|
@ -808,9 +779,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("debug").index(1)
|
||||
/// .possible_values(&mode_vals)
|
||||
/// # ).get_matches();
|
||||
pub fn possible_values<T, I>(mut self,
|
||||
names: I)
|
||||
-> Self
|
||||
pub fn possible_values<T, I>(mut self, names: I) -> Self
|
||||
where T: AsRef<str> + 'p,
|
||||
I: IntoIterator<Item = &'p T>
|
||||
{
|
||||
|
@ -840,9 +809,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// .possible_value("fast")
|
||||
/// .possible_value("slow")
|
||||
/// # ).get_matches();
|
||||
pub fn possible_value(mut self,
|
||||
name: &'p str)
|
||||
-> Self {
|
||||
pub fn possible_value(mut self, name: &'p str) -> Self {
|
||||
if let Some(ref mut vec) = self.possible_vals {
|
||||
vec.push(name);
|
||||
} else {
|
||||
|
@ -863,9 +830,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("debug").index(1)
|
||||
/// .group("mode")
|
||||
/// # ).get_matches();
|
||||
pub fn group(mut self,
|
||||
name: &'g str)
|
||||
-> Self {
|
||||
pub fn group(mut self, name: &'g str) -> Self {
|
||||
self.group = Some(name);
|
||||
self
|
||||
}
|
||||
|
@ -888,9 +853,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("debug").index(1)
|
||||
/// .number_of_values(3)
|
||||
/// # ).get_matches();
|
||||
pub fn number_of_values(mut self,
|
||||
qty: u8)
|
||||
-> Self {
|
||||
pub fn number_of_values(mut self, qty: u8) -> Self {
|
||||
self.num_vals = Some(qty);
|
||||
self
|
||||
}
|
||||
|
@ -921,9 +884,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// }
|
||||
/// })
|
||||
/// # ).get_matches();
|
||||
pub fn validator<F>(mut self,
|
||||
f: F)
|
||||
-> Self
|
||||
pub fn validator<F>(mut self, f: F) -> Self
|
||||
where F: Fn(String) -> Result<(), String> + 'static
|
||||
{
|
||||
self.validator = Some(Rc::new(f));
|
||||
|
@ -948,9 +909,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("debug").index(1)
|
||||
/// .max_values(3)
|
||||
/// # ).get_matches();
|
||||
pub fn max_values(mut self,
|
||||
qty: u8)
|
||||
-> Self {
|
||||
pub fn max_values(mut self, qty: u8) -> Self {
|
||||
if qty < 2 {
|
||||
panic!("Arguments with max_values(qty) qty must be > 1. Prefer \
|
||||
takes_value(true) for arguments with only one value, or flags for arguments \
|
||||
|
@ -982,9 +941,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// # Arg::with_name("debug").index(1)
|
||||
/// .min_values(2)
|
||||
/// # ).get_matches();
|
||||
pub fn min_values(mut self,
|
||||
qty: u8)
|
||||
-> Self {
|
||||
pub fn min_values(mut self, qty: u8) -> Self {
|
||||
if qty < 1 {
|
||||
panic!("Arguments with min_values(qty) qty must be > 0. Prefer flags for arguments \
|
||||
with 0 values.");
|
||||
|
@ -1018,9 +975,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)
|
||||
-> Self
|
||||
pub fn value_names<T, I>(mut self, names: I) -> Self
|
||||
where T: AsRef<str> + 'n,
|
||||
I: IntoIterator<Item = &'n T>
|
||||
{
|
||||
|
@ -1047,9 +1002,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
/// .index(1)
|
||||
/// .value_name("file")
|
||||
/// # ).get_matches();
|
||||
pub fn value_name(mut self,
|
||||
name: &'n str)
|
||||
-> Self {
|
||||
pub fn value_name(mut self, name: &'n str) -> Self {
|
||||
if let Some(ref mut vec) = self.val_names {
|
||||
vec.insert(name);
|
||||
} else {
|
||||
|
@ -1085,7 +1038,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r, 'z> From<&'z Arg<'n, 'l, 'h, 'g, 'p, 'r>>
|
|||
empty_vals: a.empty_vals,
|
||||
validator: a.validator.clone(),
|
||||
overrides: a.overrides.clone(),
|
||||
hidden: a.hidden
|
||||
hidden: a.hidden,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,14 +41,11 @@ impl<'n> FlagBuilder<'n> {
|
|||
blacklist: None,
|
||||
requires: None,
|
||||
overrides: None,
|
||||
settings: ArgFlags::new()
|
||||
settings: ArgFlags::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_help<W: io::Write>(&self,
|
||||
w: &mut W,
|
||||
tab: &str,
|
||||
longest: usize) -> io::Result<()> {
|
||||
pub fn write_help<W: io::Write>(&self, w: &mut W, tab: &str, longest: usize) -> io::Result<()> {
|
||||
try!(write!(w, "{}", tab));
|
||||
if let Some(s) = self.short {
|
||||
try!(write!(w, "-{}", s));
|
||||
|
@ -56,10 +53,14 @@ impl<'n> FlagBuilder<'n> {
|
|||
try!(write!(w, "{}", tab));
|
||||
}
|
||||
if let Some(l) = self.long {
|
||||
try!(write!(w, "{}--{}",
|
||||
if self.short.is_some() { ", " } else { "" },
|
||||
l
|
||||
));
|
||||
try!(write!(w,
|
||||
"{}--{}",
|
||||
if self.short.is_some() {
|
||||
", "
|
||||
} else {
|
||||
""
|
||||
},
|
||||
l));
|
||||
write_spaces!((longest + 4) - (l.len() + 2), w);
|
||||
} else {
|
||||
// 6 is tab (4) + -- (2)
|
||||
|
@ -90,15 +91,18 @@ impl<'n, 'a> From<&'a Arg<'n, 'n, 'n, 'n, 'n, 'n>> for FlagBuilder<'n> {
|
|||
if !a.empty_vals {
|
||||
// Empty vals defaults to true, so if it's false it was manually set
|
||||
panic!("The argument '{}' cannot have empty_values() set because it is a flag. \
|
||||
Perhaps you mean't to set takes_value(true) as well?", a.name);
|
||||
Perhaps you mean't to set takes_value(true) as well?",
|
||||
a.name);
|
||||
}
|
||||
if a.required {
|
||||
panic!("The argument '{}' cannot be required(true) because it has no index() or \
|
||||
takes_value(true)", a.name);
|
||||
takes_value(true)",
|
||||
a.name);
|
||||
}
|
||||
if a.possible_vals.is_some() {
|
||||
panic!("The argument '{}' cannot have a specific value set because it doesn't \
|
||||
have takes_value(true) set", a.name);
|
||||
have takes_value(true) set",
|
||||
a.name);
|
||||
}
|
||||
// No need to check for index() or takes_value() as that is handled above
|
||||
|
||||
|
@ -110,7 +114,7 @@ impl<'n, 'a> From<&'a Arg<'n, 'n, 'n, 'n, 'n, 'n>> for FlagBuilder<'n> {
|
|||
blacklist: None,
|
||||
requires: None,
|
||||
overrides: None,
|
||||
settings: ArgFlags::new()
|
||||
settings: ArgFlags::new(),
|
||||
};
|
||||
if a.multiple {
|
||||
fb.settings.set(&ArgSettings::Multiple);
|
||||
|
@ -121,7 +125,8 @@ impl<'n, 'a> From<&'a Arg<'n, 'n, 'n, 'n, 'n, 'n>> for FlagBuilder<'n> {
|
|||
if a.hidden {
|
||||
fb.settings.set(&ArgSettings::Hidden);
|
||||
}
|
||||
// Check if there is anything in the blacklist (mutually excludes list) and add any
|
||||
// Check if there is anything in the blacklist (mutually excludes list) and add
|
||||
// any
|
||||
// values
|
||||
if let Some(ref bl) = a.blacklist {
|
||||
let mut bhs = vec![];
|
||||
|
@ -154,9 +159,7 @@ impl<'n, 'a> From<&'a Arg<'n, 'n, 'n, 'n, 'n, 'n>> for FlagBuilder<'n> {
|
|||
}
|
||||
|
||||
impl<'n> Display for FlagBuilder<'n> {
|
||||
fn fmt(&self,
|
||||
f: &mut Formatter)
|
||||
-> Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
if let Some(l) = self.long {
|
||||
write!(f, "--{}", l)
|
||||
} else {
|
||||
|
|
|
@ -50,15 +50,15 @@ impl<'n> OptBuilder<'n> {
|
|||
val_names: None,
|
||||
validator: None,
|
||||
overrides: None,
|
||||
settings: ArgFlags::new()
|
||||
settings: ArgFlags::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_arg(a: &Arg<'n, 'n, 'n, 'n, 'n,'n>,
|
||||
reqs: &mut Vec<&'n str>) -> Self {
|
||||
pub fn from_arg(a: &Arg<'n, 'n, 'n, 'n, 'n, 'n>, reqs: &mut Vec<&'n str>) -> Self {
|
||||
if a.short.is_none() && a.long.is_none() {
|
||||
panic!("Argument \"{}\" has takes_value(true), yet neither a short() or long() \
|
||||
was supplied", a.name);
|
||||
was supplied",
|
||||
a.name);
|
||||
}
|
||||
// No need to check for .index() as that is handled above
|
||||
let mut ob = OptBuilder {
|
||||
|
@ -75,7 +75,7 @@ impl<'n> OptBuilder<'n> {
|
|||
requires: None,
|
||||
validator: None,
|
||||
overrides: None,
|
||||
settings: ArgFlags::new()
|
||||
settings: ArgFlags::new(),
|
||||
};
|
||||
if a.multiple {
|
||||
ob.settings.set(&ArgSettings::Multiple);
|
||||
|
@ -95,7 +95,8 @@ impl<'n> OptBuilder<'n> {
|
|||
if let Some(ref vec) = ob.val_names {
|
||||
ob.num_vals = Some(vec.len() as u8);
|
||||
}
|
||||
// Check if there is anything in the blacklist (mutually excludes list) and add any
|
||||
// Check if there is anything in the blacklist (mutually excludes list) and add
|
||||
// any
|
||||
// values
|
||||
if let Some(ref bl) = a.blacklist {
|
||||
let mut bhs = vec![];
|
||||
|
@ -145,12 +146,19 @@ impl<'n> OptBuilder<'n> {
|
|||
// if it supports multiple we add '...' i.e. 3 to the name length
|
||||
try!(write!(w, "{}", tab));
|
||||
if let Some(s) = self.short {
|
||||
try!(write!(w, "-{}",s));
|
||||
try!(write!(w, "-{}", s));
|
||||
} else {
|
||||
try!(write!(w, "{}", tab));
|
||||
}
|
||||
if let Some(l) = self.long {
|
||||
try!(write!(w, "{}--{}", if self.short.is_some() {", "} else {""}, l));
|
||||
try!(write!(w,
|
||||
"{}--{}",
|
||||
if self.short.is_some() {
|
||||
", "
|
||||
} else {
|
||||
""
|
||||
},
|
||||
l));
|
||||
}
|
||||
if let Some(ref vec) = self.val_names {
|
||||
for val in vec {
|
||||
|
@ -161,31 +169,28 @@ impl<'n> OptBuilder<'n> {
|
|||
try!(write!(w, " <{}>", self.name));
|
||||
}
|
||||
} else {
|
||||
try!(write!(w, " <{}>{}", self.name,
|
||||
if self.settings.is_set(&ArgSettings::Multiple) {
|
||||
"..."
|
||||
} else {
|
||||
""
|
||||
}
|
||||
));
|
||||
try!(write!(w,
|
||||
" <{}>{}",
|
||||
self.name,
|
||||
if self.settings.is_set(&ArgSettings::Multiple) {
|
||||
"..."
|
||||
} else {
|
||||
""
|
||||
}));
|
||||
}
|
||||
if self.long.is_some() {
|
||||
write_spaces!(
|
||||
(longest + 4) - (self.to_string().len()), w
|
||||
);
|
||||
write_spaces!((longest + 4) - (self.to_string().len()), w);
|
||||
} else {
|
||||
// 8 = tab + '-a, '.len()
|
||||
write_spaces!((longest + 8) - (self.to_string().len()), w);
|
||||
};
|
||||
}
|
||||
print_opt_help!(self, longest + 12, w);
|
||||
write!(w, "\n")
|
||||
}
|
||||
}
|
||||
|
||||
impl<'n> Display for OptBuilder<'n> {
|
||||
fn fmt(&self,
|
||||
f: &mut Formatter)
|
||||
-> Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
// Write the name such --long or -l
|
||||
if let Some(l) = self.long {
|
||||
try!(write!(f, "--{}", l));
|
||||
|
|
|
@ -44,30 +44,32 @@ impl<'n> PosBuilder<'n> {
|
|||
max_vals: None,
|
||||
validator: None,
|
||||
overrides: None,
|
||||
settings: ArgFlags::new()
|
||||
settings: ArgFlags::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_arg(a: &Arg<'n, 'n, 'n, 'n, 'n, 'n>,
|
||||
idx: u8,
|
||||
reqs: &mut Vec<&'n str>) -> Self {
|
||||
pub fn from_arg(a: &Arg<'n, 'n, 'n, 'n, 'n, 'n>, idx: u8, reqs: &mut Vec<&'n str>) -> Self {
|
||||
if a.short.is_some() || a.long.is_some() {
|
||||
panic!("Argument \"{}\" has conflicting requirements, both index() and short(), \
|
||||
or long(), were supplied", a.name);
|
||||
or long(), were supplied",
|
||||
a.name);
|
||||
}
|
||||
|
||||
if a.takes_value {
|
||||
panic!("Argument \"{}\" has conflicting requirements, both index() and \
|
||||
takes_value(true) were supplied\n\n\tArguments with an index automatically \
|
||||
take a value, you do not need to specify it manually", a.name);
|
||||
take a value, you do not need to specify it manually",
|
||||
a.name);
|
||||
}
|
||||
|
||||
if a.val_names.is_some() {
|
||||
panic!("Positional arguments (\"{}\") do not support named values, instead \
|
||||
consider multiple positional arguments", a.name);
|
||||
consider multiple positional arguments",
|
||||
a.name);
|
||||
}
|
||||
|
||||
// Create the Positional Arguemnt Builder with each HashSet = None to only allocate
|
||||
// Create the Positional Arguemnt Builder with each HashSet = None to only
|
||||
// allocate
|
||||
// those that require it
|
||||
let mut pb = PosBuilder {
|
||||
name: a.name,
|
||||
|
@ -81,7 +83,7 @@ impl<'n> PosBuilder<'n> {
|
|||
help: a.help,
|
||||
validator: None,
|
||||
overrides: None,
|
||||
settings: ArgFlags::new()
|
||||
settings: ArgFlags::new(),
|
||||
};
|
||||
if a.multiple {
|
||||
pb.settings.set(&ArgSettings::Multiple);
|
||||
|
@ -95,7 +97,8 @@ impl<'n> PosBuilder<'n> {
|
|||
if a.hidden {
|
||||
pb.settings.set(&ArgSettings::Hidden);
|
||||
}
|
||||
// Check if there is anything in the blacklist (mutually excludes list) and add any
|
||||
// Check if there is anything in the blacklist (mutually excludes list) and add
|
||||
// any
|
||||
// values
|
||||
if let Some(ref bl) = a.blacklist {
|
||||
let mut bhs = vec![];
|
||||
|
@ -165,9 +168,7 @@ impl<'n> PosBuilder<'n> {
|
|||
}
|
||||
|
||||
impl<'n> Display for PosBuilder<'n> {
|
||||
fn fmt(&self,
|
||||
f: &mut Formatter)
|
||||
-> Result {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
if self.settings.is_set(&ArgSettings::Required) {
|
||||
try!(write!(f, "<{}>", self.name));
|
||||
} else {
|
||||
|
|
|
@ -77,7 +77,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
|
|||
ArgMatches {
|
||||
args: HashMap::new(),
|
||||
subcommand: None,
|
||||
usage: None
|
||||
usage: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,9 +100,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
|
|||
/// println!("Value for output: {}", o);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn value_of(&self,
|
||||
name: &str)
|
||||
-> Option<&str> {
|
||||
pub fn value_of(&self, name: &str) -> Option<&str> {
|
||||
if let Some(ref arg) = self.args.get(name) {
|
||||
if let Some(ref vals) = arg.values {
|
||||
if let Some(ref val) = vals.values().nth(0) {
|
||||
|
@ -132,9 +130,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
|
|||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn values_of(&'a self,
|
||||
name: &str)
|
||||
-> Option<Vec<&'a str>> {
|
||||
pub fn values_of(&'a self, name: &str) -> Option<Vec<&'a str>> {
|
||||
if let Some(ref arg) = self.args.get(name) {
|
||||
if let Some(ref vals) = arg.values {
|
||||
return Some(vals.values().map(|s| &s[..]).collect::<Vec<_>>());
|
||||
|
@ -156,9 +152,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
|
|||
/// println!("The output argument was used!");
|
||||
/// }
|
||||
/// ```
|
||||
pub fn is_present(&self,
|
||||
name: &str)
|
||||
-> bool {
|
||||
pub fn is_present(&self, name: &str) -> bool {
|
||||
if let Some(ref sc) = self.subcommand {
|
||||
if sc.name == name {
|
||||
return true;
|
||||
|
@ -187,9 +181,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
|
|||
/// println!("Debug mode kind of on");
|
||||
/// }
|
||||
/// ```
|
||||
pub fn occurrences_of(&self,
|
||||
name: &str)
|
||||
-> u8 {
|
||||
pub fn occurrences_of(&self, name: &str) -> u8 {
|
||||
if let Some(ref arg) = self.args.get(name) {
|
||||
return arg.occurrences;
|
||||
}
|
||||
|
@ -210,10 +202,8 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
|
|||
/// // Use matches as normal
|
||||
/// }
|
||||
/// ```
|
||||
pub fn subcommand_matches<'na>(&self,
|
||||
name: &'na str)
|
||||
-> Option<&ArgMatches> {
|
||||
if let Some( ref sc) = self.subcommand {
|
||||
pub fn subcommand_matches<'na>(&self, name: &'na str) -> Option<&ArgMatches> {
|
||||
if let Some(ref sc) = self.subcommand {
|
||||
if sc.name != name {
|
||||
return None;
|
||||
}
|
||||
|
@ -241,7 +231,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn subcommand_name(&self) -> Option<&str> {
|
||||
if let Some( ref sc ) = self.subcommand {
|
||||
if let Some(ref sc) = self.subcommand {
|
||||
return Some(&sc.name[..]);
|
||||
}
|
||||
None
|
||||
|
@ -264,7 +254,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn subcommand(&self) -> (&str, Option<&ArgMatches>) {
|
||||
if let Some( ref sc ) = self.subcommand {
|
||||
if let Some(ref sc) = self.subcommand {
|
||||
return (&sc.name[..], Some(&sc.matches));
|
||||
}
|
||||
("", None)
|
||||
|
@ -282,7 +272,7 @@ impl<'n, 'a> ArgMatches<'n, 'a> {
|
|||
/// println!("{}",app_matches.usage());
|
||||
/// ```
|
||||
pub fn usage(&self) -> &str {
|
||||
if let Some( ref u ) = self.usage {
|
||||
if let Some(ref u) = self.usage {
|
||||
return &u[..];
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
required: false,
|
||||
args: vec![],
|
||||
requires: None,
|
||||
conflicts: None
|
||||
conflicts: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,9 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
a
|
||||
}
|
||||
s => panic!("Unknown ArgGroup setting '{}' in YAML file for \
|
||||
ArgGroup '{}'", s, name_str),
|
||||
ArgGroup '{}'",
|
||||
s,
|
||||
name_str),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,10 +142,10 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
/// # ArgGroup::with_name("conifg")
|
||||
/// .add("config")
|
||||
/// # ).get_matches();
|
||||
pub fn add(mut self,
|
||||
n: &'ar str)
|
||||
-> Self {
|
||||
assert!(self.name != n, "ArgGroup '{}' can not have same name as arg inside it", self.name);
|
||||
pub fn add(mut self, n: &'ar str) -> Self {
|
||||
assert!(self.name != n,
|
||||
"ArgGroup '{}' can not have same name as arg inside it",
|
||||
self.name);
|
||||
self.args.push(n);
|
||||
self
|
||||
}
|
||||
|
@ -160,9 +162,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
/// # ArgGroup::with_name("conifg")
|
||||
/// .add_all(&["config", "input", "output"])
|
||||
/// # ).get_matches();
|
||||
pub fn add_all(mut self,
|
||||
ns: &[&'ar str])
|
||||
-> Self {
|
||||
pub fn add_all(mut self, ns: &[&'ar str]) -> Self {
|
||||
for n in ns {
|
||||
self = self.add(n);
|
||||
}
|
||||
|
@ -184,9 +184,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
/// # ArgGroup::with_name("conifg")
|
||||
/// .required(true)
|
||||
/// # ).get_matches();
|
||||
pub fn required(mut self,
|
||||
r: bool)
|
||||
-> Self {
|
||||
pub fn required(mut self, r: bool) -> Self {
|
||||
self.required = r;
|
||||
self
|
||||
}
|
||||
|
@ -207,9 +205,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
/// # ArgGroup::with_name("conifg")
|
||||
/// .requires("config")
|
||||
/// # ).get_matches();
|
||||
pub fn requires(mut self,
|
||||
n: &'ar str)
|
||||
-> Self {
|
||||
pub fn requires(mut self, n: &'ar str) -> Self {
|
||||
if let Some(ref mut reqs) = self.requires {
|
||||
reqs.push(n);
|
||||
} else {
|
||||
|
@ -234,9 +230,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
/// # ArgGroup::with_name("conifg")
|
||||
/// .requires_all(&["config", "input"])
|
||||
/// # ).get_matches();
|
||||
pub fn requires_all(mut self,
|
||||
ns: &[&'ar str])
|
||||
-> Self {
|
||||
pub fn requires_all(mut self, ns: &[&'ar str]) -> Self {
|
||||
for n in ns {
|
||||
self = self.requires(n);
|
||||
}
|
||||
|
@ -259,9 +253,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
/// # ArgGroup::with_name("conifg")
|
||||
/// .conflicts_with("config")
|
||||
/// # ).get_matches();
|
||||
pub fn conflicts_with(mut self,
|
||||
n: &'ar str)
|
||||
-> Self {
|
||||
pub fn conflicts_with(mut self, n: &'ar str) -> Self {
|
||||
if let Some(ref mut confs) = self.conflicts {
|
||||
confs.push(n);
|
||||
} else {
|
||||
|
@ -286,9 +278,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
/// # ArgGroup::with_name("conifg")
|
||||
/// .conflicts_with_all(&["config", "input"])
|
||||
/// # ).get_matches();
|
||||
pub fn conflicts_with_all(mut self,
|
||||
ns: &[&'ar str])
|
||||
-> Self {
|
||||
pub fn conflicts_with_all(mut self, ns: &[&'ar str]) -> Self {
|
||||
for n in ns {
|
||||
self = self.conflicts_with(n);
|
||||
}
|
||||
|
@ -297,16 +287,20 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> {
|
|||
}
|
||||
|
||||
impl<'n, 'ar> Debug for ArgGroup<'n, 'ar> {
|
||||
fn fmt(&self,
|
||||
f: &mut Formatter)
|
||||
-> Result {
|
||||
write!(f, "{{
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
write!(f,
|
||||
"{{
|
||||
name:{:?},
|
||||
args: {:?},
|
||||
required: {:?},
|
||||
requires: {:?},
|
||||
conflicts: {:?},
|
||||
}}", self.name, self.args, self.required, self.requires, self.conflicts)
|
||||
}}",
|
||||
self.name,
|
||||
self.args,
|
||||
self.required,
|
||||
self.requires,
|
||||
self.conflicts)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,16 +311,16 @@ mod test {
|
|||
#[test]
|
||||
fn groups() {
|
||||
let g = ArgGroup::with_name("test")
|
||||
.add("a1")
|
||||
.add_all(&["a2", "a3"])
|
||||
.add("a4")
|
||||
.required(true)
|
||||
.conflicts_with("c1")
|
||||
.conflicts_with_all(&["c2", "c3"])
|
||||
.conflicts_with("c4")
|
||||
.requires("r1")
|
||||
.requires_all(&["r2", "r3"])
|
||||
.requires("r4");
|
||||
.add("a1")
|
||||
.add_all(&["a2", "a3"])
|
||||
.add("a4")
|
||||
.required(true)
|
||||
.conflicts_with("c1")
|
||||
.conflicts_with_all(&["c2", "c3"])
|
||||
.conflicts_with("c4")
|
||||
.requires("r1")
|
||||
.requires_all(&["r2", "r3"])
|
||||
.requires("r4");
|
||||
|
||||
let args = vec!["a1", "a2", "a3", "a4"];
|
||||
let reqs = vec!["r1", "r2", "r3", "r4"];
|
||||
|
|
|
@ -8,6 +8,5 @@ pub struct MatchedArg {
|
|||
#[doc(hidden)]
|
||||
pub occurrences: u8,
|
||||
#[doc(hidden)]
|
||||
// Consider VecMap<String> once stablized
|
||||
pub values: Option<BTreeMap<u8, String>>,
|
||||
}
|
||||
|
|
|
@ -12,4 +12,4 @@ mod argbuilder;
|
|||
mod matchedarg;
|
||||
mod group;
|
||||
#[allow(dead_code)]
|
||||
pub mod settings;
|
||||
pub mod settings;
|
||||
|
|
|
@ -21,31 +21,31 @@ impl ArgFlags {
|
|||
|
||||
pub fn set(&mut self, s: &ArgSettings) {
|
||||
match *s {
|
||||
ArgSettings::Required => self.0.insert(REQUIRED),
|
||||
ArgSettings::Multiple => self.0.insert(MULTIPLE),
|
||||
ArgSettings::Required => self.0.insert(REQUIRED),
|
||||
ArgSettings::Multiple => self.0.insert(MULTIPLE),
|
||||
ArgSettings::EmptyValues => self.0.insert(EMPTY_VALS),
|
||||
ArgSettings::Global => self.0.insert(GLOBAL),
|
||||
ArgSettings::Hidden => self.0.insert(HIDDEN),
|
||||
ArgSettings::Global => self.0.insert(GLOBAL),
|
||||
ArgSettings::Hidden => self.0.insert(HIDDEN),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unset(&mut self, s: &ArgSettings) {
|
||||
match *s {
|
||||
ArgSettings::Required => self.0.remove(REQUIRED),
|
||||
ArgSettings::Multiple => self.0.remove(MULTIPLE),
|
||||
ArgSettings::Required => self.0.remove(REQUIRED),
|
||||
ArgSettings::Multiple => self.0.remove(MULTIPLE),
|
||||
ArgSettings::EmptyValues => self.0.remove(EMPTY_VALS),
|
||||
ArgSettings::Global => self.0.remove(GLOBAL),
|
||||
ArgSettings::Hidden => self.0.remove(HIDDEN),
|
||||
ArgSettings::Global => self.0.remove(GLOBAL),
|
||||
ArgSettings::Hidden => self.0.remove(HIDDEN),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_set(&self, s: &ArgSettings) -> bool {
|
||||
match *s {
|
||||
ArgSettings::Required => self.0.contains(REQUIRED),
|
||||
ArgSettings::Multiple => self.0.contains(MULTIPLE),
|
||||
ArgSettings::Required => self.0.contains(REQUIRED),
|
||||
ArgSettings::Multiple => self.0.contains(MULTIPLE),
|
||||
ArgSettings::EmptyValues => self.0.contains(EMPTY_VALS),
|
||||
ArgSettings::Global => self.0.contains(GLOBAL),
|
||||
ArgSettings::Hidden => self.0.contains(HIDDEN),
|
||||
ArgSettings::Global => self.0.contains(GLOBAL),
|
||||
ArgSettings::Hidden => self.0.contains(HIDDEN),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,12 +64,12 @@ impl FromStr for ArgSettings {
|
|||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
|
||||
match &*s.to_ascii_lowercase() {
|
||||
"required" => Ok(ArgSettings::Required),
|
||||
"multiple" => Ok(ArgSettings::Multiple),
|
||||
"global" => Ok(ArgSettings::Global),
|
||||
"required" => Ok(ArgSettings::Required),
|
||||
"multiple" => Ok(ArgSettings::Multiple),
|
||||
"global" => Ok(ArgSettings::Global),
|
||||
"emptyvalues" => Ok(ArgSettings::EmptyValues),
|
||||
"hidden" => Ok(ArgSettings::Hidden),
|
||||
_ => Err("unknown ArgSetting, cannot convert from str".to_owned())
|
||||
"hidden" => Ok(ArgSettings::Hidden),
|
||||
_ => Err("unknown ArgSetting, cannot convert from str".to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
src/fmt.rs
13
src/fmt.rs
|
@ -1,7 +1,7 @@
|
|||
use std::fmt;
|
||||
|
||||
#[cfg(all(feature = "color", not(target_os = "windows")))]
|
||||
use ansi_term::Colour::{Red, Green, Yellow};
|
||||
use ansi_term::Colour::{Green, Red, Yellow};
|
||||
#[cfg(all(feature = "color", not(target_os = "windows")))]
|
||||
use ansi_term::ANSIString;
|
||||
|
||||
|
@ -32,8 +32,7 @@ impl<T: AsRef<str>> Format<T> {
|
|||
|
||||
#[cfg(all(feature = "color", not(target_os = "windows")))]
|
||||
impl<T: AsRef<str>> fmt::Display for Format<T> {
|
||||
fn fmt(&self,
|
||||
f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", &self.format())
|
||||
}
|
||||
}
|
||||
|
@ -51,8 +50,7 @@ impl<T: fmt::Display> Format<T> {
|
|||
|
||||
#[cfg(any(not(feature = "color"), target_os = "windows"))]
|
||||
impl<T: fmt::Display> fmt::Display for Format<T> {
|
||||
fn fmt(&self,
|
||||
f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", &self.format())
|
||||
}
|
||||
}
|
||||
|
@ -60,12 +58,13 @@ impl<T: fmt::Display> fmt::Display for Format<T> {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::Format;
|
||||
use ansi_term::Colour::{Red, Green, Yellow};
|
||||
use ansi_term::Colour::{Green, Red, Yellow};
|
||||
|
||||
#[test]
|
||||
fn colored_output() {
|
||||
let err = Format::Error("error");
|
||||
assert_eq!(&*format!("{}", err), &*format!("{}", Red.bold().paint("error")));
|
||||
assert_eq!(&*format!("{}", err),
|
||||
&*format!("{}", Red.bold().paint("error")));
|
||||
let good = Format::Good("good");
|
||||
assert_eq!(&*format!("{}", good), &*format!("{}", Green.paint("good")));
|
||||
let warn = Format::Warning("warn");
|
||||
|
|
322
src/lib.rs
322
src/lib.rs
|
@ -1,70 +1,88 @@
|
|||
//! Command Line Argument Parser for Rust
|
||||
//!
|
||||
//! It is a simple to use, efficient, and full featured library for parsing command line arguments
|
||||
//! It is a simple to use, efficient, and full featured library for parsing
|
||||
//! command line arguments
|
||||
//! and subcommands when writing console, or terminal applications.
|
||||
//!
|
||||
//! ## About
|
||||
//!
|
||||
//! `clap` is used to parse *and validate* the string of command line arguments provided by the
|
||||
//! user at runtime. You provide the list of valid possibilities, and `clap` handles the rest. This
|
||||
//! means you focus on your *applications* functionality, and less on the parsing and validating of
|
||||
//! `clap` is used to parse *and validate* the string of command line arguments
|
||||
//! provided by the
|
||||
//! user at runtime. You provide the list of valid possibilities, and `clap`
|
||||
//! handles the rest. This
|
||||
//! means you focus on your *applications* functionality, and less on the
|
||||
//! parsing and validating of
|
||||
//! arguments.
|
||||
//!
|
||||
//! `clap` also provides the traditional version and help switches (or flags) 'for free' meaning
|
||||
//! automatically with no configuration. It does this by checking list of valid possibilities you
|
||||
//! supplied and if you haven't them already (or only defined some of them), `clap` will auto-
|
||||
//! generate the applicable ones. If you are using subcommands, `clap` will also auto-generate a
|
||||
//! `clap` also provides the traditional version and help switches (or flags)
|
||||
//! 'for free' meaning
|
||||
//! automatically with no configuration. It does this by checking list of valid
|
||||
//! possibilities you
|
||||
//! supplied and if you haven't them already (or only defined some of them),
|
||||
//! `clap` will auto-
|
||||
//! generate the applicable ones. If you are using subcommands, `clap` will
|
||||
//! also auto-generate a
|
||||
//! `help` subcommand for you in addition to the traditional flags.
|
||||
//!
|
||||
//! Once `clap` parses the user provided string of arguments, it returns the matches along with any
|
||||
//! applicable values. If the user made an error or typo, `clap` informs them of the mistake and
|
||||
//! exits gracefully. Because of this, you can make reasonable assumptions in your code about the
|
||||
//! Once `clap` parses the user provided string of arguments, it returns the
|
||||
//! matches along with any
|
||||
//! applicable values. If the user made an error or typo, `clap` informs them
|
||||
//! of the mistake and
|
||||
//! exits gracefully. Because of this, you can make reasonable assumptions in
|
||||
//! your code about the
|
||||
//! validity of the arguments.
|
||||
//!
|
||||
//! ## Quick Examples
|
||||
//!
|
||||
//! The following examples show a quick example of some of the very basic functionality of `clap`.
|
||||
//! For more advanced usage, such as requirements, exclusions, groups, multiple values and
|
||||
//! occurrences see the [video tutorials][video tutorials], [documentation][docs], or
|
||||
//! The following examples show a quick example of some of the very basic
|
||||
//! functionality of `clap`.
|
||||
//! For more advanced usage, such as requirements, exclusions, groups, multiple
|
||||
//! values and
|
||||
//! occurrences see the [video tutorials][video tutorials],
|
||||
//! [documentation][docs], or
|
||||
//! [examples/][examples] directory of this crate's repository.
|
||||
//!
|
||||
//! **NOTE:** All these examples are functionally the same, but show three different styles in
|
||||
//! **NOTE:** All these examples are functionally the same, but show three
|
||||
//! different styles in
|
||||
//! which to use `clap`
|
||||
//!
|
||||
//! ```no_run
|
||||
//! // (Full example with detailed comments in examples/01a_quick_example.rs)
|
||||
//! //
|
||||
//! // This example demonstrates clap's "usage strings" method of creating arguments which is less
|
||||
//! // less verbose
|
||||
//! // This example demonstrates clap's "usage strings" method of creating
|
||||
//! // arguments which is less less verbose
|
||||
//! extern crate clap;
|
||||
//! use clap::{Arg, App, SubCommand};
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let matches = App::new("myapp")
|
||||
//! .version("1.0")
|
||||
//! .author("Kevin K. <kbknapp@gmail.com>")
|
||||
//! .about("Does awesome things")
|
||||
//! .args_from_usage(
|
||||
//! "-c --config=[CONFIG] 'Sets a custom config file'
|
||||
//! <INPUT> 'Sets the input file to use'
|
||||
//! [debug]... -d 'Sets the level of debugging information'")
|
||||
//! .subcommand(SubCommand::with_name("test")
|
||||
//! .about("controls testing features")
|
||||
//! .version("1.3")
|
||||
//! .author("Someone E. <someone_else@other.com>")
|
||||
//! .arg_from_usage("-v --verbose 'Print test information verbosely'"))
|
||||
//! .get_matches();
|
||||
//! .version("1.0")
|
||||
//! .author("Kevin K. <kbknapp@gmail.com>")
|
||||
//! .about("Does awesome things")
|
||||
//! .args_from_usage(
|
||||
//! "-c --config=[CONFIG] 'Sets a custom config file'
|
||||
//! <INPUT> 'Sets the input file to use'
|
||||
//! [debug]... -d 'Sets the level of debugging information'")
|
||||
//! .subcommand(SubCommand::with_name("test")
|
||||
//! .about("controls testing features")
|
||||
//! .version("1.3")
|
||||
//! .author("Someone E. <someone_else@other.com>")
|
||||
//! .arg_from_usage(
|
||||
//! "-v --verbose 'Print test information verbosely'"))
|
||||
//! .get_matches();
|
||||
//!
|
||||
//! // Calling .unwrap() is safe here because "INPUT" is required (if "INPUT" wasn't
|
||||
//! // required we could have used an 'if let' to conditionally get the value)
|
||||
//! // Calling .unwrap() is safe here because "INPUT" is required (if
|
||||
//! // "INPUT" wasn't required we could have used an 'if let' to
|
||||
//! // conditionally get the value)
|
||||
//! println!("Using input file: {}", matches.value_of("INPUT").unwrap());
|
||||
//!
|
||||
//! // Gets a value for config if supplied by user, or defaults to "default.conf"
|
||||
//! // Gets a value for config if supplied by user, or defaults to
|
||||
//! // "default.conf"
|
||||
//! let config = matches.value_of("CONFIG").unwrap_or("default.conf");
|
||||
//! println!("Value for config: {}", config);
|
||||
//!
|
||||
//! // Vary the output based on how many times the user used the "debug" flag
|
||||
//! // (i.e. 'myapp -d -d -d' or 'myapp -ddd' vs 'myapp -d'
|
||||
//! // Vary the output based on how many times the user used the "debug"
|
||||
//! // flag (i.e. 'myapp -d -d -d' or 'myapp -ddd' vs 'myapp -d')
|
||||
//! match matches.occurrences_of("debug") {
|
||||
//! 0 => println!("Debug mode is off"),
|
||||
//! 1 => println!("Debug mode is kind of on"),
|
||||
|
@ -72,8 +90,9 @@
|
|||
//! 3 | _ => println!("Don't be crazy"),
|
||||
//! }
|
||||
//!
|
||||
//! // You can information about subcommands by requesting their matches by name
|
||||
//! // (as below), requesting just the name used, or both at the same time
|
||||
//! // You can information about subcommands by requesting their matches by
|
||||
//! // name (as below), requesting just the name used, or both at the same
|
||||
//! // time
|
||||
//! if let Some(matches) = matches.subcommand_matches("test") {
|
||||
//! if matches.is_present("verbose") {
|
||||
//! println!("Printing verbosely...");
|
||||
|
@ -86,57 +105,64 @@
|
|||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! The following example is functionally the same as the one above, but this method allows more
|
||||
//! advanced configuration options (not shown in this small example), or even dynamically
|
||||
//! generating arguments when desired. Both methods can be used together to get the best of both
|
||||
//! The following example is functionally the same as the one above, but this
|
||||
//! method allows more
|
||||
//! advanced configuration options (not shown in this small example), or even
|
||||
//! dynamically
|
||||
//! generating arguments when desired. Both methods can be used together to get
|
||||
//! the best of both
|
||||
//! worlds (see the documentation, [examples/][examples], or video tutorials).
|
||||
//!
|
||||
//! ```no_run
|
||||
//! // (Full example with detailed comments in examples/01b_quick_example.rs)
|
||||
//! //
|
||||
//! // This example demonstrates clap's full 'builder pattern' style of creating arguments which is
|
||||
//! // more verbose, but allows easier editing, and at times more advanced options, or the possibility
|
||||
//! // This example demonstrates clap's full 'builder pattern' style of
|
||||
//! // creating arguments which is
|
||||
//! // more verbose, but allows easier editing, and at times more advanced
|
||||
//! // options, or the possibility
|
||||
//! // to generate arguments dynamically.
|
||||
//! extern crate clap;
|
||||
//! use clap::{Arg, App, SubCommand};
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let matches = App::new("myapp")
|
||||
//! .version("1.0")
|
||||
//! .author("Kevin K. <kbknapp@gmail.com>")
|
||||
//! .about("Does awesome things")
|
||||
//! .arg(Arg::with_name("CONFIG")
|
||||
//! .short("c")
|
||||
//! .long("config")
|
||||
//! .help("Sets a custom config file")
|
||||
//! .takes_value(true))
|
||||
//! .arg(Arg::with_name("INPUT")
|
||||
//! .help("Sets the input file to use")
|
||||
//! .required(true)
|
||||
//! .index(1))
|
||||
//! .arg(Arg::with_name("debug")
|
||||
//! .short("d")
|
||||
//! .multiple(true)
|
||||
//! .help("Sets the level of debugging information"))
|
||||
//! .subcommand(SubCommand::with_name("test")
|
||||
//! .about("controls testing features")
|
||||
//! .version("1.3")
|
||||
//! .author("Someone E. <someone_else@other.com>")
|
||||
//! .arg(Arg::with_name("verbose")
|
||||
//! .short("v")
|
||||
//! .help("print test information verbosely")))
|
||||
//! .get_matches();
|
||||
//! .version("1.0")
|
||||
//! .author("Kevin K. <kbknapp@gmail.com>")
|
||||
//! .about("Does awesome things")
|
||||
//! .arg(Arg::with_name("CONFIG")
|
||||
//! .short("c")
|
||||
//! .long("config")
|
||||
//! .help("Sets a custom config file")
|
||||
//! .takes_value(true))
|
||||
//! .arg(Arg::with_name("INPUT")
|
||||
//! .help("Sets the input file to use")
|
||||
//! .required(true)
|
||||
//! .index(1))
|
||||
//! .arg(Arg::with_name("debug")
|
||||
//! .short("d")
|
||||
//! .multiple(true)
|
||||
//! .help("Sets the level of debugging information"))
|
||||
//! .subcommand(SubCommand::with_name("test")
|
||||
//! .about("controls testing features")
|
||||
//! .version("1.3")
|
||||
//! .author("Someone E. <someone_else@other.com>")
|
||||
//! .arg(Arg::with_name("verbose")
|
||||
//! .short("v")
|
||||
//! .help("print test information verbosely")))
|
||||
//! .get_matches();
|
||||
//!
|
||||
//! // Calling .unwrap() is safe here because "INPUT" is required (if "INPUT" wasn't
|
||||
//! // required we could have used an 'if let' to conditionally get the value)
|
||||
//! // Calling .unwrap() is safe here because "INPUT" is required (if
|
||||
//! // "INPUT" wasn't required we could have used an 'if let' to
|
||||
//! // conditionally get the value)
|
||||
//! println!("Using input file: {}", matches.value_of("INPUT").unwrap());
|
||||
//!
|
||||
//! // Gets a value for config if supplied by user, or defaults to "default.conf"
|
||||
//! // Gets a value for config if supplied by user, or defaults to
|
||||
//! // "default.conf"
|
||||
//! let config = matches.value_of("CONFIG").unwrap_or("default.conf");
|
||||
//! println!("Value for config: {}", config);
|
||||
//!
|
||||
//! // Vary the output based on how many times the user used the "debug" flag
|
||||
//! // (i.e. 'myapp -d -d -d' or 'myapp -ddd' vs 'myapp -d'
|
||||
//! // Vary the output based on how many times the user used the "debug"
|
||||
//! // flag (i.e. 'myapp -d -d -d' or 'myapp -ddd' vs 'myapp -d')
|
||||
//! match matches.occurrences_of("debug") {
|
||||
//! 0 => println!("Debug mode is off"),
|
||||
//! 1 => println!("Debug mode is kind of on"),
|
||||
|
@ -144,8 +170,9 @@
|
|||
//! 3 | _ => println!("Don't be crazy"),
|
||||
//! }
|
||||
//!
|
||||
//! // You can information about subcommands by requesting their matches by name
|
||||
//! // (as below), requesting just the name used, or both at the same time
|
||||
//! // You can information about subcommands by requesting their matches by
|
||||
//! // name (as below), requesting just the name used, or both at the same
|
||||
//! // time
|
||||
//! if let Some(matches) = matches.subcommand_matches("test") {
|
||||
//! if matches.is_present("verbose") {
|
||||
//! println!("Printing verbosely...");
|
||||
|
@ -158,14 +185,15 @@
|
|||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! The following combines the previous two examples by using the simplicity of the `from_usage`
|
||||
//! The following combines the previous two examples by using the simplicity of
|
||||
//! the `from_usage`
|
||||
//! methods and the performance of the Builder Pattern.
|
||||
//!
|
||||
//! ```no_run
|
||||
//! // (Full example with detailed comments in examples/01c_quick_example.rs)
|
||||
//! //
|
||||
//! // This example demonstrates clap's "usage strings" method of creating arguments which is less
|
||||
//! // less verbose
|
||||
//! // This example demonstrates clap's "usage strings" method of creating
|
||||
//! // arguments which is less verbose
|
||||
//! #[macro_use]
|
||||
//! extern crate clap;
|
||||
//!
|
||||
|
@ -185,16 +213,18 @@
|
|||
//! )
|
||||
//! ).get_matches();
|
||||
//!
|
||||
//! // Calling .unwrap() is safe here because "INPUT" is required (if "INPUT" wasn't
|
||||
//! // required we could have used an 'if let' to conditionally get the value)
|
||||
//! // Calling .unwrap() is safe here because "INPUT" is required (if
|
||||
//! // "INPUT" wasn't required we could have used an 'if let' to
|
||||
//! // conditionally get the value)
|
||||
//! println!("Using input file: {}", matches.value_of("INPUT").unwrap());
|
||||
//!
|
||||
//! // Gets a value for config if supplied by user, or defaults to "default.conf"
|
||||
//! // Gets a value for config if supplied by user, or defaults to
|
||||
//! // "default.conf"
|
||||
//! let config = matches.value_of("CONFIG").unwrap_or("default.conf");
|
||||
//! println!("Value for config: {}", config);
|
||||
//!
|
||||
//! // Vary the output based on how many times the user used the "debug" flag
|
||||
//! // (i.e. 'myapp -d -d -d' or 'myapp -ddd' vs 'myapp -d'
|
||||
//! // Vary the output based on how many times the user used the "debug"
|
||||
//! // flag (i.e. 'myapp -d -d -d' or 'myapp -ddd' vs 'myapp -d')
|
||||
//! match matches.occurrences_of("debug") {
|
||||
//! 0 => println!("Debug mode is off"),
|
||||
//! 1 => println!("Debug mode is kind of on"),
|
||||
|
@ -202,8 +232,9 @@
|
|||
//! 3 | _ => println!("Don't be crazy"),
|
||||
//! }
|
||||
//!
|
||||
//! // You can information about subcommands by requesting their matches by name
|
||||
//! // (as below), requesting just the name used, or both at the same time
|
||||
//! // You can information about subcommands by requesting their matches by
|
||||
//! // name (as below), requesting just the name used, or both at the same
|
||||
//! // time
|
||||
//! if let Some(matches) = matches.subcommand_matches("test") {
|
||||
//! if matches.is_present("verbose") {
|
||||
//! println!("Printing verbosely...");
|
||||
|
@ -216,9 +247,12 @@
|
|||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! This final method shows how you can use a YAML file to build your CLI and keep your Rust source
|
||||
//! tidy. First, create the `cli.yml` file to hold your CLI options, but it could be called
|
||||
//! anything we like (we'll use the same both examples above to keep it functionally equivilant):
|
||||
//! This final method shows how you can use a YAML file to build your CLI and
|
||||
//! keep your Rust source
|
||||
//! tidy. First, create the `cli.yml` file to hold your CLI options, but it
|
||||
//! could be called
|
||||
//! anything we like (we'll use the same both examples above to keep it
|
||||
//! functionally equivilant):
|
||||
//!
|
||||
//! ```yaml
|
||||
//! name: myapp
|
||||
|
@ -250,31 +284,39 @@
|
|||
//! help: print test information verbosely
|
||||
//! ```
|
||||
//!
|
||||
//! Now we create our `main.rs` file just like we would have with the previous two examples:
|
||||
//! Now we create our `main.rs` file just like we would have with the previous
|
||||
//! two examples:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! // (Full example with detailed comments in examples/17_yaml.rs)
|
||||
//! //
|
||||
//! // This example demonstrates clap's building from YAML style of creating arguments which is far
|
||||
//! // more clean, but takes a very small performance hit compared to the other two methods.
|
||||
//! // This example demonstrates clap's building from YAML style of creating
|
||||
//! arguments which is far
|
||||
//! // more clean, but takes a very small performance hit compared to the other
|
||||
//! two methods.
|
||||
//! #[macro_use]
|
||||
//! extern crate clap;
|
||||
//! use clap::App;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! // The YAML file is found relative to the current file, similar to how modules are found
|
||||
//! // The YAML file is found relative to the current file, similar to how
|
||||
//! modules are found
|
||||
//! let yaml = load_yaml!("cli.yml");
|
||||
//! let matches = App::from_yaml(yaml).get_matches();
|
||||
//!
|
||||
//! // Calling .unwrap() is safe here because "INPUT" is required (if "INPUT" wasn't
|
||||
//! // required we could have used an 'if let' to conditionally get the value)
|
||||
//! // Calling .unwrap() is safe here because "INPUT" is required (if
|
||||
//! "INPUT" wasn't
|
||||
//! // required we could have used an 'if let' to conditionally get the
|
||||
//! value)
|
||||
//! println!("Using input file: {}", matches.value_of("INPUT").unwrap());
|
||||
//!
|
||||
//! // Gets a value for config if supplied by user, or defaults to "default.conf"
|
||||
//! // Gets a value for config if supplied by user, or defaults to
|
||||
//! "default.conf"
|
||||
//! let config = matches.value_of("CONFIG").unwrap_or("default.conf");
|
||||
//! println!("Value for config: {}", config);
|
||||
//!
|
||||
//! // Vary the output based on how many times the user used the "debug" flag
|
||||
//! // Vary the output based on how many times the user used the "debug"
|
||||
//! flag
|
||||
//! // (i.e. 'myapp -d -d -d' or 'myapp -ddd' vs 'myapp -d'
|
||||
//! match matches.occurrences_of("debug") {
|
||||
//! 0 => println!("Debug mode is off"),
|
||||
|
@ -283,7 +325,8 @@
|
|||
//! 3 | _ => println!("Don't be crazy"),
|
||||
//! }
|
||||
//!
|
||||
//! // You can information about subcommands by requesting their matches by name
|
||||
//! // You can information about subcommands by requesting their matches by
|
||||
//! name
|
||||
//! // (as below), requesting just the name used, or both at the same time
|
||||
//! if let Some(matches) = matches.subcommand_matches("test") {
|
||||
//! if matches.is_present("verbose") {
|
||||
|
@ -297,12 +340,17 @@
|
|||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! If you were to compile any of the above programs and run them with the flag `--help` or `-h`
|
||||
//! (or `help` subcommand, since we defined `test` as a subcommand) the following would be output
|
||||
//! If you were to compile any of the above programs and run them with the flag
|
||||
//! `--help` or `-h`
|
||||
//! (or `help` subcommand, since we defined `test` as a subcommand) the
|
||||
//! following would be output
|
||||
//!
|
||||
//! **NOTE**: The YAML option requires adding a special `features` flag when compiling `clap`
|
||||
//! because it is not compiled by default since it takes additional dependencies that some people
|
||||
//! may not need. Simply change your `clap = "1"` to `clap = {version = "1", features = ["yaml"]}`
|
||||
//! **NOTE**: The YAML option requires adding a special `features` flag when
|
||||
//! compiling `clap`
|
||||
//! because it is not compiled by default since it takes additional
|
||||
//! dependencies that some people
|
||||
//! may not need. Simply change your `clap = "1"` to `clap = {version = "1",
|
||||
//! features = ["yaml"]}`
|
||||
//! in your `Cargo.toml` to use the YAML version.
|
||||
//!
|
||||
//! ```text
|
||||
|
@ -330,7 +378,8 @@
|
|||
//! test Controls testing features
|
||||
//! ```
|
||||
//!
|
||||
//! **NOTE:** You could also run `myapp test --help` to see similar output and options for the
|
||||
//! **NOTE:** You could also run `myapp test --help` to see similar output and
|
||||
//! options for the
|
||||
//! `test` subcommand.
|
||||
//!
|
||||
//! ## Try it!
|
||||
|
@ -339,7 +388,8 @@
|
|||
//!
|
||||
//! To try out the pre-built example, use the following steps:
|
||||
//!
|
||||
//! * Clone the repo `$ git clone https://github.com/kbknapp/clap-rs && cd clap-rs/clap-tests`
|
||||
//! * Clone the repo `$ git clone https://github.com/kbknapp/clap-rs && cd
|
||||
//! clap-rs/clap-tests`
|
||||
//! * Compile the example `$ cargo build --release`
|
||||
//! * Run the help info `$ ./target/release/claptests --help`
|
||||
//! * Play with the arguments!
|
||||
|
@ -367,11 +417,13 @@
|
|||
//! ```
|
||||
//!
|
||||
//! * Build your program `$ cargo build --release`
|
||||
//! * Run w/ help or version `$ ./target/release/fake --help` or `$ ./target/release/fake --version`
|
||||
//! * Run w/ help or version `$ ./target/release/fake --help` or `$
|
||||
//! ./target/release/fake --version`
|
||||
//!
|
||||
//! ## Usage
|
||||
//!
|
||||
//! For full usage, add `clap` as a dependency in your `Cargo.toml` file to use from crates.io:
|
||||
//! For full usage, add `clap` as a dependency in your `Cargo.toml` file to use
|
||||
//! from crates.io:
|
||||
//!
|
||||
//! ```toml
|
||||
//! [dependencies]
|
||||
|
@ -386,15 +438,18 @@
|
|||
//!
|
||||
//! Add `extern crate clap;` to your crate root.
|
||||
//!
|
||||
//! Define a list of valid arguments for your program (see the [documentation][docs] or
|
||||
//! Define a list of valid arguments for your program (see the
|
||||
//! [documentation][docs] or
|
||||
//! [examples/][examples] directory of this repo)
|
||||
//!
|
||||
//! Then run `cargo build` or `cargo update && cargo build` for your project.
|
||||
//!
|
||||
//! ### Optional Dependencies / Features
|
||||
//!
|
||||
//! If you'd like to keep your dependency list to **only** `clap`, you can disable any features
|
||||
//! that require an additional dependency. To do this, add this to your `Cargo.toml`:
|
||||
//! If you'd like to keep your dependency list to **only** `clap`, you can
|
||||
//! disable any features
|
||||
//! that require an additional dependency. To do this, add this to your
|
||||
//! `Cargo.toml`:
|
||||
//!
|
||||
//! ```toml
|
||||
//! [dependencies.clap]
|
||||
|
@ -402,7 +457,8 @@
|
|||
//! default-features = false
|
||||
//! ```
|
||||
//!
|
||||
//! You can also selectively enable only the features you'd like to include, by adding:
|
||||
//! You can also selectively enable only the features you'd like to include, by
|
||||
//! adding:
|
||||
//!
|
||||
//! ```toml
|
||||
//! [dependencies.clap]
|
||||
|
@ -415,10 +471,13 @@
|
|||
//!
|
||||
//! The following is a list of optional `clap` features:
|
||||
//!
|
||||
//! * **"suggestions"**: Turns on the `Did you mean '--myoption' ?` feature for when users make
|
||||
//! * **"suggestions"**: Turns on the `Did you mean '--myoption' ?` feature for
|
||||
//! when users make
|
||||
//! typos.
|
||||
//! * **"color"**: Turns on red error messages. This feature only works on non-Windows OSs.
|
||||
//! * **"lints"**: This is **not** included by default and should only be used while developing to
|
||||
//! * **"color"**: Turns on red error messages. This feature only works on
|
||||
//! non-Windows OSs.
|
||||
//! * **"lints"**: This is **not** included by default and should only be used
|
||||
//! while developing to
|
||||
//! run basic lints against changes. This can only be used on Rust nightly.
|
||||
//!
|
||||
//! ### Dependencies Tree
|
||||
|
@ -426,32 +485,42 @@
|
|||
//! The following graphic depicts `clap`s dependency graph.
|
||||
//!
|
||||
//! * **Dashed** Line: Optional dependency
|
||||
//! * **Red** Color: **NOT** included by default (must use cargo `features` to enable)
|
||||
//! * **Red** Color: **NOT** included by default (must use cargo `features` to
|
||||
//! enable)
|
||||
//!
|
||||
//! ![clap dependencies](https://raw.githubusercontent.com/kbknapp/clap-rs/master/clap.png)
|
||||
//! ![clap dependencies](https://raw.githubusercontent.
|
||||
//! com/kbknapp/clap-rs/master/clap.png)
|
||||
//!
|
||||
//! ### More Information
|
||||
//!
|
||||
//! You can find complete documentation on the [github-pages site][docs] for this project.
|
||||
//! You can find complete documentation on the [github-pages site][docs] for
|
||||
//! this project.
|
||||
//!
|
||||
//! You can also find usage examples in the [examples/][examples] directory of this repo.
|
||||
//! You can also find usage examples in the [examples/][examples] directory of
|
||||
//! this repo.
|
||||
//!
|
||||
//! #### Video Tutorials
|
||||
//!
|
||||
//! There's also the video tutorial series [Argument Parsing with Rust][video tutorials] that I've
|
||||
//! There's also the video tutorial series [Argument Parsing with Rust][video
|
||||
//! tutorials] that I've
|
||||
//! been working on.
|
||||
//!
|
||||
//! *Note*: Two new videos have just been added ([08 From Usage](https://youtu.be/xc6VdedFrG0), and
|
||||
//! [09 Typed Values](https://youtu.be/mZn3C1DnD90)), if you're already familiar with `clap` but
|
||||
//! want to know more about these two details you can check out those videos without watching the
|
||||
//! *Note*: Two new videos have just been added ([08 From
|
||||
//! Usage](https://youtu.be/xc6VdedFrG0), and
|
||||
//! [09 Typed Values](https://youtu.be/mZn3C1DnD90)), if you're already
|
||||
//! familiar with `clap` but
|
||||
//! want to know more about these two details you can check out those videos
|
||||
//! without watching the
|
||||
//! previous few.
|
||||
//!
|
||||
//! *Note*: Apologies for the resolution of the first video, it will be updated to a better
|
||||
//! *Note*: Apologies for the resolution of the first video, it will be updated
|
||||
//! to a better
|
||||
//! resolution soon. The other videos have a proper resolution.
|
||||
//!
|
||||
//! ### Running the tests
|
||||
//!
|
||||
//! If contributing, you can run the tests as follows (assuming you're in the `clap-rs` directory)
|
||||
//! If contributing, you can run the tests as follows (assuming you're in the
|
||||
//! `clap-rs` directory)
|
||||
//!
|
||||
//! ```sh
|
||||
//! cargo test --features yaml && make -C clap-tests test
|
||||
|
@ -459,14 +528,17 @@
|
|||
//!
|
||||
//! ## License
|
||||
//!
|
||||
//! `clap` is licensed under the MIT license. Please read the [LICENSE-MIT][license]
|
||||
//! `clap` is licensed under the MIT license. Please read the
|
||||
//! [LICENSE-MIT][license]
|
||||
//! file in
|
||||
//! this repository for more information.
|
||||
//!
|
||||
//! [examples]: https://github.com/kbknapp/clap-rs/tree/master/examples
|
||||
//! [docs]: http://kbknapp.github.io/clap-rs/clap/index.html
|
||||
//! [video tutorials]: https://www.youtube.com/playlist?list=PLza5oFLQGTl0Bc_EU_pBNcX-rhVqDTRxv
|
||||
//! [license]: https://raw.githubusercontent.com/kbknapp/clap-rs/master/LICENSE-MIT
|
||||
//! [video tutorials]:
|
||||
//! https://www.youtube.com/playlist?list=PLza5oFLQGTl0Bc_EU_pBNcX-rhVqDTRxv
|
||||
//! [license]:
|
||||
//! https://raw.githubusercontent.com/kbknapp/clap-rs/master/LICENSE-MIT
|
||||
|
||||
#![crate_type= "lib"]
|
||||
#![cfg_attr(feature = "nightly", feature(plugin))]
|
||||
|
@ -494,7 +566,7 @@ extern crate bitflags;
|
|||
|
||||
#[cfg(feature = "yaml")]
|
||||
pub use yaml_rust::YamlLoader;
|
||||
pub use args::{Arg, SubCommand, ArgMatches, ArgGroup};
|
||||
pub use args::{Arg, ArgGroup, ArgMatches, SubCommand};
|
||||
pub use app::{App, AppSettings, ClapError, ClapErrorType};
|
||||
pub use fmt::Format;
|
||||
|
||||
|
|
|
@ -213,7 +213,8 @@ macro_rules! parse_group_reqs {
|
|||
|
||||
// Thanks to bluss and flan3002 in #rust IRC
|
||||
//
|
||||
// Helps with rightward drift when iterating over something and matching each item.
|
||||
// Helps with rightward drift when iterating over something and matching each
|
||||
// item.
|
||||
macro_rules! for_match {
|
||||
($it:ident, $($p:pat => $($e:expr);+),*) => {
|
||||
for i in $it {
|
||||
|
|
|
@ -48,23 +48,28 @@ impl<'u> Iterator for UsageParser<'u> {
|
|||
while let Some(c) = self.chars.next() {
|
||||
self.e += 1;
|
||||
if c == closing {
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
if self.e > self.usage.len() {
|
||||
return None
|
||||
return None;
|
||||
}
|
||||
|
||||
let name = &self.usage[self.s..self.e];
|
||||
|
||||
return Some(UsageToken::Name(name, if c == '<' { Some(true) } else { None }));
|
||||
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
|
||||
continue;
|
||||
}
|
||||
|
||||
return Some(UsageToken::Help(&self.usage[self.s..self.e]));
|
||||
|
@ -82,17 +87,17 @@ impl<'u> Iterator for UsageParser<'u> {
|
|||
while let Some(c) = self.chars.next() {
|
||||
self.e += 1;
|
||||
if c == ' ' || c == '=' || c == '.' {
|
||||
break
|
||||
break;
|
||||
}
|
||||
}
|
||||
if self.e > self.usage.len() {
|
||||
return None
|
||||
return None;
|
||||
}
|
||||
|
||||
if self.e == self.usage.len() - 1 {
|
||||
return Some(UsageToken::Long(&self.usage[self.s..]))
|
||||
return Some(UsageToken::Long(&self.usage[self.s..]));
|
||||
}
|
||||
return Some(UsageToken::Long(&self.usage[self.s..self.e]))
|
||||
return Some(UsageToken::Long(&self.usage[self.s..self.e]));
|
||||
}
|
||||
Some(c) => {
|
||||
// When short is first don't increment e
|
||||
|
@ -101,12 +106,12 @@ impl<'u> Iterator for UsageParser<'u> {
|
|||
}
|
||||
// Short
|
||||
if !c.is_alphanumeric() {
|
||||
return None
|
||||
return None;
|
||||
}
|
||||
return Some(UsageToken::Short(c))
|
||||
return Some(UsageToken::Short(c));
|
||||
}
|
||||
_ => {
|
||||
return None
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,18 +136,20 @@ impl<'u> Iterator for UsageParser<'u> {
|
|||
}
|
||||
}
|
||||
if mult {
|
||||
return Some(UsageToken::Multiple)
|
||||
return Some(UsageToken::Multiple);
|
||||
}
|
||||
}
|
||||
Some(' ') | Some('=') | Some(']') | Some('>') | Some('\t') | Some(',') => {
|
||||
self.e += 1;
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
None => {
|
||||
return None
|
||||
return None;
|
||||
}
|
||||
Some(c) => panic!("Usage parser error, unexpected \
|
||||
\"{}\" at \"{}\", check from_usage call", c, self.usage),
|
||||
\"{}\" at \"{}\", check from_usage call",
|
||||
c,
|
||||
self.usage),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue