2016-09-05 19:29:40 +00:00
|
|
|
// Third Party
|
2016-09-05 21:03:45 +00:00
|
|
|
use vec_map::VecMap;
|
2016-09-05 19:29:40 +00:00
|
|
|
|
|
|
|
// Internal
|
|
|
|
use INTERNAL_ERROR_MSG;
|
2016-01-25 20:45:50 +00:00
|
|
|
use args::Arg;
|
|
|
|
use args::settings::ArgSettings;
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
enum UsageToken {
|
|
|
|
Name,
|
|
|
|
ValName,
|
|
|
|
Short,
|
|
|
|
Long,
|
|
|
|
Help,
|
|
|
|
Multiple,
|
2016-05-06 21:35:53 +00:00
|
|
|
Unknown,
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 19:02:10 +00:00
|
|
|
#[doc(hidden)]
|
2016-01-25 20:45:50 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct UsageParser<'a> {
|
|
|
|
usage: &'a str,
|
|
|
|
pos: usize,
|
|
|
|
start: usize,
|
|
|
|
prev: UsageToken,
|
2016-05-06 21:35:53 +00:00
|
|
|
explicit_name_set: bool,
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> UsageParser<'a> {
|
|
|
|
fn new(usage: &'a str) -> Self {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::new: usage={:?}", usage);
|
2016-01-25 20:45:50 +00:00
|
|
|
UsageParser {
|
|
|
|
usage: usage,
|
|
|
|
pos: 0,
|
|
|
|
start: 0,
|
|
|
|
prev: UsageToken::Unknown,
|
|
|
|
explicit_name_set: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_usage(usage: &'a str) -> Self {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::from_usage;");
|
2016-01-25 20:45:50 +00:00
|
|
|
UsageParser::new(usage)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse(mut self) -> Arg<'a, 'a> {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::parse;");
|
2016-01-25 20:45:50 +00:00
|
|
|
let mut arg = Arg::default();
|
|
|
|
loop {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::parse:iter: pos={};", self.pos);
|
2016-01-25 20:45:50 +00:00
|
|
|
self.stop_at(token);
|
2016-09-30 11:47:47 +00:00
|
|
|
if let Some(&c) = self.usage.as_bytes().get(self.pos) {
|
|
|
|
match c {
|
|
|
|
b'-' => self.short_or_long(&mut arg),
|
|
|
|
b'.' => self.multiple(&mut arg),
|
|
|
|
b'\'' => self.help(&mut arg),
|
|
|
|
_ => self.name(&mut arg),
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
2016-05-06 21:35:53 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
2017-02-17 23:27:51 +00:00
|
|
|
debug_assert!(!arg.b.name.is_empty(),
|
2016-05-06 21:35:53 +00:00
|
|
|
format!("No name found for Arg when parsing usage string: {}",
|
|
|
|
self.usage));
|
2017-02-17 23:27:51 +00:00
|
|
|
arg.v.num_vals = match arg.v.val_names {
|
2016-09-30 13:30:31 +00:00
|
|
|
Some(ref v) if v.len() >= 2 => Some(v.len() as u64),
|
|
|
|
_ => None,
|
2016-05-06 21:35:53 +00:00
|
|
|
};
|
2017-02-17 23:27:51 +00:00
|
|
|
debugln!("UsageParser::parse: vals...{:?}", arg.v.val_names);
|
2016-01-25 20:45:50 +00:00
|
|
|
arg
|
|
|
|
}
|
|
|
|
|
|
|
|
fn name(&mut self, arg: &mut Arg<'a, 'a>) {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::name;");
|
2016-09-30 11:47:47 +00:00
|
|
|
if *self.usage.as_bytes().get(self.pos).expect(INTERNAL_ERROR_MSG) == b'<' &&
|
2016-05-06 21:35:53 +00:00
|
|
|
!self.explicit_name_set {
|
|
|
|
arg.setb(ArgSettings::Required);
|
|
|
|
}
|
2016-01-25 20:45:50 +00:00
|
|
|
self.pos += 1;
|
|
|
|
self.stop_at(name_end);
|
|
|
|
let name = &self.usage[self.start..self.pos];
|
2016-03-08 15:39:43 +00:00
|
|
|
if self.prev == UsageToken::Unknown {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::name: setting name...{}", name);
|
2017-02-17 23:27:51 +00:00
|
|
|
arg.b.name = name;
|
|
|
|
if arg.s.long.is_none() && arg.s.short.is_none() {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::name: explicit name set...");
|
2016-03-08 15:39:43 +00:00
|
|
|
self.explicit_name_set = true;
|
|
|
|
self.prev = UsageToken::Name;
|
|
|
|
}
|
|
|
|
} else {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::name: setting val name...{}", name);
|
2017-02-17 23:27:51 +00:00
|
|
|
if let Some(ref mut v) = arg.v.val_names {
|
2016-01-25 20:45:50 +00:00
|
|
|
let len = v.len();
|
|
|
|
v.insert(len, name);
|
|
|
|
} else {
|
|
|
|
let mut v = VecMap::new();
|
|
|
|
v.insert(0, name);
|
2017-02-17 23:27:51 +00:00
|
|
|
arg.v.val_names = Some(v);
|
2016-01-25 20:45:50 +00:00
|
|
|
arg.setb(ArgSettings::TakesValue);
|
|
|
|
}
|
|
|
|
self.prev = UsageToken::ValName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 21:35:53 +00:00
|
|
|
fn stop_at<F>(&mut self, f: F)
|
2016-09-30 11:47:47 +00:00
|
|
|
where F: Fn(u8) -> bool
|
2016-05-06 21:35:53 +00:00
|
|
|
{
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::stop_at;");
|
2016-01-25 20:45:50 +00:00
|
|
|
self.start = self.pos;
|
2016-11-20 19:41:15 +00:00
|
|
|
self.pos += self.usage[self.start..].bytes().take_while(|&b| f(b)).count();
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn short_or_long(&mut self, arg: &mut Arg<'a, 'a>) {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::short_or_long;");
|
2016-01-25 20:45:50 +00:00
|
|
|
self.pos += 1;
|
2016-09-30 11:47:47 +00:00
|
|
|
if *self.usage.as_bytes().get(self.pos).expect(INTERNAL_ERROR_MSG) == b'-' {
|
2016-01-25 20:45:50 +00:00
|
|
|
self.pos += 1;
|
|
|
|
self.long(arg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.short(arg)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn long(&mut self, arg: &mut Arg<'a, 'a>) {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::long;");
|
2016-01-25 20:45:50 +00:00
|
|
|
self.stop_at(long_end);
|
|
|
|
let name = &self.usage[self.start..self.pos];
|
2016-09-30 11:47:47 +00:00
|
|
|
if !self.explicit_name_set {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::long: setting name...{}", name);
|
2017-02-17 23:27:51 +00:00
|
|
|
arg.b.name = name;
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::long: setting long...{}", name);
|
2017-02-17 23:27:51 +00:00
|
|
|
arg.s.long = Some(name);
|
2016-01-25 20:45:50 +00:00
|
|
|
self.prev = UsageToken::Long;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn short(&mut self, arg: &mut Arg<'a, 'a>) {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::short;");
|
2016-09-30 11:47:47 +00:00
|
|
|
let start = &self.usage[self.pos..];
|
|
|
|
let short = start.chars().nth(0).expect(INTERNAL_ERROR_MSG);
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::short: setting short...{}", short);
|
2017-02-17 23:27:51 +00:00
|
|
|
arg.s.short = Some(short);
|
|
|
|
if arg.b.name.is_empty() {
|
2016-09-30 11:47:47 +00:00
|
|
|
// --long takes precedence but doesn't set self.explicit_name_set
|
|
|
|
let name = &start[..short.len_utf8()];
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::short: setting name...{}", name);
|
2017-02-17 23:27:51 +00:00
|
|
|
arg.b.name = name;
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
|
|
|
self.prev = UsageToken::Short;
|
|
|
|
}
|
|
|
|
|
2016-09-30 11:47:47 +00:00
|
|
|
// "something..."
|
2016-01-25 20:45:50 +00:00
|
|
|
fn multiple(&mut self, arg: &mut Arg) {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::multiple;");
|
2016-01-25 20:45:50 +00:00
|
|
|
let mut dot_counter = 1;
|
|
|
|
let start = self.pos;
|
2016-09-30 11:47:47 +00:00
|
|
|
let mut bytes = self.usage[start..].bytes();
|
|
|
|
while bytes.next() == Some(b'.') {
|
|
|
|
dot_counter += 1;
|
|
|
|
self.pos += 1;
|
|
|
|
if dot_counter == 3 {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::multiple: setting multiple");
|
2016-09-30 11:47:47 +00:00
|
|
|
arg.setb(ArgSettings::Multiple);
|
2017-02-17 23:27:51 +00:00
|
|
|
if arg.is_set(ArgSettings::TakesValue) {
|
2016-09-30 11:47:47 +00:00
|
|
|
arg.setb(ArgSettings::UseValueDelimiter);
|
|
|
|
arg.unsetb(ArgSettings::ValueDelimiterNotSet);
|
2017-02-17 23:27:51 +00:00
|
|
|
if arg.v.val_delim.is_none() {
|
|
|
|
arg.v.val_delim = Some(',');
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
2016-05-06 21:35:53 +00:00
|
|
|
}
|
2016-09-30 11:47:47 +00:00
|
|
|
self.prev = UsageToken::Multiple;
|
|
|
|
self.pos += 1;
|
|
|
|
break;
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn help(&mut self, arg: &mut Arg<'a, 'a>) {
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::help;");
|
2016-01-31 12:05:49 +00:00
|
|
|
self.stop_at(help_start);
|
2016-05-06 21:35:53 +00:00
|
|
|
self.start = self.pos + 1;
|
|
|
|
self.pos = self.usage.len() - 1;
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::help: setting help...{}", &self.usage[self.start..self.pos]);
|
2017-02-17 23:27:51 +00:00
|
|
|
arg.b.help = Some(&self.usage[self.start..self.pos]);
|
2016-01-25 20:45:50 +00:00
|
|
|
self.pos += 1; // Move to next byte to keep from thinking ending ' is a start
|
|
|
|
self.prev = UsageToken::Help;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-31 12:05:49 +00:00
|
|
|
#[inline]
|
2016-11-20 19:41:15 +00:00
|
|
|
fn name_end(b: u8) -> bool { b != b']' && b != b'>' }
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
#[inline]
|
2016-11-20 19:41:15 +00:00
|
|
|
fn token(b: u8) -> bool { b != b'\'' && b != b'.' && b != b'<' && b != b'[' && b != b'-' }
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
#[inline]
|
2016-09-30 11:47:47 +00:00
|
|
|
fn long_end(b: u8) -> bool {
|
2016-09-30 11:48:37 +00:00
|
|
|
b != b'\'' && b != b'.' && b != b'<' && b != b'[' && b != b'=' && b != b' '
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2016-11-20 19:41:15 +00:00
|
|
|
fn help_start(b: u8) -> bool { b != b'\'' }
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use args::Arg;
|
|
|
|
use args::ArgSettings;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_flag_usage() {
|
|
|
|
let a = Arg::from_usage("[flag] -f 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "flag");
|
|
|
|
assert_eq!(a.s.short.unwrap(), 'f');
|
|
|
|
assert!(a.s.long.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(a.v.val_names.is_none());
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let b = Arg::from_usage("[flag] --flag 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "flag");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "flag");
|
|
|
|
assert!(b.s.short.is_none());
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!b.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(a.v.val_names.is_none());
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let b = Arg::from_usage("--flag 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "flag");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "flag");
|
|
|
|
assert!(b.s.short.is_none());
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!b.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.val_names.is_none());
|
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let c = Arg::from_usage("[flag] -f --flag 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "flag");
|
|
|
|
assert_eq!(c.s.short.unwrap(), 'f');
|
|
|
|
assert_eq!(c.s.long.unwrap(), "flag");
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!c.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(c.v.val_names.is_none());
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let d = Arg::from_usage("[flag] -f... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "flag");
|
|
|
|
assert_eq!(d.s.short.unwrap(), 'f');
|
|
|
|
assert!(d.s.long.is_none());
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(d.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.val_names.is_none());
|
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let e = Arg::from_usage("[flag] -f --flag... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(e.b.name, "flag");
|
|
|
|
assert_eq!(e.s.long.unwrap(), "flag");
|
|
|
|
assert_eq!(e.s.short.unwrap(), 'f');
|
|
|
|
assert_eq!(e.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(e.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(e.v.val_names.is_none());
|
|
|
|
assert!(e.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let e = Arg::from_usage("-f --flag... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(e.b.name, "flag");
|
|
|
|
assert_eq!(e.s.long.unwrap(), "flag");
|
|
|
|
assert_eq!(e.s.short.unwrap(), 'f');
|
|
|
|
assert_eq!(e.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(e.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(e.v.val_names.is_none());
|
|
|
|
assert!(e.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let e = Arg::from_usage("--flags");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(e.b.name, "flags");
|
|
|
|
assert_eq!(e.s.long.unwrap(), "flags");
|
|
|
|
assert!(e.v.val_names.is_none());
|
|
|
|
assert!(e.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let e = Arg::from_usage("--flags...");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(e.b.name, "flags");
|
|
|
|
assert_eq!(e.s.long.unwrap(), "flags");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(e.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(e.v.val_names.is_none());
|
|
|
|
assert!(e.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let e = Arg::from_usage("[flags] -f");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(e.b.name, "flags");
|
|
|
|
assert_eq!(e.s.short.unwrap(), 'f');
|
|
|
|
assert!(e.v.val_names.is_none());
|
|
|
|
assert!(e.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let e = Arg::from_usage("[flags] -f...");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(e.b.name, "flags");
|
|
|
|
assert_eq!(e.s.short.unwrap(), 'f');
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(e.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(e.v.val_names.is_none());
|
|
|
|
assert!(e.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let a = Arg::from_usage("-f 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "f");
|
|
|
|
assert_eq!(a.s.short.unwrap(), 'f');
|
|
|
|
assert!(a.s.long.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(a.v.val_names.is_none());
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let e = Arg::from_usage("-f");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(e.b.name, "f");
|
|
|
|
assert_eq!(e.s.short.unwrap(), 'f');
|
|
|
|
assert!(e.v.val_names.is_none());
|
|
|
|
assert!(e.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let e = Arg::from_usage("-f...");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(e.b.name, "f");
|
|
|
|
assert_eq!(e.s.short.unwrap(), 'f');
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(e.is_set(ArgSettings::Multiple));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(e.v.val_names.is_none());
|
|
|
|
assert!(e.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage0() {
|
|
|
|
// Short only
|
|
|
|
let a = Arg::from_usage("[option] -o [opt] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.short.unwrap(), 'o');
|
|
|
|
assert!(a.s.long.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage1() {
|
|
|
|
let b = Arg::from_usage("-o [opt] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "o");
|
|
|
|
assert_eq!(b.s.short.unwrap(), 'o');
|
|
|
|
assert!(b.s.long.is_none());
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage2() {
|
|
|
|
let c = Arg::from_usage("<option> -o <opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.short.unwrap(), 'o');
|
|
|
|
assert!(c.s.long.is_none());
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage3() {
|
|
|
|
let d = Arg::from_usage("-o <opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "o");
|
|
|
|
assert_eq!(d.s.short.unwrap(), 'o');
|
|
|
|
assert!(d.s.long.is_none());
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage4() {
|
|
|
|
let a = Arg::from_usage("[option] -o [opt]... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.short.unwrap(), 'o');
|
|
|
|
assert!(a.s.long.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage5() {
|
|
|
|
let a = Arg::from_usage("[option]... -o [opt] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.short.unwrap(), 'o');
|
|
|
|
assert!(a.s.long.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage6() {
|
|
|
|
let b = Arg::from_usage("-o [opt]... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "o");
|
|
|
|
assert_eq!(b.s.short.unwrap(), 'o');
|
|
|
|
assert!(b.s.long.is_none());
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage7() {
|
|
|
|
let c = Arg::from_usage("<option> -o <opt>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.short.unwrap(), 'o');
|
|
|
|
assert!(c.s.long.is_none());
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage8() {
|
|
|
|
let c = Arg::from_usage("<option>... -o <opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.short.unwrap(), 'o');
|
|
|
|
assert!(c.s.long.is_none());
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage9() {
|
|
|
|
let d = Arg::from_usage("-o <opt>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "o");
|
|
|
|
assert_eq!(d.s.short.unwrap(), 'o');
|
|
|
|
assert!(d.s.long.is_none());
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long1() {
|
|
|
|
let a = Arg::from_usage("[option] --opt [opt] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert!(a.s.short.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long2() {
|
|
|
|
let b = Arg::from_usage("--opt [option] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "opt");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "opt");
|
|
|
|
assert!(b.s.short.is_none());
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long3() {
|
|
|
|
let c = Arg::from_usage("<option> --opt <opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert!(c.s.short.is_none());
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long4() {
|
|
|
|
let d = Arg::from_usage("--opt <option> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert!(d.s.short.is_none());
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long5() {
|
|
|
|
let a = Arg::from_usage("[option] --opt [opt]... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert!(a.s.short.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long6() {
|
|
|
|
let a = Arg::from_usage("[option]... --opt [opt] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert!(a.s.short.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long7() {
|
|
|
|
let b = Arg::from_usage("--opt [option]... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "opt");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "opt");
|
|
|
|
assert!(b.s.short.is_none());
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long8() {
|
|
|
|
let c = Arg::from_usage("<option> --opt <opt>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert!(c.s.short.is_none());
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long9() {
|
|
|
|
let c = Arg::from_usage("<option>... --opt <opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert!(c.s.short.is_none());
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long10() {
|
|
|
|
let d = Arg::from_usage("--opt <option>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert!(d.s.short.is_none());
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals1() {
|
|
|
|
let a = Arg::from_usage("[option] --opt=[opt] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert!(a.s.short.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals2() {
|
|
|
|
let b = Arg::from_usage("--opt=[option] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "opt");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "opt");
|
|
|
|
assert!(b.s.short.is_none());
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals3() {
|
|
|
|
let c = Arg::from_usage("<option> --opt=<opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert!(c.s.short.is_none());
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals4() {
|
|
|
|
let d = Arg::from_usage("--opt=<option> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert!(d.s.short.is_none());
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals5() {
|
|
|
|
let a = Arg::from_usage("[option] --opt=[opt]... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert!(a.s.short.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals6() {
|
|
|
|
let a = Arg::from_usage("[option]... --opt=[opt] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert!(a.s.short.is_none());
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals7() {
|
|
|
|
let b = Arg::from_usage("--opt=[option]... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "opt");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "opt");
|
|
|
|
assert!(b.s.short.is_none());
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals8() {
|
|
|
|
let c = Arg::from_usage("<option> --opt=<opt>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert!(c.s.short.is_none());
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals9() {
|
|
|
|
let c = Arg::from_usage("<option>... --opt=<opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert!(c.s.short.is_none());
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals10() {
|
|
|
|
let d = Arg::from_usage("--opt=<option>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert!(d.s.short.is_none());
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both1() {
|
|
|
|
let a = Arg::from_usage("[option] -o --opt [option] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both2() {
|
|
|
|
let b = Arg::from_usage("-o --opt [option] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "opt");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(b.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both3() {
|
|
|
|
let c = Arg::from_usage("<option> -o --opt <opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(c.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both4() {
|
|
|
|
let d = Arg::from_usage("-o --opt <option> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(d.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both5() {
|
|
|
|
let a = Arg::from_usage("[option]... -o --opt [option] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both6() {
|
|
|
|
let b = Arg::from_usage("-o --opt [option]... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "opt");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(b.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both7() {
|
|
|
|
let c = Arg::from_usage("<option>... -o --opt <opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(c.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both8() {
|
|
|
|
let d = Arg::from_usage("-o --opt <option>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(d.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals1() {
|
|
|
|
let a = Arg::from_usage("[option] -o --opt=[option] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals2() {
|
|
|
|
let b = Arg::from_usage("-o --opt=[option] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "opt");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(b.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals3() {
|
|
|
|
let c = Arg::from_usage("<option> -o --opt=<opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(c.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 12:05:49 +00:00
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals4() {
|
|
|
|
let d = Arg::from_usage("-o --opt=<option> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(d.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 12:05:49 +00:00
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals5() {
|
|
|
|
let a = Arg::from_usage("[option]... -o --opt=[option] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "option");
|
|
|
|
assert_eq!(a.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 12:05:49 +00:00
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals6() {
|
|
|
|
let b = Arg::from_usage("-o --opt=[option]... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "opt");
|
|
|
|
assert_eq!(b.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(b.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals7() {
|
|
|
|
let c = Arg::from_usage("<option>... -o --opt=<opt> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "option");
|
|
|
|
assert_eq!(c.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(c.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(c.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.v.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals8() {
|
|
|
|
let d = Arg::from_usage("-o --opt=<option>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(d.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-11-20 19:41:15 +00:00
|
|
|
[&"option"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals1() {
|
|
|
|
let d = Arg::from_usage("-o <file> <mode> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "o");
|
|
|
|
assert!(d.s.long.is_none());
|
|
|
|
assert_eq!(d.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"file", &"mode"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.num_vals.unwrap(), 2);
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals2() {
|
|
|
|
let d = Arg::from_usage("-o <file> <mode>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "o");
|
|
|
|
assert!(d.s.long.is_none());
|
|
|
|
assert_eq!(d.s.short.unwrap(), 'o');
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"file", &"mode"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.num_vals.unwrap(), 2);
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals3() {
|
|
|
|
let d = Arg::from_usage("--opt <file> <mode>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert!(d.s.short.is_none());
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"file", &"mode"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.num_vals.unwrap(), 2);
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals4() {
|
|
|
|
let d = Arg::from_usage("[myopt] --opt <file> <mode> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "myopt");
|
|
|
|
assert!(d.s.short.is_none());
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-09-30 12:03:53 +00:00
|
|
|
[&"file", &"mode"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.num_vals.unwrap(), 2);
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals5() {
|
|
|
|
let d = Arg::from_usage("--opt <file> <mode> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "opt");
|
|
|
|
assert!(d.s.short.is_none());
|
|
|
|
assert_eq!(d.s.long.unwrap(), "opt");
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.v.num_vals.unwrap(), 2);
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_positional_usage() {
|
|
|
|
let a = Arg::from_usage("[pos] 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "pos");
|
|
|
|
assert_eq!(a.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(a.v.val_names.is_none());
|
|
|
|
assert!(a.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_positional_usage0() {
|
|
|
|
let b = Arg::from_usage("<pos> 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "pos");
|
|
|
|
assert_eq!(b.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.val_names.is_none());
|
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_mult_help() {
|
|
|
|
let c = Arg::from_usage("[pos]... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "pos");
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(!c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(c.v.val_names.is_none());
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_help_lit_single_quote() {
|
|
|
|
let c = Arg::from_usage("[pos]... 'some help\' info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "pos");
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help' info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(!c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(c.v.val_names.is_none());
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_help_double_lit_single_quote() {
|
|
|
|
let c = Arg::from_usage("[pos]... 'some \'help\' info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "pos");
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some 'help' info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(!c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(c.v.val_names.is_none());
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_help_newline() {
|
|
|
|
let c = Arg::from_usage("[pos]... 'some help{n}\
|
|
|
|
info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "pos");
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help{n}info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(!c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(c.v.val_names.is_none());
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_help_newline_lit_sq() {
|
|
|
|
let c = Arg::from_usage("[pos]... 'some help\' stuff{n}\
|
|
|
|
info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "pos");
|
|
|
|
assert_eq!(c.b.help.unwrap(), "some help' stuff{n}info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(!c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(c.v.val_names.is_none());
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_req_mult_help() {
|
|
|
|
let d = Arg::from_usage("<pos>... 'some help info'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(d.b.name, "pos");
|
|
|
|
assert_eq!(d.b.help.unwrap(), "some help info");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(d.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(d.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(d.v.val_names.is_none());
|
|
|
|
assert!(d.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_req() {
|
|
|
|
let b = Arg::from_usage("<pos>");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(b.b.name, "pos");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!b.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(b.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(b.v.val_names.is_none());
|
|
|
|
assert!(b.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_mult() {
|
|
|
|
let c = Arg::from_usage("[pos]...");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(c.b.name, "pos");
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(c.is_set(ArgSettings::Multiple));
|
|
|
|
assert!(!c.is_set(ArgSettings::Required));
|
2017-02-17 23:27:51 +00:00
|
|
|
assert!(c.v.val_names.is_none());
|
|
|
|
assert!(c.v.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
2016-09-30 11:47:47 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nonascii() {
|
|
|
|
let a = Arg::from_usage("<ASCII> 'üñíčöĐ€'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "ASCII");
|
|
|
|
assert_eq!(a.b.help, Some("üñíčöĐ€"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("<üñíčöĐ€> 'ASCII'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "üñíčöĐ€");
|
|
|
|
assert_eq!(a.b.help, Some("ASCII"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("<üñíčöĐ€> 'üñíčöĐ€'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "üñíčöĐ€");
|
|
|
|
assert_eq!(a.b.help, Some("üñíčöĐ€"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("-ø 'ø'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "ø");
|
|
|
|
assert_eq!(a.s.short, Some('ø'));
|
|
|
|
assert_eq!(a.b.help, Some("ø"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("--üñíčöĐ€ 'Nōṫ ASCII'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "üñíčöĐ€");
|
|
|
|
assert_eq!(a.s.long, Some("üñíčöĐ€"));
|
|
|
|
assert_eq!(a.b.help, Some("Nōṫ ASCII"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("[ñämê] --ôpt=[üñíčöĐ€] 'hælp'");
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.name, "ñämê");
|
|
|
|
assert_eq!(a.s.long, Some("ôpt"));
|
|
|
|
assert_eq!(a.v.val_names.unwrap().values().collect::<Vec<_>>(),
|
2016-11-20 19:41:15 +00:00
|
|
|
[&"üñíčöĐ€"]);
|
2017-02-17 23:27:51 +00:00
|
|
|
assert_eq!(a.b.help, Some("hælp"));
|
2016-09-30 11:47:47 +00:00
|
|
|
}
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|