Commit a8ef5b8d2fe3932039fa51bcd351cf25001c192a
Committed by
GitHub
1 parent
2fa8cae9
fix: avoid printing description for non configurable subcommand (#604)
Showing
2 changed files
with
22 additions
and
1 deletions
include/CLI/Config.hpp
| ... | ... | @@ -277,7 +277,7 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description, |
| 277 | 277 | std::vector<std::string> groups = app->get_groups(); |
| 278 | 278 | bool defaultUsed = false; |
| 279 | 279 | groups.insert(groups.begin(), std::string("Options")); |
| 280 | - if(write_description) { | |
| 280 | + if(write_description && (app->get_configurable() || app->get_parent() == nullptr || app->get_name().empty())) { | |
| 281 | 281 | out << commentLead << app->get_description() << '\n'; |
| 282 | 282 | } |
| 283 | 283 | for(auto &group : groups) { | ... | ... |
tests/ConfigFileTest.cpp
| ... | ... | @@ -1888,6 +1888,27 @@ TEST_CASE_METHOD(TApp, "TomlOutputSubsubcomConfigurable", "[config]") { |
| 1888 | 1888 | CHECK(std::string::npos == str.find("sub2.newest=true")); |
| 1889 | 1889 | } |
| 1890 | 1890 | |
| 1891 | +TEST_CASE_METHOD(TApp, "TomlOutputSubcomNonConfigurable", "[config]") { | |
| 1892 | + | |
| 1893 | + app.add_flag("--simple"); | |
| 1894 | + auto subcom = app.add_subcommand("other", "other_descriptor")->configurable(); | |
| 1895 | + subcom->add_flag("--newer"); | |
| 1896 | + | |
| 1897 | + auto subcom2 = app.add_subcommand("sub2", "descriptor2"); | |
| 1898 | + subcom2->add_flag("--newest")->configurable(false); | |
| 1899 | + | |
| 1900 | + args = {"--simple", "other", "--newer", "sub2", "--newest"}; | |
| 1901 | + run(); | |
| 1902 | + | |
| 1903 | + std::string str = app.config_to_str(true, true); | |
| 1904 | + CHECK_THAT(str, Contains("other_descriptor")); | |
| 1905 | + CHECK_THAT(str, Contains("simple=true")); | |
| 1906 | + CHECK_THAT(str, Contains("[other]")); | |
| 1907 | + CHECK_THAT(str, Contains("newer=true")); | |
| 1908 | + CHECK_THAT(str, !Contains("newest")); | |
| 1909 | + CHECK_THAT(str, !Contains("descriptor2")); | |
| 1910 | +} | |
| 1911 | + | |
| 1891 | 1912 | TEST_CASE_METHOD(TApp, "TomlOutputSubsubcomConfigurableDeep", "[config]") { |
| 1892 | 1913 | |
| 1893 | 1914 | app.add_flag("--simple"); | ... | ... |