mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
Adding two required functions
This commit is contained in:
parent
b519a13119
commit
8e650c3873
@ -1,8 +1,10 @@
|
||||
## In progress
|
||||
|
||||
* Make unlimited positionals vs. unlimited options more intuitive [#102]
|
||||
* Add missing getters `get_options` and `get_description` to App [#105]
|
||||
|
||||
[#102]: https://github.com/CLIUtils/CLI11/issues/102
|
||||
[#105]: https://github.com/CLIUtils/CLI11/issues/105
|
||||
|
||||
|
||||
## Version 1.5: Optionals
|
||||
|
@ -977,6 +977,18 @@ class App {
|
||||
/// @name Getters
|
||||
///@{
|
||||
|
||||
/// Get the app or subcommand description
|
||||
std::string get_description() const { return description_; }
|
||||
|
||||
/// Get the list of options (user facing function, so returns raw pointers)
|
||||
std::vector<Option *> get_options() const {
|
||||
std::vector<Option *> options(options_.size());
|
||||
std::transform(std::begin(options_), std::end(options_), std::begin(options), [](const Option_p &val) {
|
||||
return val.get();
|
||||
});
|
||||
return options;
|
||||
}
|
||||
|
||||
/// Check the status of ignore_case
|
||||
bool get_ignore_case() const { return ignore_case_; }
|
||||
|
||||
|
@ -404,3 +404,15 @@ TEST_F(TApp, SubcommandMinMax) {
|
||||
EXPECT_EQ(app.get_require_subcommand_min(), (size_t)3);
|
||||
EXPECT_EQ(app.get_require_subcommand_max(), (size_t)7);
|
||||
}
|
||||
|
||||
TEST_F(TApp, GetOptionList) {
|
||||
int two;
|
||||
auto flag = app.add_flag("--one");
|
||||
auto opt = app.add_option("--two", two);
|
||||
|
||||
auto opt_list = app.get_options();
|
||||
|
||||
ASSERT_EQ(opt_list.size(), static_cast<size_t>(3));
|
||||
EXPECT_EQ(opt_list.at(1), flag);
|
||||
EXPECT_EQ(opt_list.at(2), opt);
|
||||
}
|
||||
|
@ -477,3 +477,9 @@ TEST(THelp, CustomDoubleOption) {
|
||||
|
||||
EXPECT_THAT(app.help(), Not(HasSubstr("x 2")));
|
||||
}
|
||||
|
||||
TEST(THelp, AccessDescription) {
|
||||
CLI::App app{"My description goes here"};
|
||||
|
||||
EXPECT_EQ(app.get_description(), "My description goes here");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user