Commit b1d5fcb3 authored by John Rummell's avatar John Rummell Committed by Commit Bot

Note that only the last value of a switch is used by CommandLine.

Also adds a test to verify the behavior.

BUG=957138
TEST=new base_unittest passes

Change-Id: Ida1d0801f457e96dbf1d2ed299966a50aec05442
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1586220
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654698}
parent 542bee1e
......@@ -6,6 +6,7 @@
// Arguments with prefixes ('--', '-', and on Windows, '/') are switches.
// Switches will precede all other arguments without switch prefixes.
// Switches can optionally have values, delimited by '=', e.g., "-switch=value".
// If a switch is specified multiple times, only the last value is used.
// An argument of "--" will terminate switch parsing during initialization,
// interpreting subsequent tokens as non-switch arguments, regardless of prefix.
......
......@@ -461,4 +461,19 @@ TEST(CommandLineTest, RemoveSwitch) {
EXPECT_EQ(value2, cl.GetSwitchValueASCII(switch2));
}
TEST(CommandLineTest, MultipleSameSwitch) {
const CommandLine::CharType* argv[] = {
FILE_PATH_LITERAL("program"),
FILE_PATH_LITERAL("--foo=one"), // --foo first time
FILE_PATH_LITERAL("-baz"),
FILE_PATH_LITERAL("--foo=two") // --foo second time
};
CommandLine cl(size(argv), argv);
EXPECT_TRUE(cl.HasSwitch("foo"));
EXPECT_TRUE(cl.HasSwitch("baz"));
EXPECT_EQ("two", cl.GetSwitchValueASCII("foo"));
}
} // namespace base
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment