1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-07 07:33:51 +00:00

Incorrect subcommand callback trigger (#733)

* fix the issue where subcommand callbacks would be triggered multiple times if specified as configurable.

* style: pre-commit.ci fixes

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Philip Top 2022-05-24 12:19:41 -07:00 committed by GitHub
parent efbfd460a7
commit de215ef978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -2413,7 +2413,7 @@ class App {
}
// check for section close
if(item.name == "--") {
if(configurable_) {
if(configurable_ && parse_complete_callback_) {
_process_callbacks();
_process_requirements();
run_callback();

View File

@ -1581,6 +1581,25 @@ TEST_CASE_METHOD(TApp, "DuplicateSubcommandCallbacks", "[config]") {
CHECK(3 == count);
}
TEST_CASE_METHOD(TApp, "SubcommandCallbackSingle", "[config]") {
TempFile tmptoml{"Testtomlcallback.toml"};
app.set_config("--config", tmptoml);
{
std::ofstream out{tmptoml};
out << "[foo]" << std::endl;
}
int count{0};
auto *foo = app.add_subcommand("foo");
foo->configurable();
foo->callback([&count]() { ++count; });
run();
CHECK(1 == count);
}
TEST_CASE_METHOD(TApp, "IniFailure", "[config]") {
TempFile tmpini{"TestIniTmp.ini"};