You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While adding a new subcommand to our app and using excludes to setup mutual exclusivity with the other subcommands, we found the subcommands refuse to run, even when only one was specified at command line.
This seems to happen when force_callback is used, which sets a variable on the subcommand before the exclusion tests are performed.
Here is a minimal app to reproduce the issue. subcommand_1 has a forced callback, and prevents subcommand_2 to run, despite no parameters being passed for subcommand_1.
Basically, CLI11 is processing the forced callback for subcommand_1 first, which is setting the flag. Then, the requirements for subcommand_2 are processed; when it reaches the exclusion for subcommand_1, it sees a variable is set, and believes it is a conflict.
I don't know the best way of fixing this in the library, other than perhaps marking the variable as being set by a forced callback (and not explicitly set by the user/program otherwise), and ignore those when counting the variables only for the exclusion check?
Our workaround has involved removing the flag lambda entirely, and putting the logic into app.parse_complete_callback() instead. This works, but decouples the flag logic a bit.
The text was updated successfully, but these errors were encountered:
Demonslay335
changed the title
force_callback prevents excluded subcommands from runningforce_callback prevents subcommands with excludes from running
Feb 6, 2024
So apparently this was resolved by #1060, and didn't know it. Was adding a test and couldn't get it to fail. So dug in a bit more and some of the changes for handling round trips on config files, found by the fuzzer, resolved this issue as well.
I added this test
While adding a new subcommand to our app and using
excludes
to setup mutual exclusivity with the other subcommands, we found the subcommands refuse to run, even when only one was specified at command line.This seems to happen when
force_callback
is used, which sets a variable on the subcommand before the exclusion tests are performed.Here is a minimal app to reproduce the issue.
subcommand_1
has a forced callback, and preventssubcommand_2
to run, despite no parameters being passed forsubcommand_1
.Expected output:
Actual output:
Basically, CLI11 is processing the forced callback for
subcommand_1
first, which is setting the flag. Then, the requirements forsubcommand_2
are processed; when it reaches the exclusion forsubcommand_1
, it sees a variable is set, and believes it is a conflict.CLI11/include/CLI/impl/App_inl.hpp
Lines 1188 to 1193 in fd483ea
I don't know the best way of fixing this in the library, other than perhaps marking the variable as being set by a forced callback (and not explicitly set by the user/program otherwise), and ignore those when counting the variables only for the exclusion check?
Our workaround has involved removing the flag lambda entirely, and putting the logic into
app.parse_complete_callback()
instead. This works, but decouples the flag logic a bit.The text was updated successfully, but these errors were encountered: