mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
set_default_str and set_default_val update (#27)
* set_default_str and set_default_val update * Fixes for style checking
This commit is contained in:
parent
54114d0948
commit
93311928d7
@ -1,6 +1,9 @@
|
||||
## Version 1.2 (in progress)
|
||||
|
||||
|
||||
* `set_default_str` now only sets string, and `set_default_val` will evaluate the default string given [#26](https://github.com/CLIUtils/CLI11/issues/26)
|
||||
* Required positionals now take priority over subcommands [#23](https://github.com/CLIUtils/CLI11/issues/23)
|
||||
* Extra requirements enforced by Travis
|
||||
|
||||
## Version 1.1
|
||||
|
||||
|
@ -261,7 +261,7 @@ class App {
|
||||
if(defaulted) {
|
||||
std::stringstream out;
|
||||
out << variable;
|
||||
opt->set_default_val(out.str());
|
||||
opt->set_default_str(out.str());
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
@ -307,7 +307,7 @@ class App {
|
||||
Option *opt = add_option(name, fun, description, defaulted);
|
||||
opt->set_custom_option(detail::type_name<T>(), -1, true);
|
||||
if(defaulted)
|
||||
opt->set_default_val("[" + detail::join(variable) + "]");
|
||||
opt->set_default_str("[" + detail::join(variable) + "]");
|
||||
return opt;
|
||||
}
|
||||
|
||||
@ -410,7 +410,7 @@ class App {
|
||||
if(defaulted) {
|
||||
std::stringstream out;
|
||||
out << member;
|
||||
opt->set_default_val(out.str());
|
||||
opt->set_default_str(out.str());
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
@ -473,7 +473,7 @@ class App {
|
||||
typeval += " in {" + detail::join(options) + "}";
|
||||
opt->set_custom_option(typeval);
|
||||
if(defaulted) {
|
||||
opt->set_default_val(member);
|
||||
opt->set_default_str(member);
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
@ -500,7 +500,7 @@ class App {
|
||||
if(defaulted) {
|
||||
std::stringstream out;
|
||||
out << variable;
|
||||
opt->set_default_val(out.str());
|
||||
opt->set_default_str(out.str());
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
|
@ -431,7 +431,16 @@ class Option {
|
||||
}
|
||||
|
||||
/// Set the default value string representation
|
||||
void set_default_val(std::string val) { defaultval_ = val; }
|
||||
void set_default_str(std::string val) { defaultval_ = val; }
|
||||
|
||||
/// Set the default value string representation and evaluate
|
||||
void set_default_val(std::string val) {
|
||||
set_default_str(val);
|
||||
auto old_results = results_;
|
||||
results_ = {val};
|
||||
run_callback();
|
||||
results_ = std::move(old_results);
|
||||
}
|
||||
|
||||
/// Set the type name displayed on this option
|
||||
void set_type_name(std::string val) { typeval_ = val; }
|
||||
|
@ -194,16 +194,22 @@ TEST(THelp, ManualSetters) {
|
||||
|
||||
CLI::App app{"My prog"};
|
||||
|
||||
int x;
|
||||
int x = 1;
|
||||
|
||||
CLI::Option *op1 = app.add_option("--op", x);
|
||||
op1->set_default_val("12");
|
||||
op1->set_default_str("12");
|
||||
op1->set_type_name("BIGGLES");
|
||||
EXPECT_EQ(x, 1);
|
||||
|
||||
std::string help = app.help();
|
||||
|
||||
EXPECT_THAT(help, HasSubstr("=12"));
|
||||
EXPECT_THAT(help, HasSubstr("BIGGLES"));
|
||||
|
||||
op1->set_default_val("14");
|
||||
EXPECT_EQ(x, 14);
|
||||
help = app.help();
|
||||
EXPECT_THAT(help, HasSubstr("=14"));
|
||||
}
|
||||
|
||||
TEST(THelp, Subcom) {
|
||||
|
@ -23,7 +23,7 @@ add_option(CLI::App &app, std::string name, cx &variable, std::string descriptio
|
||||
if(defaulted) {
|
||||
std::stringstream out;
|
||||
out << variable;
|
||||
opt->set_default_val(out.str());
|
||||
opt->set_default_str(out.str());
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user