mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [2/2] git commit: Introduced '--' to flags parsing.
Date Tue, 13 May 2014 22:11:15 GMT
Introduced '--' to flags parsing.

Review: https://reviews.apache.org/r/21384


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f797836c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f797836c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f797836c

Branch: refs/heads/master
Commit: f797836cf4c5214412c81c11692b039d2b258906
Parents: aa56a2b
Author: Benjamin Hindman <benjamin.hindman@gmail.com>
Authored: Tue May 13 09:34:14 2014 -0700
Committer: Benjamin Hindman <benjamin.hindman@gmail.com>
Committed: Tue May 13 15:10:30 2014 -0700

----------------------------------------------------------------------
 .../stout/include/stout/flags/flags.hpp         |  6 ++++
 .../3rdparty/stout/tests/flags_tests.cpp        | 30 ++++++++++++++++++++
 2 files changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f797836c/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
index 70bd59c..e8415a9 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
@@ -336,6 +336,12 @@ inline Try<Nothing> FlagsBase::load(
   for (int i = 1; i < argc; i++) {
     const std::string arg(strings::trim(argv[i]));
 
+    // Stop parsing flags after '--' is encountered.
+    if (arg == "--") {
+      break;
+    }
+
+    // Skip anything that doesn't look like a flag.
     if (arg.find("--") != 0) {
       continue;
     }

http://git-wip-us.apache.org/repos/asf/mesos/blob/f797836c/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
index 9d48c16..146b277 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
@@ -228,6 +228,36 @@ TEST(FlagsTest, LoadFromCommandLineWithNonFlags)
 }
 
 
+TEST(FlagsTest, LoadFromCommandLineWithDashDash)
+{
+  TestFlags flags;
+
+  int argc = 11;
+  char* argv[argc];
+
+  argv[0] = (char*) "/path/to/program";
+  argv[1] = (char*) "more";
+  argv[2] = (char*) "--name1=billy joel";
+  argv[3] = (char*) "stuff";
+  argv[4] = (char*) "at";
+  argv[5] = (char*) "--name2=43";
+  argv[6] = (char*) "--no-name3";
+  argv[7] = (char*) "--";
+  argv[8] = (char*) "--no-name4";
+  argv[9] = (char*) "--name5";
+  argv[10] = (char*) "the";
+
+  Try<Nothing> load = flags.load("FLAGSTEST_", argc, argv);
+  EXPECT_SOME(load);
+
+  EXPECT_EQ("billy joel", flags.name1);
+  EXPECT_EQ(43, flags.name2);
+  EXPECT_FALSE(flags.name3);
+  ASSERT_NONE(flags.name4);
+  ASSERT_NONE(flags.name5);
+}
+
+
 TEST(FlagsTest, Stringification)
 {
   TestFlags flags;


Mime
View raw message