Change internal getopts
so --a=b=c
acts like --a b=c
rather than --a b
.
This is an adaption of
8ec916b86a
including its unit test.
This commit is contained in:
parent
77ed39cfe3
commit
5bb1e648cd
@ -598,7 +598,7 @@ fn f(_x: usize) -> Vec<Optval> {
|
||||
let mut i_arg = None;
|
||||
if cur.as_bytes()[1] == b'-' {
|
||||
let tail = &cur[2..curlen];
|
||||
let tail_eq: Vec<&str> = tail.split('=').collect();
|
||||
let tail_eq: Vec<&str> = tail.splitn(2, '=').collect();
|
||||
if tail_eq.len() <= 1 {
|
||||
names = vec![Long(tail.to_owned())];
|
||||
} else {
|
||||
@ -1626,4 +1626,18 @@ fn test_short_usage() {
|
||||
debug!("generated: <<{}>>", generated_usage);
|
||||
assert_eq!(generated_usage, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_args_with_equals() {
|
||||
let args = vec!("--one".to_string(), "A=B".to_string(),
|
||||
"--two=C=D".to_string());
|
||||
let opts = vec![optopt("o", "one", "One", "INFO"),
|
||||
optopt("t", "two", "Two", "INFO")];
|
||||
let matches = &match getopts(&args, &opts) {
|
||||
result::Result::Ok(m) => m,
|
||||
result::Result::Err(e) => panic!("{}", e)
|
||||
};
|
||||
assert_eq!(matches.opts_str(&["o".to_string()]).unwrap(), "A=B");
|
||||
assert_eq!(matches.opts_str(&["t".to_string()]).unwrap(), "C=D");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user