diff --git a/README.md b/README.md index 9affd9e8..5cd1a535 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ The add commands return a pointer to an internally stored `Option`. If you set t * `->requires(opt)`: This option requires another option to also be present, opt is an `Option` pointer. * `->excludes(opt)`: This option cannot be given with `opt` present, opt is an `Option` pointer. * `->envname(name)`: Gets the value from the environment if present and not passed on the command line. -* `->group(name)`: The help group to put the option in. No effect for positional options. Defaults to `"Options"`. `"Hidden"` will not show up in the help print. +* `->group(name)`: The help group to put the option in. No effect for positional options. Defaults to `"Options"`. `""` will not show up in the help print (hidden). * `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments). * `->take_last()`: Only take the last option/flag given on the command line, automatically true for bool flags * `->check(CLI::ExistingFile)`: Requires that the file exists if given. @@ -211,6 +211,7 @@ There are several options that are supported on the main app and subcommands. Th * `.allow_extras()`: Do not throw an error if extra arguments are left over * `.prefix_command()`: Like `allow_extras`, but stop immediately on the first unrecognised item. It is ideal for allowing your app or subcommand to be a "prefix" to calling another app. * `.set_footer(message)`: Set text to appear at the bottom of the help string. +* `.group(name)`: Set a group name, defaults to `"Subcommands"`. Setting `""` will be hide the subcommand. > Note: if you have a fixed number of required positional options, that will match before subcommand names. diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index e139e2e5..762a45b0 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -850,7 +850,7 @@ class App { for(const Option_p &opt : options_) if(opt->get_positional()) { // A hidden positional should still show up in the usage statement - // if(detail::to_lower(opt->get_group()) == "hidden") + // if(detail::to_lower(opt->get_group()).empty()) // continue; out << " " << opt->help_positional(); if(opt->_has_help_positional()) @@ -870,8 +870,8 @@ class App { if(pos) { out << std::endl << "Positionals:" << std::endl; for(const Option_p &opt : options_) { - if(detail::to_lower(opt->get_group()) == "hidden") - continue; + if(detail::to_lower(opt->get_group()).empty()) + continue; // Hidden if(opt->_has_help_positional()) detail::format_help(out, opt->help_pname(), opt->get_description(), wid); } @@ -880,8 +880,8 @@ class App { // Options if(npos) { for(const std::string &group : groups) { - if(detail::to_lower(group) == "hidden") - continue; + if(detail::to_lower(group).empty()) + continue; // Hidden out << std::endl << group << ":" << std::endl; for(const Option_p &opt : options_) { if(opt->nonpositional() && opt->get_group() == group) @@ -896,7 +896,7 @@ class App { for(const App_p &com : subcommands_) { const std::string &group_key = detail::to_lower(com->get_group()); if(group_key.empty() || subcmd_groups_seen.count(group_key) != 0) - continue; + continue; // Hidden or not in a group subcmd_groups_seen.insert(group_key); out << std::endl << com->get_group() << ":" << std::endl; diff --git a/tests/HelpTest.cpp b/tests/HelpTest.cpp index 76742c9f..b89cbc45 100644 --- a/tests/HelpTest.cpp +++ b/tests/HelpTest.cpp @@ -56,9 +56,9 @@ TEST(THelp, Hidden) { CLI::App app{"My prog"}; std::string x; - app.add_option("something", x, "My option here")->group("Hidden"); + app.add_option("something", x, "My option here")->group(""); std::string y; - app.add_option("--another", y)->group("Hidden"); + app.add_option("--another", y)->group(""); std::string help = app.help();