mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-05 22:53:52 +00:00
parent
9e8bceb91d
commit
ff1ec84e35
@ -417,7 +417,8 @@ Before parsing, you can set the following options:
|
|||||||
option. Options can be removed from the excludes list with
|
option. Options can be removed from the excludes list with
|
||||||
`->remove_excludes(opt)`
|
`->remove_excludes(opt)`
|
||||||
- `->envname(name)`: Gets the value from the environment if present and not
|
- `->envname(name)`: Gets the value from the environment if present and not
|
||||||
passed on the command line.
|
passed on the command line. 🚧 The value must also pass any validators to be
|
||||||
|
used.
|
||||||
- `->group(name)`: The help group to put the option in. No effect for positional
|
- `->group(name)`: The help group to put the option in. No effect for positional
|
||||||
options. Defaults to `"Options"`. Options given an empty string will not show
|
options. Defaults to `"Options"`. Options given an empty string will not show
|
||||||
up in the help print (hidden).
|
up in the help print (hidden).
|
||||||
|
@ -214,7 +214,7 @@ that to add option modifiers. A full listing of the option modifiers:
|
|||||||
| `->type_size(Nmin,Nmax)` | specify that each block of values would consist of between Nmin and Nmax elements |
|
| `->type_size(Nmin,Nmax)` | specify that each block of values would consist of between Nmin and Nmax elements |
|
||||||
| `->needs(opt)` | This option requires another option to also be present, opt is an `Option` pointer or a string with the name of the option. Can be removed with `->remove_needs(opt)` |
|
| `->needs(opt)` | This option requires another option to also be present, opt is an `Option` pointer or a string with the name of the option. Can be removed with `->remove_needs(opt)` |
|
||||||
| `->excludes(opt)` | This option cannot be given with `opt` present, opt is an `Option` pointer or a string with the name of the option. Can be removed with `->remove_excludes(opt)` |
|
| `->excludes(opt)` | This option cannot be given with `opt` present, opt is an `Option` pointer or a string with the name of the option. Can be removed with `->remove_excludes(opt)` |
|
||||||
| `->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 and passes any validators. |
|
||||||
| `->group(name)` | The help group to put the option in. No effect for positional options. Defaults to `"Options"`. Options given an empty string for the group name 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"`. Options given an empty string for the group name will not show up in the help print. |
|
||||||
| `->description(string)` | Set/change the description |
|
| `->description(string)` | Set/change the description |
|
||||||
| `->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). |
|
||||||
|
@ -1080,7 +1080,11 @@ CLI11_INLINE void App::_process_env() {
|
|||||||
if(opt->count() == 0 && !opt->envname_.empty()) {
|
if(opt->count() == 0 && !opt->envname_.empty()) {
|
||||||
std::string ename_string = detail::get_environment_value(opt->envname_);
|
std::string ename_string = detail::get_environment_value(opt->envname_);
|
||||||
if(!ename_string.empty()) {
|
if(!ename_string.empty()) {
|
||||||
opt->add_result(ename_string);
|
std::string result = ename_string;
|
||||||
|
result = opt->_validate(result, 0);
|
||||||
|
if(result.empty()) {
|
||||||
|
opt->add_result(ename_string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
#include "CLI/CLI.hpp"
|
#include "CLI/CLI.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "app_helper.hpp"
|
||||||
|
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
@ -718,6 +720,22 @@ TEST_CASE("THelp: CustomHelp", "[help]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("THelp: HelpSubcommandPriority", "[help]") {
|
||||||
|
CLI::App app{"My prog"};
|
||||||
|
|
||||||
|
app.set_help_flag("-h", "display help and exit");
|
||||||
|
|
||||||
|
auto *sub1 = app.add_subcommand("sub1");
|
||||||
|
std::string someFile = "";
|
||||||
|
|
||||||
|
put_env("SOME_FILE", "NOT_A_FILE");
|
||||||
|
sub1->add_option("-f,--file", someFile)->envname("SOME_FILE")->required()->expected(1)->check(CLI::ExistingFile);
|
||||||
|
|
||||||
|
std::string input{"sub1 -h"};
|
||||||
|
CHECK_THROWS_AS(app.parse(input), CLI::CallForHelp);
|
||||||
|
unset_env("SOME_FILE");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("THelp: NextLineShouldBeAlignmentInMultilineDescription", "[help]") {
|
TEST_CASE("THelp: NextLineShouldBeAlignmentInMultilineDescription", "[help]") {
|
||||||
CLI::App app;
|
CLI::App app;
|
||||||
int i{0};
|
int i{0};
|
||||||
|
@ -2138,6 +2138,6 @@ TEST_CASE_METHOD(TApp, "subcommandEnvironmentName", "[subcom]") {
|
|||||||
CHECK_NOTHROW(run());
|
CHECK_NOTHROW(run());
|
||||||
|
|
||||||
args = {"sub1", "-v", "111"};
|
args = {"sub1", "-v", "111"};
|
||||||
CHECK_THROWS_AS(run(), CLI::ValidationError);
|
CHECK_THROWS_AS(run(), CLI::RequiredError);
|
||||||
unset_env("SOME_FILE");
|
unset_env("SOME_FILE");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user