diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 28373b0e8..f31220c5a 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -2804,9 +2804,14 @@ class App { /// Helper function to run through all possible comparisons of subcommand names to check there is no overlap const std::string &_compare_subcommand_names(const App &subcom, const App &base) const { static const std::string estring; - + if(subcom.disabled_) { + return estring; + } for(auto &subc : base.subcommands_) { if(subc.get() != &subcom) { + if(subc->disabled_) { + continue; + } if(!subcom.get_name().empty()) { if(subc->check_name(subcom.get_name())) { return subcom.get_name(); diff --git a/tests/OptionGroupTest.cpp b/tests/OptionGroupTest.cpp index 0f0eb280c..e109c3bf2 100644 --- a/tests/OptionGroupTest.cpp +++ b/tests/OptionGroupTest.cpp @@ -473,7 +473,7 @@ TEST_F(TApp, ExistingSubcommandMatch) { } sshared->remove_subcommand(s1); - auto s3 = app.add_subcommand("sub3"); + app.add_subcommand("sub3"); // now check that the subsubcommand overlaps try { app.add_subcommand(sshared); @@ -569,10 +569,13 @@ TEST_F(ManyGroups, DisableFirst) { TEST_F(ManyGroups, SameSubcommand) { // only 1 group can be used if remove_required not used remove_required(); - auto sub1 = g1->add_subcommand("sub1"); - auto sub2 = g2->add_subcommand("sub1"); + auto sub1 = g1->add_subcommand("sub1")->disabled(); + auto sub2 = g2->add_subcommand("sub1")->disabled(); auto sub3 = g3->add_subcommand("sub1"); - + // so when the subcommands are disabled they can have the same name + sub1->disabled(false); + sub2->disabled(false); + // if they are reenabled they are not checked for overlap on enabling so they can have the same name args = {"sub1", "sub1", "sub1"}; run(); @@ -580,7 +583,6 @@ TEST_F(ManyGroups, SameSubcommand) { EXPECT_TRUE(*sub1); EXPECT_TRUE(*sub2); EXPECT_TRUE(*sub3); - /// This should be made to work at some point auto subs = app.get_subcommands(); EXPECT_EQ(subs.size(), 3u); EXPECT_EQ(subs[0], sub1); diff --git a/tests/SubcommandTest.cpp b/tests/SubcommandTest.cpp index 2d32c9abd..336dd924b 100644 --- a/tests/SubcommandTest.cpp +++ b/tests/SubcommandTest.cpp @@ -1661,6 +1661,10 @@ TEST_F(TApp, ExistingSubcommandMatch) { } catch(const CLI::OptionAlreadyAdded &oaa) { EXPECT_THAT(oaa.what(), HasSubstr("sub2")); } + // now check that disabled subcommands can be added regardless of name + sshared->name("sub1"); + sshared->disabled(); + EXPECT_NO_THROW(app.add_subcommand(sshared)); } TEST_F(TApp, AliasErrorsInOptionGroup) {