-
Notifications
You must be signed in to change notification settings - Fork 364
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
fix: remove duplicated call to subcommand's final_callback #584
fix: remove duplicated call to subcommand's final_callback #584
Conversation
When parse_complete_callback_ is set there is an extra call to run_callback() inside the App::_parse(std::vector<std::string>&) method. This extra call also excessively calls a final_callback_ (when it is also set) for the command and (since it is recursive) for it's subcommands. This commit adds extra boolean parameter for the run_callback() method allowing to explicitly suppress calling to final_callback_. The value of this parameter is also propagated to recursive calls to run_callback(). Fixes CLIUtils#572
Codecov Report
@@ Coverage Diff @@
## master #584 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 12 12
Lines 3764 3764
=========================================
Hits 3764 3764
Continue to review full report at Codecov.
|
Nice, thanks! Could you add a little test for this? (I can add it later if not, though it might be able to be merged faster if you add it). |
Added tests, and fixed another bug, I think - if this is the main app, the |
if(final_callback_ && (parsed_ > 0)) { | ||
if(!name_.empty() || count_all() > 0) { | ||
if(final_callback_ && (parsed_ > 0) && (!suppress_final_callback)) { | ||
if(!name_.empty() || count_all() > 0 || parent_ == nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, specifically, final_callback wasn't always running on the main app.
run(); | ||
|
||
CHECK(app_compl == 1); | ||
CHECK(app_final == 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the above fix, this is 0, not 1. The rest of them were correct.
Fixes #572.