about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2015-12-04 22:02:09 +0100
committerFelix S. Klock II <pnkfelix@pnkfx.org>2015-12-04 22:02:09 +0100
commit5bb1e648cdaacfca330deed10a663606266604ea (patch)
tree65808aae29624708a15488bba5da2cdf19924f69
parent77ed39cfe37a17737e0b2256b1a1689e01c32b26 (diff)
downloadrust-5bb1e648cdaacfca330deed10a663606266604ea.tar.gz
rust-5bb1e648cdaacfca330deed10a663606266604ea.zip
Change internal `getopts` so `--a=b=c` acts like `--a b=c` rather than `--a b`.
This is an adaption of

 https://github.com/rust-lang-nursery/getopts/commit/8ec916b86afce0a2a9100b7327b12b5ffcb2cabb

including its unit test.
-rw-r--r--src/libgetopts/lib.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs
index f7544e3f5ea..228ceb92da6 100644
--- a/src/libgetopts/lib.rs
+++ b/src/libgetopts/lib.rs
@@ -598,7 +598,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
             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 @@ Options:
         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");
+    }
 }