mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 12:43:52 +00:00
Removed virtual setup, since it didn't work
This commit is contained in:
parent
56c85b1e22
commit
feaabb4fb3
@ -1,3 +1,10 @@
|
||||
## Version 0.3 (in progress)
|
||||
|
||||
* Supports GCC 4.7 again
|
||||
* TODO: Support type and set syntax in positionals
|
||||
* Changes `setup` for an explicit help bool in constructor/`add_subcommand`
|
||||
|
||||
|
||||
## Version 0.2
|
||||
|
||||
* Moved to simpler syntax, where `Option` pointers are returned and operated on
|
||||
|
@ -128,9 +128,9 @@ even exit the program through the callback. The main `App` has a callback slot,
|
||||
|
||||
|
||||
|
||||
> ## Subclassing
|
||||
> ### Subclassing
|
||||
>
|
||||
> The App class was designed allow toolkits to subclass it, to provide default options and setup/teardown code. Subcommands remain `App`'s, since those are not expected to need setup and teardown. The default `App` only adds a help flag, `-h,--help` through the `virtual void setup()` method. If you only want to change this flag, override this method. Since subcommands are always the built in `App` object, they must have a normal help flag.
|
||||
> The App class was designed allow toolkits to subclass it, to provide default options and setup/teardown code. Subcommands remain `App`'s, since those are not expected to need setup and teardown. The default `App` only adds a help flag, `-h,--help`, but provides an option to disable it in the constructor (and in `add_subcommand`).
|
||||
>
|
||||
> Also, in a related note, the `App`s you get a pointer to are stored in the parent `App` in `unique_ptr`s (like `Option`s) and are deleted when the main `App` goes out of scope.
|
||||
|
||||
|
@ -81,20 +81,17 @@ public:
|
||||
}
|
||||
|
||||
/// Create a new program. Pass in the same arguments as main(), along with a help string.
|
||||
App(std::string prog_description="")
|
||||
App(std::string prog_description="", bool help=true)
|
||||
: prog_description(prog_description) {
|
||||
|
||||
setup();
|
||||
if(help)
|
||||
help_flag = add_flag("-h,--help", "Print this help message and exit");
|
||||
|
||||
}
|
||||
|
||||
/// Setup help flag. Virtual to allow customization.
|
||||
virtual void setup() {
|
||||
help_flag = add_flag("-h,--help", "Print this help message and exit");
|
||||
}
|
||||
|
||||
App* add_subcommand(std::string name, std::string description="") {
|
||||
subcommands.emplace_back(new App(description));
|
||||
/// Add a subcommand. Like the constructor, you can override the help message addition by setting help=false
|
||||
App* add_subcommand(std::string name, std::string description="", bool help=true) {
|
||||
subcommands.emplace_back(new App(description, help));
|
||||
subcommands.back()->name = name;
|
||||
return subcommands.back().get();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user