Commit e3423bb5ad99ec327076fec9e67bbc67a57d2039
1 parent
04268dac
Futher improvement for #12, can change type str
Showing
2 changed files
with
20 additions
and
0 deletions
include/CLI/Option.hpp
| ... | ... | @@ -433,6 +433,10 @@ class Option { |
| 433 | 433 | /// Set the default value string representation |
| 434 | 434 | void set_default_val(std::string val) { defaultval_ = val; } |
| 435 | 435 | |
| 436 | + | |
| 437 | + /// Set the type name displayed on this option | |
| 438 | + void set_type_name(std::string val) {typeval_ = val;} | |
| 439 | + | |
| 436 | 440 | ///@} |
| 437 | 441 | |
| 438 | 442 | protected: | ... | ... |
tests/HelpTest.cpp
| ... | ... | @@ -190,6 +190,22 @@ TEST(THelp, ExcludesPositional) { |
| 190 | 190 | EXPECT_THAT(help, HasSubstr("Excludes: op1")); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | +TEST(THelp, ManualSetters) { | |
| 194 | + | |
| 195 | + CLI::App app{"My prog"}; | |
| 196 | + | |
| 197 | + int x; | |
| 198 | + | |
| 199 | + CLI::Option *op1 = app.add_option("--op", x); | |
| 200 | + op1->set_default_val("12"); | |
| 201 | + op1->set_type_name("BIGGLES"); | |
| 202 | + | |
| 203 | + std::string help = app.help(); | |
| 204 | + | |
| 205 | + EXPECT_THAT(help, HasSubstr("=12")); | |
| 206 | + EXPECT_THAT(help, HasSubstr("BIGGLES")); | |
| 207 | +} | |
| 208 | + | |
| 193 | 209 | TEST(THelp, Subcom) { |
| 194 | 210 | CLI::App app{"My prog"}; |
| 195 | 211 | ... | ... |