Skip to content

Commit 5bb1e64

Browse files
committed
Change internal getopts so --a=b=c acts like --a b=c rather than --a b.
This is an adaption of rust-lang/getopts@8ec916b including its unit test.
1 parent 77ed39c commit 5bb1e64

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/libgetopts/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
598598
let mut i_arg = None;
599599
if cur.as_bytes()[1] == b'-' {
600600
let tail = &cur[2..curlen];
601-
let tail_eq: Vec<&str> = tail.split('=').collect();
601+
let tail_eq: Vec<&str> = tail.splitn(2, '=').collect();
602602
if tail_eq.len() <= 1 {
603603
names = vec![Long(tail.to_owned())];
604604
} else {
@@ -1626,4 +1626,18 @@ Options:
16261626
debug!("generated: <<{}>>", generated_usage);
16271627
assert_eq!(generated_usage, expected);
16281628
}
1629+
1630+
#[test]
1631+
fn test_args_with_equals() {
1632+
let args = vec!("--one".to_string(), "A=B".to_string(),
1633+
"--two=C=D".to_string());
1634+
let opts = vec![optopt("o", "one", "One", "INFO"),
1635+
optopt("t", "two", "Two", "INFO")];
1636+
let matches = &match getopts(&args, &opts) {
1637+
result::Result::Ok(m) => m,
1638+
result::Result::Err(e) => panic!("{}", e)
1639+
};
1640+
assert_eq!(matches.opts_str(&["o".to_string()]).unwrap(), "A=B");
1641+
assert_eq!(matches.opts_str(&["t".to_string()]).unwrap(), "C=D");
1642+
}
16291643
}

0 commit comments

Comments
 (0)