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:
parent
efbfd460a7
commit
de215ef978
@ -2413,7 +2413,7 @@ class App {
|
|||||||
}
|
}
|
||||||
// check for section close
|
// check for section close
|
||||||
if(item.name == "--") {
|
if(item.name == "--") {
|
||||||
if(configurable_) {
|
if(configurable_ && parse_complete_callback_) {
|
||||||
_process_callbacks();
|
_process_callbacks();
|
||||||
_process_requirements();
|
_process_requirements();
|
||||||
run_callback();
|
run_callback();
|
||||||
|
@ -1581,6 +1581,25 @@ TEST_CASE_METHOD(TApp, "DuplicateSubcommandCallbacks", "[config]") {
|
|||||||
CHECK(3 == count);
|
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]") {
|
TEST_CASE_METHOD(TApp, "IniFailure", "[config]") {
|
||||||
|
|
||||||
TempFile tmpini{"TestIniTmp.ini"};
|
TempFile tmpini{"TestIniTmp.ini"};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user