diff --git a/include/CLI/Config.hpp b/include/CLI/Config.hpp index 17b816a1c..490923142 100644 --- a/include/CLI/Config.hpp +++ b/include/CLI/Config.hpp @@ -277,7 +277,7 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description, std::vector groups = app->get_groups(); bool defaultUsed = false; groups.insert(groups.begin(), std::string("Options")); - if(write_description) { + if(write_description && (app->get_configurable() || app->get_parent() == nullptr || app->get_name().empty())) { out << commentLead << app->get_description() << '\n'; } for(auto &group : groups) { diff --git a/tests/ConfigFileTest.cpp b/tests/ConfigFileTest.cpp index afe170544..8c77360e5 100644 --- a/tests/ConfigFileTest.cpp +++ b/tests/ConfigFileTest.cpp @@ -1888,6 +1888,27 @@ TEST_CASE_METHOD(TApp, "TomlOutputSubsubcomConfigurable", "[config]") { CHECK(std::string::npos == str.find("sub2.newest=true")); } +TEST_CASE_METHOD(TApp, "TomlOutputSubcomNonConfigurable", "[config]") { + + app.add_flag("--simple"); + auto subcom = app.add_subcommand("other", "other_descriptor")->configurable(); + subcom->add_flag("--newer"); + + auto subcom2 = app.add_subcommand("sub2", "descriptor2"); + subcom2->add_flag("--newest")->configurable(false); + + args = {"--simple", "other", "--newer", "sub2", "--newest"}; + run(); + + std::string str = app.config_to_str(true, true); + CHECK_THAT(str, Contains("other_descriptor")); + CHECK_THAT(str, Contains("simple=true")); + CHECK_THAT(str, Contains("[other]")); + CHECK_THAT(str, Contains("newer=true")); + CHECK_THAT(str, !Contains("newest")); + CHECK_THAT(str, !Contains("descriptor2")); +} + TEST_CASE_METHOD(TApp, "TomlOutputSubsubcomConfigurableDeep", "[config]") { app.add_flag("--simple");