mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
Added option description setter (#199)
* Added posibility to modify option description: Option::description(const std::string&). Related: https://github.com/CLIUtils/CLI11/issues/193 * Return Option* from Option::description(...). Format-fix to make clang-format happy. * Fixing format * Added posibility to modify app description: App::description(const std::string&). * Fixing Style * Update readme and changelog
This commit is contained in:
parent
72c384cfbb
commit
8d7aefe21f
16
CHANGELOG.md
16
CHANGELOG.md
@ -7,7 +7,8 @@ Passing the same subcommand multiple times is better supported. Several new feat
|
|||||||
* Added `parse(string)` to split up and parse a command-line style string directly. [#186]
|
* Added `parse(string)` to split up and parse a command-line style string directly. [#186]
|
||||||
* Added `ignore_underscore` and related functions, to ignore underscores when matching names. [#185]
|
* Added `ignore_underscore` and related functions, to ignore underscores when matching names. [#185]
|
||||||
* The default INI Config will now add quotes to strings with spaces [#195]
|
* The default INI Config will now add quotes to strings with spaces [#195]
|
||||||
* The default message now will mention the help--all flag also if present [#197]
|
* The default message now will mention the help-all flag also if present [#197]
|
||||||
|
* Added `->description` to set Option descriptions [#199]
|
||||||
* Subcommands now track how many times they were parsed in a parsing process. `count()` with no arguments will return the number of times a subcommand was encountered. [#179]
|
* Subcommands now track how many times they were parsed in a parsing process. `count()` with no arguments will return the number of times a subcommand was encountered. [#179]
|
||||||
* Parsing is now done in phases: `shortcurcuits`, `ini`, `env`, `callbacks`, and `requirements`; all subcommands complete a phase before moving on. [#179]
|
* Parsing is now done in phases: `shortcurcuits`, `ini`, `env`, `callbacks`, and `requirements`; all subcommands complete a phase before moving on. [#179]
|
||||||
* Calling parse multiple times is now officially supported without `clear` (automatic). [#179]
|
* Calling parse multiple times is now officially supported without `clear` (automatic). [#179]
|
||||||
@ -26,6 +27,7 @@ Passing the same subcommand multiple times is better supported. Several new feat
|
|||||||
[#192]: https://github.com/CLIUtils/CLI11/pull/192
|
[#192]: https://github.com/CLIUtils/CLI11/pull/192
|
||||||
[#197]: https://github.com/CLIUtils/CLI11/pull/197
|
[#197]: https://github.com/CLIUtils/CLI11/pull/197
|
||||||
[#195]: https://github.com/CLIUtils/CLI11/issues/195
|
[#195]: https://github.com/CLIUtils/CLI11/issues/195
|
||||||
|
[#199]: https://github.com/CLIUtils/CLI11/pull/199
|
||||||
|
|
||||||
## Version 1.6.2: Help-all
|
## Version 1.6.2: Help-all
|
||||||
|
|
||||||
@ -125,7 +127,7 @@ Other changes:
|
|||||||
|
|
||||||
Backend and testing changes:
|
Backend and testing changes:
|
||||||
|
|
||||||
* Internally, `type_name` is now a lambda function; for sets, this reads the set live. [#116]
|
* Internally, `type_name` is now a lambda function; for sets, this reads the set live. [#116]
|
||||||
* Cleaner tests without `app.reset()` (and `reset` is now `clear`). [#141]
|
* Cleaner tests without `app.reset()` (and `reset` is now `clear`). [#141]
|
||||||
* Better CMake policy handling. [#110]
|
* Better CMake policy handling. [#110]
|
||||||
* Includes are properly sorted. [#120]
|
* Includes are properly sorted. [#120]
|
||||||
@ -221,7 +223,7 @@ This version adds lots of smaller fixes and additions after the refactor in vers
|
|||||||
* Added `ExistingPath` validator [#73]
|
* Added `ExistingPath` validator [#73]
|
||||||
* `app.allow_ini_extras()` added to allow extras in INI files [#70]
|
* `app.allow_ini_extras()` added to allow extras in INI files [#70]
|
||||||
* Multiline INI comments now supported
|
* Multiline INI comments now supported
|
||||||
* Descriptions can now be written with `config_to_str` [#66]
|
* Descriptions can now be written with `config_to_str` [#66]
|
||||||
* Double printing of error message fixed [#77]
|
* Double printing of error message fixed [#77]
|
||||||
* Renamed `requires` to `needs` to avoid C++20 keyword [#75], [#82]
|
* Renamed `requires` to `needs` to avoid C++20 keyword [#75], [#82]
|
||||||
* MakeSingleHeader now works if outside of git [#78]
|
* MakeSingleHeader now works if outside of git [#78]
|
||||||
@ -260,7 +262,7 @@ favorite CLI programs. Error messages and help messages are better and more flex
|
|||||||
* Footers can be added to help [#42](https://github.com/CLIUtils/CLI11/pull/42)
|
* Footers can be added to help [#42](https://github.com/CLIUtils/CLI11/pull/42)
|
||||||
* Help flags are easier to customize [#43](https://github.com/CLIUtils/CLI11/pull/43)
|
* Help flags are easier to customize [#43](https://github.com/CLIUtils/CLI11/pull/43)
|
||||||
* Subcommand now support groups [#46](https://github.com/CLIUtils/CLI11/pull/46)
|
* Subcommand now support groups [#46](https://github.com/CLIUtils/CLI11/pull/46)
|
||||||
* `CLI::RuntimeError` added, for easy exit with error codes [#45](https://github.com/CLIUtils/CLI11/pull/45)
|
* `CLI::RuntimeError` added, for easy exit with error codes [#45](https://github.com/CLIUtils/CLI11/pull/45)
|
||||||
* The clang-format script is now no longer "hidden" [#48](https://github.com/CLIUtils/CLI11/pull/48)
|
* The clang-format script is now no longer "hidden" [#48](https://github.com/CLIUtils/CLI11/pull/48)
|
||||||
* The order is now preserved for subcommands (list and callbacks) [#49](https://github.com/CLIUtils/CLI11/pull/49)
|
* The order is now preserved for subcommands (list and callbacks) [#49](https://github.com/CLIUtils/CLI11/pull/49)
|
||||||
* Tests now run individually, utilizing CMake 3.10 additions if possible [#50](https://github.com/CLIUtils/CLI11/pull/50)
|
* Tests now run individually, utilizing CMake 3.10 additions if possible [#50](https://github.com/CLIUtils/CLI11/pull/50)
|
||||||
@ -277,7 +279,7 @@ favorite CLI programs. Error messages and help messages are better and more flex
|
|||||||
* Allow options to be disabled from INI file, rename `add_config` to `set_config` [#60](https://github.com/CLIUtils/CLI11/pull/60)
|
* Allow options to be disabled from INI file, rename `add_config` to `set_config` [#60](https://github.com/CLIUtils/CLI11/pull/60)
|
||||||
|
|
||||||
> ### Converting from CLI11 1.2:
|
> ### Converting from CLI11 1.2:
|
||||||
>
|
>
|
||||||
> * `app.parse` no longer returns a vector. Instead, use `app.remaining(true)`.
|
> * `app.parse` no longer returns a vector. Instead, use `app.remaining(true)`.
|
||||||
> * `"hidden"` is no longer a special group name, instead use `""`
|
> * `"hidden"` is no longer a special group name, instead use `""`
|
||||||
> * Validators API has changed to return an error string; use `.empty()` to get the old bool back
|
> * Validators API has changed to return an error string; use `.empty()` to get the old bool back
|
||||||
@ -302,8 +304,8 @@ This release focuses on making CLI11 behave properly in corner cases, and with c
|
|||||||
This release incorporates feedback from the release announcement. The examples are slowly being expanded, some corner cases improved, and some new functionality for tricky parsing situations.
|
This release incorporates feedback from the release announcement. The examples are slowly being expanded, some corner cases improved, and some new functionality for tricky parsing situations.
|
||||||
|
|
||||||
* Added simple support for enumerations, allow non-printable objects [#12](https://github.com/CLIUtils/CLI11/issues/12)
|
* Added simple support for enumerations, allow non-printable objects [#12](https://github.com/CLIUtils/CLI11/issues/12)
|
||||||
* Added `app.parse_order()` with original parse order ([#13](https://github.com/CLIUtils/CLI11/issues/13), [#16](https://github.com/CLIUtils/CLI11/pull/16))
|
* Added `app.parse_order()` with original parse order ([#13](https://github.com/CLIUtils/CLI11/issues/13), [#16](https://github.com/CLIUtils/CLI11/pull/16))
|
||||||
* Added `prefix_command()`, which is like `allow_extras` but instantly stops and returns. ([#8](https://github.com/CLIUtils/CLI11/issues/8), [#17](https://github.com/CLIUtils/CLI11/pull/17))
|
* Added `prefix_command()`, which is like `allow_extras` but instantly stops and returns. ([#8](https://github.com/CLIUtils/CLI11/issues/8), [#17](https://github.com/CLIUtils/CLI11/pull/17))
|
||||||
* Removed Windows warning ([#10](https://github.com/CLIUtils/CLI11/issues/10), [#20](https://github.com/CLIUtils/CLI11/pull/20))
|
* Removed Windows warning ([#10](https://github.com/CLIUtils/CLI11/issues/10), [#20](https://github.com/CLIUtils/CLI11/pull/20))
|
||||||
* Some improvements to CMake, detect Python and no dependencies on Python 2 (like Python 3) ([#18](https://github.com/CLIUtils/CLI11/issues/18), [#21](https://github.com/CLIUtils/CLI11/pull/21))
|
* Some improvements to CMake, detect Python and no dependencies on Python 2 (like Python 3) ([#18](https://github.com/CLIUtils/CLI11/issues/18), [#21](https://github.com/CLIUtils/CLI11/pull/21))
|
||||||
|
|
||||||
|
@ -232,6 +232,7 @@ Before parsing, you can set the following options:
|
|||||||
- `->group(name)`: The help group to put the option in. No effect for positional options. Defaults to `"Options"`. `""` will not show up in the help print (hidden).
|
- `->group(name)`: The help group to put the option in. No effect for positional options. Defaults to `"Options"`. `""` will not show up in the help print (hidden).
|
||||||
- `->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).
|
||||||
- `->ignore_underscore()`: Ignore any underscores in the options names (also works on subcommands, does not affect arguments). For example "option_one" will match with optionone. This does not apply to short form options since they only have one character
|
- `->ignore_underscore()`: Ignore any underscores in the options names (also works on subcommands, does not affect arguments). For example "option_one" will match with optionone. This does not apply to short form options since they only have one character
|
||||||
|
- `.description(str)`: Set/change the description.
|
||||||
- `->multi_option_policy(CLI::MultiOptionPolicy::Throw)`: Set the multi-option policy. Shortcuts available: `->take_last()`, `->take_first()`, and `->join()`. This will only affect options expecting 1 argument or bool flags (which always default to take last).
|
- `->multi_option_policy(CLI::MultiOptionPolicy::Throw)`: Set the multi-option policy. Shortcuts available: `->take_last()`, `->take_first()`, and `->join()`. This will only affect options expecting 1 argument or bool flags (which always default to take last).
|
||||||
- `->check(CLI::ExistingFile)`: Requires that the file exists if given.
|
- `->check(CLI::ExistingFile)`: Requires that the file exists if given.
|
||||||
- `->check(CLI::ExistingDirectory)`: Requires that the directory exists.
|
- `->check(CLI::ExistingDirectory)`: Requires that the directory exists.
|
||||||
@ -306,6 +307,7 @@ There are several options that are supported on the main app and subcommands. Th
|
|||||||
- `.get_options(filter)`: Get the list of all defined option pointers (useful for processing the app for custom output formats).
|
- `.get_options(filter)`: Get the list of all defined option pointers (useful for processing the app for custom output formats).
|
||||||
- `.parse_order()`: Get the list of option pointers in the order they were parsed (including duplicates).
|
- `.parse_order()`: Get the list of option pointers in the order they were parsed (including duplicates).
|
||||||
- `.formatter(fmt)`: Set a formatter, with signature `std::string(const App*, std::string, AppFormatMode)`. See Formatting for more details.
|
- `.formatter(fmt)`: Set a formatter, with signature `std::string(const App*, std::string, AppFormatMode)`. See Formatting for more details.
|
||||||
|
- `.description(str)`: Set/change the description.
|
||||||
- `.get_description()`: Access the description.
|
- `.get_description()`: Access the description.
|
||||||
- `.parsed()`: True if this subcommand was given on the command line.
|
- `.parsed()`: True if this subcommand was given on the command line.
|
||||||
- `.name(name)`: Add or change the name.
|
- `.name(name)`: Add or change the name.
|
||||||
@ -478,8 +480,9 @@ Significant features and/or improvements to the code were contributed by:
|
|||||||
- [Paweł Bylica](https://github.com/chfast)
|
- [Paweł Bylica](https://github.com/chfast)
|
||||||
- [Philip Top](https://github.com/phlptp)
|
- [Philip Top](https://github.com/phlptp)
|
||||||
- [almikhayl](https://github.com/almikhayl)
|
- [almikhayl](https://github.com/almikhayl)
|
||||||
- [nurelin](https://github.com/nurelin)
|
- [nurelin](https://github.com/nurelin) <!-- help_all in message -->
|
||||||
- [ncihneg](https://github.com/ncihneg)
|
- [ncihneg](https://github.com/ncihneg) <!-- Quoting strings in INI generation -->
|
||||||
|
- [Fred Helmesjö](https://github.com/helmesjo) <!-- `->description()` -->
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
@ -1374,6 +1374,12 @@ class App {
|
|||||||
/// Get the app or subcommand description
|
/// Get the app or subcommand description
|
||||||
std::string get_description() const { return description_; }
|
std::string get_description() const { return description_; }
|
||||||
|
|
||||||
|
/// Set the description
|
||||||
|
App *description(const std::string &description) {
|
||||||
|
description_ = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the list of options (user facing function, so returns raw pointers), has optional filter function
|
/// Get the list of options (user facing function, so returns raw pointers), has optional filter function
|
||||||
std::vector<const Option *> get_options(const std::function<bool(const Option *)> filter = {}) const {
|
std::vector<const Option *> get_options(const std::function<bool(const Option *)> filter = {}) const {
|
||||||
std::vector<const Option *> options(options_.size());
|
std::vector<const Option *> options(options_.size());
|
||||||
|
@ -517,6 +517,12 @@ class Option : public OptionBase<Option> {
|
|||||||
/// Get the description
|
/// Get the description
|
||||||
const std::string &get_description() const { return description_; }
|
const std::string &get_description() const { return description_; }
|
||||||
|
|
||||||
|
/// Set the description
|
||||||
|
Option *description(const std::string &description) {
|
||||||
|
description_ = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
/// @name Help tools
|
/// @name Help tools
|
||||||
///@{
|
///@{
|
||||||
|
@ -645,6 +645,35 @@ TEST(THelp, AccessDescription) {
|
|||||||
EXPECT_EQ(app.get_description(), "My description goes here");
|
EXPECT_EQ(app.get_description(), "My description goes here");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(THelp, SetDescriptionAfterCreation) {
|
||||||
|
CLI::App app{""};
|
||||||
|
|
||||||
|
app.description("My description goes here");
|
||||||
|
|
||||||
|
EXPECT_EQ(app.get_description(), "My description goes here");
|
||||||
|
EXPECT_THAT(app.help(), HasSubstr("My description goes here"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(THelp, AccessOptionDescription) {
|
||||||
|
CLI::App app{};
|
||||||
|
|
||||||
|
int x;
|
||||||
|
auto opt = app.add_option("-a,--alpha", x, "My description goes here");
|
||||||
|
|
||||||
|
EXPECT_EQ(opt->get_description(), "My description goes here");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(THelp, SetOptionDescriptionAfterCreation) {
|
||||||
|
CLI::App app{};
|
||||||
|
|
||||||
|
int x;
|
||||||
|
auto opt = app.add_option("-a,--alpha", x);
|
||||||
|
opt->description("My description goes here");
|
||||||
|
|
||||||
|
EXPECT_EQ(opt->get_description(), "My description goes here");
|
||||||
|
EXPECT_THAT(app.help(), HasSubstr("My description goes here"));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(THelp, CleanNeeds) {
|
TEST(THelp, CleanNeeds) {
|
||||||
CLI::App app;
|
CLI::App app;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user