Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/CLI/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description,
std::vector<std::string> 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) {
Expand Down
21 changes: 21 additions & 0 deletions tests/ConfigFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down