Skip to content

Commit 709c1d0

Browse files
Recursive needs processing
The current way needs relations are checked in void App::_process_requirements() is missleading. Assume you have an application 'test' with a CLI11 config system configuring following needs relations between some subcommands: app ---> sub1 ---> sub11 | |-> sub12 |-> sub2 A) Current needs processing gives: ./test -> test requires sub1 // OK for the user ./test sub1 -> test requires sub2 // OK for the user ./test sub1 sub2 -> sub1 requires sub11 // Confuses the user ./test sub1 sub2 sub11 -> ready for execution B) Recursive needs processing gives: ./test -> test requires sub1 // OK ./test sub1 -> sub1 requires sub11 // Much more intuitive for the user ./test sub1 sub2 -> sub1 requires sub11 // Makes sense: sub1 configuration is not compleate yet ./test sub1 sub11 -> test requires sub2 // OK, sub1 configuration is compleate ./test sub1 sub11 sub2 -> ready for execution
1 parent 5248d5b commit 709c1d0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

include/CLI/impl/App_inl.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,14 @@ CLI11_INLINE void App::_process_requirements() {
13181318
}
13191319
}
13201320
for(const auto &subc : need_subcommands_) {
1321+
try {
1322+
subc->_process_requirements();
1323+
} catch (const CLI::RequiresError& e) {
1324+
if (subc->count() == 0) {
1325+
throw RequiresError(get_display_name(), subc->name_);
1326+
}
1327+
throw;
1328+
}
13211329
if(subc->count_all() == 0) {
13221330
missing_needed = true;
13231331
missing_need = subc->get_display_name();
@@ -1402,7 +1410,7 @@ CLI11_INLINE void App::_process_requirements() {
14021410
}
14031411
}
14041412
}
1405-
if(sub->count() > 0 || sub->name_.empty()) {
1413+
if(sub->count() > 0 || sub->name_.empty() && !need_subcommands_.contains(sub.get())) {
14061414
sub->_process_requirements();
14071415
}
14081416

0 commit comments

Comments
 (0)