From 057f6b180c750292ed90b9b4e453d61980ed3a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 3 Sep 2017 20:04:48 -0700 Subject: [PATCH] Added -- as command line argument terminator. --- src/commandline.cpp | 2 +- tests/tokenizecmd_test.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/commandline.cpp b/src/commandline.cpp index f6e2654..3d30d30 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -262,7 +262,7 @@ namespace bx const char* CommandLine::find(int32_t _skip, const char _short, const char* _long, int32_t _numParams) const { - for (int32_t ii = 0; ii < m_argc; ++ii) + for (int32_t ii = 0; ii < m_argc && 0 != strCmp(m_argv[ii], "--"); ++ii) { const char* arg = m_argv[ii]; if ('-' == *arg) diff --git a/tests/tokenizecmd_test.cpp b/tests/tokenizecmd_test.cpp index 0e45ab8..7b71cb7 100644 --- a/tests/tokenizecmd_test.cpp +++ b/tests/tokenizecmd_test.cpp @@ -15,12 +15,19 @@ TEST_CASE("commandLine", "") "--long", "--platform", "x", + "--foo", + "--", // it should not parse arguments after argument terminator + "--bar", }; bx::CommandLine cmdLine(BX_COUNTOF(args), args); - REQUIRE(cmdLine.hasArg("long") ); - REQUIRE(cmdLine.hasArg('s') ); + REQUIRE( cmdLine.hasArg("long") ); + REQUIRE( cmdLine.hasArg('s') ); + + // test argument terminator + REQUIRE( cmdLine.hasArg("foo") ); + REQUIRE(!cmdLine.hasArg("bar") ); // non-existing argument REQUIRE(!cmdLine.hasArg('x') );