Commit 92a3cacd597fdb6a873a33ed1dba769630190494
Committed by
Henry Schreiner
1 parent
a133e9cc
Dropping hidden keyword, just use empty string
Showing
3 changed files
with
10 additions
and
9 deletions
README.md
| @@ -153,7 +153,7 @@ The add commands return a pointer to an internally stored `Option`. If you set t | @@ -153,7 +153,7 @@ The add commands return a pointer to an internally stored `Option`. If you set t | ||
| 153 | * `->requires(opt)`: This option requires another option to also be present, opt is an `Option` pointer. | 153 | * `->requires(opt)`: This option requires another option to also be present, opt is an `Option` pointer. |
| 154 | * `->excludes(opt)`: This option cannot be given with `opt` present, opt is an `Option` pointer. | 154 | * `->excludes(opt)`: This option cannot be given with `opt` present, opt is an `Option` pointer. |
| 155 | * `->envname(name)`: Gets the value from the environment if present and not passed on the command line. | 155 | * `->envname(name)`: Gets the value from the environment if present and not passed on the command line. |
| 156 | -* `->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. | 156 | +* `->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). |
| 157 | * `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments). | 157 | * `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments). |
| 158 | * `->take_last()`: Only take the last option/flag given on the command line, automatically true for bool flags | 158 | * `->take_last()`: Only take the last option/flag given on the command line, automatically true for bool flags |
| 159 | * `->check(CLI::ExistingFile)`: Requires that the file exists if given. | 159 | * `->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 | @@ -211,6 +211,7 @@ There are several options that are supported on the main app and subcommands. Th | ||
| 211 | * `.allow_extras()`: Do not throw an error if extra arguments are left over | 211 | * `.allow_extras()`: Do not throw an error if extra arguments are left over |
| 212 | * `.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. | 212 | * `.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. |
| 213 | * `.set_footer(message)`: Set text to appear at the bottom of the help string. | 213 | * `.set_footer(message)`: Set text to appear at the bottom of the help string. |
| 214 | +* `.group(name)`: Set a group name, defaults to `"Subcommands"`. Setting `""` will be hide the subcommand. | ||
| 214 | 215 | ||
| 215 | > Note: if you have a fixed number of required positional options, that will match before subcommand names. | 216 | > Note: if you have a fixed number of required positional options, that will match before subcommand names. |
| 216 | 217 |
include/CLI/App.hpp
| @@ -850,7 +850,7 @@ class App { | @@ -850,7 +850,7 @@ class App { | ||
| 850 | for(const Option_p &opt : options_) | 850 | for(const Option_p &opt : options_) |
| 851 | if(opt->get_positional()) { | 851 | if(opt->get_positional()) { |
| 852 | // A hidden positional should still show up in the usage statement | 852 | // A hidden positional should still show up in the usage statement |
| 853 | - // if(detail::to_lower(opt->get_group()) == "hidden") | 853 | + // if(detail::to_lower(opt->get_group()).empty()) |
| 854 | // continue; | 854 | // continue; |
| 855 | out << " " << opt->help_positional(); | 855 | out << " " << opt->help_positional(); |
| 856 | if(opt->_has_help_positional()) | 856 | if(opt->_has_help_positional()) |
| @@ -870,8 +870,8 @@ class App { | @@ -870,8 +870,8 @@ class App { | ||
| 870 | if(pos) { | 870 | if(pos) { |
| 871 | out << std::endl << "Positionals:" << std::endl; | 871 | out << std::endl << "Positionals:" << std::endl; |
| 872 | for(const Option_p &opt : options_) { | 872 | for(const Option_p &opt : options_) { |
| 873 | - if(detail::to_lower(opt->get_group()) == "hidden") | ||
| 874 | - continue; | 873 | + if(detail::to_lower(opt->get_group()).empty()) |
| 874 | + continue; // Hidden | ||
| 875 | if(opt->_has_help_positional()) | 875 | if(opt->_has_help_positional()) |
| 876 | detail::format_help(out, opt->help_pname(), opt->get_description(), wid); | 876 | detail::format_help(out, opt->help_pname(), opt->get_description(), wid); |
| 877 | } | 877 | } |
| @@ -880,8 +880,8 @@ class App { | @@ -880,8 +880,8 @@ class App { | ||
| 880 | // Options | 880 | // Options |
| 881 | if(npos) { | 881 | if(npos) { |
| 882 | for(const std::string &group : groups) { | 882 | for(const std::string &group : groups) { |
| 883 | - if(detail::to_lower(group) == "hidden") | ||
| 884 | - continue; | 883 | + if(detail::to_lower(group).empty()) |
| 884 | + continue; // Hidden | ||
| 885 | out << std::endl << group << ":" << std::endl; | 885 | out << std::endl << group << ":" << std::endl; |
| 886 | for(const Option_p &opt : options_) { | 886 | for(const Option_p &opt : options_) { |
| 887 | if(opt->nonpositional() && opt->get_group() == group) | 887 | if(opt->nonpositional() && opt->get_group() == group) |
| @@ -896,7 +896,7 @@ class App { | @@ -896,7 +896,7 @@ class App { | ||
| 896 | for(const App_p &com : subcommands_) { | 896 | for(const App_p &com : subcommands_) { |
| 897 | const std::string &group_key = detail::to_lower(com->get_group()); | 897 | const std::string &group_key = detail::to_lower(com->get_group()); |
| 898 | if(group_key.empty() || subcmd_groups_seen.count(group_key) != 0) | 898 | if(group_key.empty() || subcmd_groups_seen.count(group_key) != 0) |
| 899 | - continue; | 899 | + continue; // Hidden or not in a group |
| 900 | 900 | ||
| 901 | subcmd_groups_seen.insert(group_key); | 901 | subcmd_groups_seen.insert(group_key); |
| 902 | out << std::endl << com->get_group() << ":" << std::endl; | 902 | out << std::endl << com->get_group() << ":" << std::endl; |
tests/HelpTest.cpp
| @@ -56,9 +56,9 @@ TEST(THelp, Hidden) { | @@ -56,9 +56,9 @@ TEST(THelp, Hidden) { | ||
| 56 | CLI::App app{"My prog"}; | 56 | CLI::App app{"My prog"}; |
| 57 | 57 | ||
| 58 | std::string x; | 58 | std::string x; |
| 59 | - app.add_option("something", x, "My option here")->group("Hidden"); | 59 | + app.add_option("something", x, "My option here")->group(""); |
| 60 | std::string y; | 60 | std::string y; |
| 61 | - app.add_option("--another", y)->group("Hidden"); | 61 | + app.add_option("--another", y)->group(""); |
| 62 | 62 | ||
| 63 | std::string help = app.help(); | 63 | std::string help = app.help(); |
| 64 | 64 |