diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e63f7f2..33f1f47f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 01ba655d..776070c8 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 16e68220..5aadd421 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -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(); }