280 {
281 std::stringstream out;
282
283 const std::vector<const App*> subcommands = app->get_subcommands([](const App* subc) {
284 if (subc->get_group() == "Instances") {
285 if (subc->get_option("--disabled")->as<bool>()) {
286 const_cast<CLI::App*>(subc)->group(subc->get_group() + " (disabled)");
287 }
288 }
289 return !subc->get_disabled() && !subc->get_name().empty();
290 });
291
292
293 std::set<std::string> subcmd_groups_seen;
294 for (const App* com : subcommands) {
295 if (com->get_name().empty()) {
296 if (!com->get_group().empty()) {
298 }
299 continue;
300 }
301 std::string group_key = com->get_group();
302 if (!group_key.empty() &&
303 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](const std::string& a) {
304 return detail::to_lower(a) == detail::to_lower(group_key);
305 }) == subcmd_groups_seen.end()) {
306 subcmd_groups_seen.insert(group_key);
307 }
308 }
309
310
311 const Option* disabledOpt = app->get_option_no_throw("--disabled");
312 bool disabled = false;
313 if (disabledOpt != nullptr) {
314 disabled = disabledOpt->as<bool>();
315 }
316
317 if (!disabled) {
318 for (const std::string& group : subcmd_groups_seen) {
319 out << "\n" << group << ":\n";
320 const std::vector<const App*> subcommands_group = app->get_subcommands([&group](const App* sub_app) {
321 return detail::to_lower(sub_app->get_group()) == detail::to_lower(group) && !sub_app->get_disabled() &&
322 !sub_app->get_name().empty();
323 });
324 for (const App* new_com : subcommands_group) {
325 if (new_com->get_name().empty()) {
326 continue;
327 }
328 if (mode != AppFormatMode::All) {
330 } else {
331 out << new_com->help(disabledOpt != nullptr && (app->get_help_ptr()->as<std::string>() == "exact" ||
332 app->get_help_ptr()->as<std::string>() == "expanded")
333 ? new_com
334 : nullptr,
335 new_com->get_name(),
336 AppFormatMode::Sub);
337 out << "\n";
338 }
339 }
340 }
341 }
342
343
344
345 std::string tmp = out.str();
346 if (mode == AppFormatMode::All && !tmp.empty()) {
347 tmp.pop_back();
348 }
349
350 out.str(tmp);
351 out.clear();
352
353 return out.str();
354 }