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;
|
2017-09-19 11:28:58 +00:00
|
|
|
use map::VecMap;
|
2016-01-25 20:45:50 +00:00
|
|
|
|
|
|
|
#[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();
|
2018-01-25 21:22:49 +00:00
|
|
|
arg.disp_ord = 999;
|
|
|
|
arg.unified_ord = 999;
|
2016-01-25 20:45:50 +00:00
|
|
|
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
|
|
|
}
|
2018-01-22 23:19:53 +00:00
|
|
|
arg.num_vals = match arg.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
|
|
|
};
|
2018-01-31 02:57:29 +00:00
|
|
|
if !arg.has_switch() && arg.is_set(ArgSettings::MultipleOccurrences) {
|
|
|
|
// We had a positional and need to set mult vals too
|
|
|
|
arg.setb(ArgSettings::MultipleValues);
|
|
|
|
}
|
2018-01-22 23:19:53 +00:00
|
|
|
debugln!("UsageParser::parse: vals...{:?}", arg.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;");
|
2017-11-28 12:30:06 +00:00
|
|
|
if *self.usage
|
|
|
|
.as_bytes()
|
|
|
|
.get(self.pos)
|
|
|
|
.expect(INTERNAL_ERROR_MSG) == b'<' && !self.explicit_name_set
|
|
|
|
{
|
2016-05-06 21:35:53 +00:00
|
|
|
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);
|
2018-01-22 23:19:53 +00:00
|
|
|
arg.name = name;
|
|
|
|
if arg.long.is_none() && arg.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);
|
2018-01-22 23:19:53 +00:00
|
|
|
if let Some(ref mut v) = arg.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);
|
2018-01-22 23:19:53 +00:00
|
|
|
arg.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)
|
2017-11-28 12:30:06 +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;
|
2017-11-28 12:30:06 +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;
|
2017-11-28 12:30:06 +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);
|
2018-01-22 23:19:53 +00:00
|
|
|
arg.name = name;
|
2016-01-25 20:45:50 +00:00
|
|
|
}
|
2016-12-29 19:07:04 +00:00
|
|
|
debugln!("UsageParser::long: setting long...{}", name);
|
2018-01-22 23:19:53 +00:00
|
|
|
arg.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);
|
2018-01-22 23:19:53 +00:00
|
|
|
arg.short = Some(short);
|
|
|
|
if arg.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);
|
2018-01-22 23:19:53 +00:00
|
|
|
arg.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");
|
2017-02-17 23:27:51 +00:00
|
|
|
if arg.is_set(ArgSettings::TakesValue) {
|
2018-01-31 02:57:29 +00:00
|
|
|
arg.setb(ArgSettings::MultipleValues);
|
2016-05-06 21:35:53 +00:00
|
|
|
}
|
2018-01-31 02:57:29 +00:00
|
|
|
arg.setb(ArgSettings::MultipleOccurrences);
|
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;
|
2017-11-28 12:30:06 +00:00
|
|
|
debugln!(
|
|
|
|
"UsageParser::help: setting help...{}",
|
|
|
|
&self.usage[self.start..self.pos]
|
|
|
|
);
|
2018-01-22 23:19:53 +00:00
|
|
|
arg.help = Some(&self.usage[self.start..self.pos]);
|
2017-11-28 12:30:06 +00:00
|
|
|
self.pos += 1; // Move to next byte to keep from thinking ending ' is a start
|
2016-01-25 20:45:50 +00:00
|
|
|
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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "flag");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
|
|
|
|
|
|
|
let a = Arg::from_usage("[flag] --flag 'some help info'");
|
|
|
|
assert_eq!(a.name, "flag");
|
|
|
|
assert_eq!(a.long.unwrap(), "flag");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
|
|
|
|
|
|
|
let a = Arg::from_usage("--flag 'some help info'");
|
|
|
|
assert_eq!(a.name, "flag");
|
|
|
|
assert_eq!(a.long.unwrap(), "flag");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
|
|
|
|
|
|
|
let a = Arg::from_usage("[flag] -f --flag 'some help info'");
|
|
|
|
assert_eq!(a.name, "flag");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert_eq!(a.long.unwrap(), "flag");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("[flag] -f... 'some help info'");
|
|
|
|
assert_eq!(a.name, "flag");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("[flag] -f --flag... 'some help info'");
|
|
|
|
assert_eq!(a.name, "flag");
|
|
|
|
assert_eq!(a.long.unwrap(), "flag");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
|
|
|
|
|
|
|
let a = Arg::from_usage("-f --flag... 'some help info'");
|
|
|
|
assert_eq!(a.name, "flag");
|
|
|
|
assert_eq!(a.long.unwrap(), "flag");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
|
|
|
|
|
|
|
let a = Arg::from_usage("--flags");
|
|
|
|
assert_eq!(a.name, "flags");
|
|
|
|
assert_eq!(a.long.unwrap(), "flags");
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
|
|
|
|
|
|
|
let a = Arg::from_usage("--flags...");
|
|
|
|
assert_eq!(a.name, "flags");
|
|
|
|
assert_eq!(a.long.unwrap(), "flags");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
|
|
|
|
|
|
|
let a = Arg::from_usage("[flags] -f");
|
|
|
|
assert_eq!(a.name, "flags");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
|
|
|
|
|
|
|
let a = Arg::from_usage("[flags] -f...");
|
|
|
|
assert_eq!(a.name, "flags");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
|
|
|
let a = Arg::from_usage("-f 'some help info'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "f");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-f");
|
|
|
|
assert_eq!(a.name, "f");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-f...");
|
|
|
|
assert_eq!(a.name, "f");
|
|
|
|
assert_eq!(a.short.unwrap(), 'f');
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleValues));
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage1() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o [opt] 'some help info'");
|
|
|
|
assert_eq!(a.name, "o");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage2() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option> -o <opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage3() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o <opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "o");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleValues));
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage6() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o [opt]... 'some help info'");
|
|
|
|
assert_eq!(a.name, "o");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage7() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option> -o <opt>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage8() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option>... -o <opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage9() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o <opt>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "o");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleValues));
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long2() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt [option] 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long3() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option> --opt <opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long4() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt <option> 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(!a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleValues));
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long7() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt [option]... 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long8() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option> --opt <opt>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleValues));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long9() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option>... --opt <opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long10() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt <option>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals2() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt=[option] 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals3() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option> --opt=<opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals4() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt=<option> 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-25 04:05:05 +00:00
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals7() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt=[option]... 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals8() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option> --opt=<opt>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals9() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option>... --opt=<opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_long_equals10() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt=<option>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-22 23:19:53 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both2() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o --opt [option] 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both3() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option> -o --opt <opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both4() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o --opt <option> 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-22 23:19:53 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both6() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o --opt [option]... 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both7() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option>... -o --opt <opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both8() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o --opt <option>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-22 23:19:53 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals2() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o --opt=[option] 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals3() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option> -o --opt=<opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.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() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o --opt=<option> 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-22 23:19:53 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.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() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o --opt=[option]... 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.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() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<option>... -o --opt=<opt> 'some help info'");
|
|
|
|
assert_eq!(a.name, "option");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(a.is_set(ArgSettings::MultipleOccurrences));
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.val_names.unwrap().values().collect::<Vec<_>>(), [&"opt"]);
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_usage_both_equals8() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o --opt=<option>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"option"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals1() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o <file> <mode> 'some help info'");
|
|
|
|
assert_eq!(a.name, "o");
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"file", &"mode"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert_eq!(a.num_vals.unwrap(), 2);
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals2() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("-o <file> <mode>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "o");
|
|
|
|
assert!(a.long.is_none());
|
|
|
|
assert_eq!(a.short.unwrap(), 'o');
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"file", &"mode"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert_eq!(a.num_vals.unwrap(), 2);
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals3() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt <file> <mode>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"file", &"mode"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert_eq!(a.num_vals.unwrap(), 2);
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals4() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("[myopt] --opt <file> <mode> 'some help info'");
|
|
|
|
assert_eq!(a.name, "myopt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-31 02:57:29 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"file", &"mode"]
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert_eq!(a.num_vals.unwrap(), 2);
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_option_with_vals5() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("--opt <file> <mode> 'some help info'");
|
|
|
|
assert_eq!(a.name, "opt");
|
|
|
|
assert!(a.short.is_none());
|
|
|
|
assert_eq!(a.long.unwrap(), "opt");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::TakesValue));
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert_eq!(a.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'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
2018-01-31 02:57:29 +00:00
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
2016-01-31 12:05:49 +00:00
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
2018-01-22 23:19:53 +00:00
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_positional_usage0() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<pos> 'some help info'");
|
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_mult_help() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("[pos]... 'some help info'");
|
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_help_lit_single_quote() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("[pos]... 'some help\' info'");
|
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help' info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_help_double_lit_single_quote() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("[pos]... 'some \'help\' info'");
|
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert_eq!(a.help.unwrap(), "some 'help' info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_help_newline() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage(
|
2017-11-28 12:30:06 +00:00
|
|
|
"[pos]... 'some help{n}\
|
|
|
|
info'",
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help{n}info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_help_newline_lit_sq() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage(
|
2017-11-28 12:30:06 +00:00
|
|
|
"[pos]... 'some help\' stuff{n}\
|
|
|
|
info'",
|
|
|
|
);
|
2018-01-31 02:57:29 +00:00
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help' stuff{n}info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_req_mult_help() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<pos>... 'some help info'");
|
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert_eq!(a.help.unwrap(), "some help info");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_req() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("<pos>");
|
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert!(
|
|
|
|
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
|
|
|
|
);
|
|
|
|
assert!(a.is_set(ArgSettings::Required));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.num_vals.is_none());
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pos_mult() {
|
2018-01-31 02:57:29 +00:00
|
|
|
let a = Arg::from_usage("[pos]...");
|
|
|
|
assert_eq!(a.name, "pos");
|
|
|
|
assert!(
|
|
|
|
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
|
|
|
|
);
|
|
|
|
assert!(!a.is_set(ArgSettings::Required));
|
|
|
|
assert!(a.val_names.is_none());
|
|
|
|
assert!(a.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> 'üñíčöĐ€'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "ASCII");
|
|
|
|
assert_eq!(a.help, Some("üñíčöĐ€"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("<üñíčöĐ€> 'ASCII'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "üñíčöĐ€");
|
|
|
|
assert_eq!(a.help, Some("ASCII"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("<üñíčöĐ€> 'üñíčöĐ€'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "üñíčöĐ€");
|
|
|
|
assert_eq!(a.help, Some("üñíčöĐ€"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("-ø 'ø'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "ø");
|
|
|
|
assert_eq!(a.short, Some('ø'));
|
|
|
|
assert_eq!(a.help, Some("ø"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("--üñíčöĐ€ 'Nōṫ ASCII'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "üñíčöĐ€");
|
|
|
|
assert_eq!(a.long, Some("üñíčöĐ€"));
|
|
|
|
assert_eq!(a.help, Some("Nōṫ ASCII"));
|
2016-09-30 11:47:47 +00:00
|
|
|
let a = Arg::from_usage("[ñämê] --ôpt=[üñíčöĐ€] 'hælp'");
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.name, "ñämê");
|
|
|
|
assert_eq!(a.long, Some("ôpt"));
|
2017-11-28 12:30:06 +00:00
|
|
|
assert_eq!(
|
2018-01-22 23:19:53 +00:00
|
|
|
a.val_names.unwrap().values().collect::<Vec<_>>(),
|
2017-11-28 12:30:06 +00:00
|
|
|
[&"üñíčöĐ€"]
|
|
|
|
);
|
2018-01-22 23:19:53 +00:00
|
|
|
assert_eq!(a.help, Some("hælp"));
|
2016-09-30 11:47:47 +00:00
|
|
|
}
|
2016-01-31 12:05:49 +00:00
|
|
|
}
|