1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-01 13:13:53 +00:00

Making app pointer optional

This commit is contained in:
Henry Fredrick Schreiner 2017-02-03 18:27:27 -05:00
parent 9c55fa2872
commit c10bece495
2 changed files with 10 additions and 4 deletions

View File

@ -596,9 +596,16 @@ protected:
std::function<void(App*)> app_callback;
public:
void set_callback(std::function<void(App*)> callback) {
/// Set a callback to run at the end of parsing
App* set_callback(std::function<void(App*)> callback) {
app_callback = callback;
return this;
}
/// Don't have to worry about explicit App* in argument
App* set_callback(std::function<void()> callback) {
app_callback = [callback](App*){callback();};
return this;
}
void run_callback() {

View File

@ -338,10 +338,9 @@ TEST_F(TApp, Callbacks) {
});
auto sub2 = app.add_subcommand("sub2");
bool val = false;
sub2->set_callback([&val](CLI::App*){
sub2->set_callback([&val](){
val = true;
});
app.reset();
args = {"sub2"};