1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 12:13:52 +00:00

Adding check for Windows definition order match from #187

This commit is contained in:
Henry Fredrick Schreiner 2019-01-11 13:23:28 +01:00
parent f932b51374
commit 66fedad044
2 changed files with 25 additions and 3 deletions

View File

@ -261,7 +261,7 @@ class App {
return this; return this;
} }
/// Ignore case. Subcommand inherit value. /// Ignore case. Subcommands inherit value.
App *ignore_case(bool value = true) { App *ignore_case(bool value = true) {
ignore_case_ = value; ignore_case_ = value;
if(parent_ != nullptr) { if(parent_ != nullptr) {
@ -273,13 +273,13 @@ class App {
return this; 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) { App *allow_windows_style_options(bool value = true) {
allow_windows_style_options_ = value; allow_windows_style_options_ = value;
return this; return this;
} }
/// Ignore underscore. Subcommand inherit value. /// Ignore underscore. Subcommands inherit value.
App *ignore_underscore(bool value = true) { App *ignore_underscore(bool value = true) {
ignore_underscore_ = value; ignore_underscore_ = value;
if(parent_ != nullptr) { if(parent_ != nullptr) {

View File

@ -19,6 +19,28 @@ TEST_F(TApp, OneFlagShortWindows) {
EXPECT_EQ((size_t)1, app.count("--count")); 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) { TEST_F(TApp, CountNonExist) {
app.add_flag("-c,--count"); app.add_flag("-c,--count");
args = {"-c"}; args = {"-c"};