Commit 8e650c3873d2ec2d957f4c216ba2702cd66d0609
Committed by
Henry Schreiner
1 parent
b519a131
Adding two required functions
Showing
4 changed files
with
32 additions
and
0 deletions
CHANGELOG.md
| 1 | 1 | ## In progress |
| 2 | 2 | |
| 3 | 3 | * Make unlimited positionals vs. unlimited options more intuitive [#102] |
| 4 | +* Add missing getters `get_options` and `get_description` to App [#105] | |
| 4 | 5 | |
| 5 | 6 | [#102]: https://github.com/CLIUtils/CLI11/issues/102 |
| 7 | +[#105]: https://github.com/CLIUtils/CLI11/issues/105 | |
| 6 | 8 | |
| 7 | 9 | |
| 8 | 10 | ## Version 1.5: Optionals | ... | ... |
include/CLI/App.hpp
| ... | ... | @@ -977,6 +977,18 @@ class App { |
| 977 | 977 | /// @name Getters |
| 978 | 978 | ///@{ |
| 979 | 979 | |
| 980 | + /// Get the app or subcommand description | |
| 981 | + std::string get_description() const { return description_; } | |
| 982 | + | |
| 983 | + /// Get the list of options (user facing function, so returns raw pointers) | |
| 984 | + std::vector<Option *> get_options() const { | |
| 985 | + std::vector<Option *> options(options_.size()); | |
| 986 | + std::transform(std::begin(options_), std::end(options_), std::begin(options), [](const Option_p &val) { | |
| 987 | + return val.get(); | |
| 988 | + }); | |
| 989 | + return options; | |
| 990 | + } | |
| 991 | + | |
| 980 | 992 | /// Check the status of ignore_case |
| 981 | 993 | bool get_ignore_case() const { return ignore_case_; } |
| 982 | 994 | ... | ... |
tests/CreationTest.cpp
| ... | ... | @@ -404,3 +404,15 @@ TEST_F(TApp, SubcommandMinMax) { |
| 404 | 404 | EXPECT_EQ(app.get_require_subcommand_min(), (size_t)3); |
| 405 | 405 | EXPECT_EQ(app.get_require_subcommand_max(), (size_t)7); |
| 406 | 406 | } |
| 407 | + | |
| 408 | +TEST_F(TApp, GetOptionList) { | |
| 409 | + int two; | |
| 410 | + auto flag = app.add_flag("--one"); | |
| 411 | + auto opt = app.add_option("--two", two); | |
| 412 | + | |
| 413 | + auto opt_list = app.get_options(); | |
| 414 | + | |
| 415 | + ASSERT_EQ(opt_list.size(), static_cast<size_t>(3)); | |
| 416 | + EXPECT_EQ(opt_list.at(1), flag); | |
| 417 | + EXPECT_EQ(opt_list.at(2), opt); | |
| 418 | +} | ... | ... |
tests/HelpTest.cpp
| ... | ... | @@ -477,3 +477,9 @@ TEST(THelp, CustomDoubleOption) { |
| 477 | 477 | |
| 478 | 478 | EXPECT_THAT(app.help(), Not(HasSubstr("x 2"))); |
| 479 | 479 | } |
| 480 | + | |
| 481 | +TEST(THelp, AccessDescription) { | |
| 482 | + CLI::App app{"My description goes here"}; | |
| 483 | + | |
| 484 | + EXPECT_EQ(app.get_description(), "My description goes here"); | |
| 485 | +} | ... | ... |