summary refs log tree commit diff
path: root/src/argument.rs
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@chromium.org>2019-12-18 17:52:51 -0800
committerCommit Bot <commit-bot@chromium.org>2019-12-22 10:55:05 +0000
commite2e6cd8fe6861d8e42a1b57d099c25265acf5c5f (patch)
tree40cda79264aa190b8640830cd29b0135767a0912 /src/argument.rs
parent9daf7907a36f356fe5c6677e67728b2aa6478fd8 (diff)
downloadcrosvm-e2e6cd8fe6861d8e42a1b57d099c25265acf5c5f.tar
crosvm-e2e6cd8fe6861d8e42a1b57d099c25265acf5c5f.tar.gz
crosvm-e2e6cd8fe6861d8e42a1b57d099c25265acf5c5f.tar.bz2
crosvm-e2e6cd8fe6861d8e42a1b57d099c25265acf5c5f.tar.lz
crosvm-e2e6cd8fe6861d8e42a1b57d099c25265acf5c5f.tar.xz
crosvm-e2e6cd8fe6861d8e42a1b57d099c25265acf5c5f.tar.zst
crosvm-e2e6cd8fe6861d8e42a1b57d099c25265acf5c5f.zip
Fix parsing arguments that require a value at the end of command line
We may be in state of waiting for the value for the parameter, and run
out of the parameters. In this case we should try to parse the parameter
as if it does not have a value and see if that succeeds.

This makes sure that

	crosvm run ... --plugin-mount

fails with error that --plugin-mount option needs a value instead of
succeeding.

BUG=None
TEST=cargo test

Change-Id: I9f3f1f3c7e6e2ca88efed1eeea5a52dd4aae70ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1975097
Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: Dmitry Torokhov <dtor@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
Diffstat (limited to 'src/argument.rs')
-rw-r--r--src/argument.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/argument.rs b/src/argument.rs
index 2d32083..f59d503 100644
--- a/src/argument.rs
+++ b/src/argument.rs
@@ -313,7 +313,14 @@ where
             }
         }
     }
-    Ok(())
+
+    // If we ran out of arguments while parsing the last parameter, which may be either a
+    // value parameter or a flag, try to parse it as a flag. This will produce "missing value"
+    // error if the parameter is in fact a value parameter, which is the desired outcome.
+    match s {
+        State::Value { name } => f(&name, None),
+        _ => Ok(()),
+    }
 }
 
 /// Parses the given `args` against the list of know arguments `arg_list` and calls `f` with each
@@ -473,6 +480,16 @@ mod tests {
             },
         );
         assert!(match_res.is_ok());
+        let not_match_res = set_arguments(
+            ["-c", "5", "--cpus"].iter(),
+            &arguments[..],
+            |name, value| {
+                assert_eq!(name, "cpus");
+                assert_eq!(value, Some("5"));
+                Ok(())
+            },
+        );
+        assert!(not_match_res.is_err());
     }
 
     #[test]