Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version flag/option #32

Closed
infinity0n3 opened this issue Sep 10, 2017 · 3 comments · Fixed by #33
Closed

Version flag/option #32

infinity0n3 opened this issue Sep 10, 2017 · 3 comments · Fixed by #33

Comments

@infinity0n3
Copy link

So far to get a simple flag that triggers it's callback first time it's detected I had to do this workaround.

auto ver = app.add_option("-v,--version", (CLI::callback_t)show_version, "Show version");
ver->set_custom_option("", 0); 

It would be much more user friendly to have it similar to add_flag syntax but just with a callback.
No sure if it qualifies to be a separate function as add_config.

Option *add_version(std::string name, callback_t callback, std::string description = "") {
    Option *opt = add_option(name, callback, description, false);
    opt->set_custom_option("", 0);
    return opt;
}
@henryiii
Copy link
Collaborator

Added a function basically like your add_version, but a bit more generally named. It's just an overload on .add_flag for C++14 that takes a callback (signature void(size_t)), but in C++11 you have to use the explicit name, .add_flag_function. Does this make sense, and work for you? Suggestions welcome. I'm assuming there's not a reason to have it return a bool, for example, but maybe that would be useful for requiring 1 flag, for example?

@infinity0n3
Copy link
Author

I can confirm that it works now. Would have been nicer to have the add_flag syntax but I have to use c++11.
Good thing is that it's a one liner now.

Thank you!

@henryiii
Copy link
Collaborator

I do too in several of my projects 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants