From 66fedad044403a7df9ca6880d540642d3af9ceca Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Fri, 11 Jan 2019 13:23:28 +0100 Subject: [PATCH] Adding check for Windows definition order match from #187 --- include/CLI/App.hpp | 6 +++--- tests/AppTest.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index c081fbb4..9de29bb6 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -261,7 +261,7 @@ class App { return this; } - /// Ignore case. Subcommand inherit value. + /// Ignore case. Subcommands inherit value. App *ignore_case(bool value = true) { ignore_case_ = value; if(parent_ != nullptr) { @@ -273,13 +273,13 @@ class App { return this; } - /// Ignore case. Subcommand inherit value. + /// Allow windows style options, such as `/opt`. First matching short or long name used. Subcommands inherit value. App *allow_windows_style_options(bool value = true) { allow_windows_style_options_ = value; return this; } - /// Ignore underscore. Subcommand inherit value. + /// Ignore underscore. Subcommands inherit value. App *ignore_underscore(bool value = true) { ignore_underscore_ = value; if(parent_ != nullptr) { diff --git a/tests/AppTest.cpp b/tests/AppTest.cpp index a149509f..909af7d7 100644 --- a/tests/AppTest.cpp +++ b/tests/AppTest.cpp @@ -19,6 +19,28 @@ TEST_F(TApp, OneFlagShortWindows) { EXPECT_EQ((size_t)1, app.count("--count")); } +TEST_F(TApp, WindowsLongShortMix1) { + app.allow_windows_style_options(); + + auto a = app.add_flag("-c"); + auto b = app.add_flag("--c"); + args = {"/c"}; + run(); + EXPECT_EQ((size_t)1, a->count()); + EXPECT_EQ((size_t)0, b->count()); +} + +TEST_F(TApp, WindowsLongShortMix2) { + app.allow_windows_style_options(); + + auto a = app.add_flag("--c"); + auto b = app.add_flag("-c"); + args = {"/c"}; + run(); + EXPECT_EQ((size_t)1, a->count()); + EXPECT_EQ((size_t)0, b->count()); +} + TEST_F(TApp, CountNonExist) { app.add_flag("-c,--count"); args = {"-c"};