Skip to content

Commit f74e104

Browse files
App::_process: add conditional logic for old vs. new help processing
Some use cases require altering subcommand/option states (and thus the help output) based on a flag stored in the config file. In this case, running `_process_callbacks()` before `_process_help_flags()` is necessary. A new compile-time option `CLI11_USE_OLD_HELP_PROCESSING` restores this “old” behavior by executing callbacks prior to help flag processing. Extends CLIUtils#1186
1 parent 1ab8646 commit f74e104

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/CLI/impl/App_inl.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,9 +1413,11 @@ CLI11_INLINE void App::_process_requirements() {
14131413
}
14141414

14151415
CLI11_INLINE void App::_process() {
1416+
#ifndef CLI11_USE_OLD_HELP_PROCESSING
14161417
// help takes precedence over other potential errors and config and environment shouldn't be processed if help
14171418
// throws
14181419
_process_help_flags();
1420+
#endif // CLI11_USE_OLD_HELP_PROCESSING
14191421
std::exception_ptr config_exception;
14201422
try {
14211423
// the config file might generate a FileError but that should not be processed until later in the process
@@ -1427,12 +1429,20 @@ CLI11_INLINE void App::_process() {
14271429
} catch(const CLI::FileError &) {
14281430
config_exception = std::current_exception();
14291431
}
1432+
#ifndef CLI11_USE_OLD_HELP_PROCESSING
14301433
// callbacks and requirements processing can generate exceptions which should take priority
14311434
// over the config file error if one exists.
14321435
_process_requirements();
1436+
#endif // CLI11_USE_OLD_HELP_PROCESSING
14331437

14341438
_process_callbacks();
14351439

1440+
#ifdef CLI11_USE_OLD_HELP_PROCESSING
1441+
_process_help_flags();
1442+
1443+
_process_requirements();
1444+
#endif // CLI11_USE_OLD_HELP_PROCESSING
1445+
14361446
if(config_exception) {
14371447
std::rethrow_exception(config_exception);
14381448
}

0 commit comments

Comments
 (0)