mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 04:33:53 +00:00
Adding hidden options
This commit is contained in:
parent
e63898df9f
commit
b59a16ccf2
@ -1,5 +1,6 @@
|
|||||||
## Version 0.5 (in progress)
|
## Version 0.5 (in progress)
|
||||||
|
|
||||||
|
* Allow `Hidden` options.
|
||||||
* Throw `OptionAlreadyAdded` errors for matching subcommands or options, with ignore-case included, tests
|
* Throw `OptionAlreadyAdded` errors for matching subcommands or options, with ignore-case included, tests
|
||||||
* `->ignore_case()` added to subcommands, options, and `add_set_ignore_case`. Subcommands inherit setting from parent App on creation.
|
* `->ignore_case()` added to subcommands, options, and `add_set_ignore_case`. Subcommands inherit setting from parent App on creation.
|
||||||
* Subcommands now can be "chained", that is, left over arguments can now include subcommands that then get parsed. Subcommands are now a list (`get_subcommands`). Added `got_subcommand(App_or_name)` to check for subcommands.
|
* Subcommands now can be "chained", that is, left over arguments can now include subcommands that then get parsed. Subcommands are now a list (`get_subcommands`). Added `got_subcommand(App_or_name)` to check for subcommands.
|
||||||
|
@ -128,7 +128,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.
|
* `->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.
|
* `->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.
|
* `->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"`.
|
* `->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.
|
||||||
* `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments).
|
* `->ignore_case()`: Ignore the case on the command line (also works on subcommands, does not affect arguments).
|
||||||
* `->check(CLI::ExistingFile)`: Requires that the file exists if given.
|
* `->check(CLI::ExistingFile)`: Requires that the file exists if given.
|
||||||
* `->check(CLI::ExistingDirectory)`: Requires that the directory exists.
|
* `->check(CLI::ExistingDirectory)`: Requires that the directory exists.
|
||||||
|
@ -467,6 +467,9 @@ public:
|
|||||||
bool pos=false;
|
bool pos=false;
|
||||||
for(const Option_p &opt : options)
|
for(const Option_p &opt : options)
|
||||||
if(opt->get_positional()) {
|
if(opt->get_positional()) {
|
||||||
|
// A hidden positional should still show up in the usage statement
|
||||||
|
//if(detail::to_lower(opt->get_group()) == "hidden")
|
||||||
|
// continue;
|
||||||
out << " " << opt->help_positional();
|
out << " " << opt->help_positional();
|
||||||
if(opt->has_description())
|
if(opt->has_description())
|
||||||
pos=true;
|
pos=true;
|
||||||
@ -484,9 +487,12 @@ public:
|
|||||||
// Positional descriptions
|
// Positional descriptions
|
||||||
if(pos) {
|
if(pos) {
|
||||||
out << "Positionals:" << std::endl;
|
out << "Positionals:" << std::endl;
|
||||||
for(const Option_p &opt : options)
|
for(const Option_p &opt : options) {
|
||||||
|
if(detail::to_lower(opt->get_group()) == "hidden")
|
||||||
|
continue;
|
||||||
if(opt->get_positional() && opt->has_description())
|
if(opt->get_positional() && opt->has_description())
|
||||||
detail::format_help(out, opt->help_pname(), opt->get_description(), wid);
|
detail::format_help(out, opt->help_pname(), opt->get_description(), wid);
|
||||||
|
}
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -495,6 +501,8 @@ public:
|
|||||||
// Options
|
// Options
|
||||||
if(npos) {
|
if(npos) {
|
||||||
for (const std::string& group : groups) {
|
for (const std::string& group : groups) {
|
||||||
|
if(detail::to_lower(group) == "hidden")
|
||||||
|
continue;
|
||||||
out << group << ":" << std::endl;
|
out << group << ":" << std::endl;
|
||||||
for(const Option_p &opt : options) {
|
for(const Option_p &opt : options) {
|
||||||
if(opt->nonpositional() && opt->get_group() == group)
|
if(opt->nonpositional() && opt->get_group() == group)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using ::testing::HasSubstr;
|
using ::testing::HasSubstr;
|
||||||
|
using ::testing::Not;
|
||||||
|
|
||||||
TEST(THelp, Basic) {
|
TEST(THelp, Basic) {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
@ -37,8 +38,28 @@ TEST(THelp, OptionalPositional) {
|
|||||||
EXPECT_THAT(help, HasSubstr("something TEXT"));
|
EXPECT_THAT(help, HasSubstr("something TEXT"));
|
||||||
EXPECT_THAT(help, HasSubstr("My option here"));
|
EXPECT_THAT(help, HasSubstr("My option here"));
|
||||||
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] [something]"));
|
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] [something]"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(THelp, Hidden) {
|
||||||
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
|
std::string x;
|
||||||
|
app.add_option("something", x, "My option here")
|
||||||
|
->group("Hidden");
|
||||||
|
std::string y;
|
||||||
|
app.add_option("--another", y)
|
||||||
|
->group("Hidden");
|
||||||
|
|
||||||
|
std::string help = app.help();
|
||||||
|
|
||||||
|
EXPECT_THAT(help, HasSubstr("My prog"));
|
||||||
|
EXPECT_THAT(help, HasSubstr("-h,--help"));
|
||||||
|
EXPECT_THAT(help, HasSubstr("Options:"));
|
||||||
|
EXPECT_THAT(help, HasSubstr("[something]"));
|
||||||
|
EXPECT_THAT(help, Not(HasSubstr("something ")));
|
||||||
|
EXPECT_THAT(help, Not(HasSubstr("another")));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(THelp, OptionalPositionalAndOptions) {
|
TEST(THelp, OptionalPositionalAndOptions) {
|
||||||
CLI::App app{"My prog"};
|
CLI::App app{"My prog"};
|
||||||
app.add_flag("-q,--quick");
|
app.add_flag("-q,--quick");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user