319 {
320 std::stringstream out;
321
322 const std::vector<const App*> subcommands = app->get_subcommands([](const App* subc) {
323 if (subc->get_group() == "Instances") {
324 if (subc->get_option("--disabled")->as<bool>()) {
325 const_cast<CLI::App*>(subc)->group(subc->get_group() + " (disabled)");
326 }
327 }
328 return !subc->get_disabled() && !subc->get_name().empty();
329 });
330
331
332 std::set<std::string> subcmd_groups_seen;
333 for (const App* com : subcommands) {
334 if (com->get_name().empty()) {
335 if (!com->get_group().empty()) {
337 }
338 continue;
339 }
340 std::string group_key = com->get_group();
341 if (!group_key.empty() &&
342 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](const std::string& a) {
343 return detail::to_lower(a) == detail::to_lower(group_key);
344 }) == subcmd_groups_seen.end()) {
345 subcmd_groups_seen.insert(group_key);
346 }
347 }
348
349
350 const Option* disabledOpt = app->get_option_no_throw("--disabled");
351 bool disabled = false;
352 if (disabledOpt != nullptr) {
353 disabled = disabledOpt->as<bool>();
354 }
355
356 if (!disabled) {
357 for (const std::string& group : subcmd_groups_seen) {
358 out << "\n" << group << ":\n";
359 const std::vector<const App*> subcommands_group = app->get_subcommands([&group](const App* sub_app) {
360 return detail::to_lower(sub_app->get_group()) == detail::to_lower(group) && !sub_app->get_disabled() &&
361 !sub_app->get_name().empty();
362 });
363 for (const App* new_com : subcommands_group) {
364 if (new_com->get_name().empty()) {
365 continue;
366 }
367 if (mode != AppFormatMode::All) {
369 } else {
370 out << new_com->help(disabledOpt != nullptr && (app->get_help_ptr()->as<std::string>() == "exact" ||
371 app->get_help_ptr()->as<std::string>() == "expanded")
372 ? new_com
373 : nullptr,
374 new_com->get_name(),
375 AppFormatMode::Sub);
376 out << "\n";
377 }
378 }
379 }
380 }
381
382
383
384 std::string tmp = out.str();
385 if (mode == AppFormatMode::All && !tmp.empty()) {
386 tmp.pop_back();
387 }
388
389 out.str(tmp);
390 out.clear();
391
392 return out.str();
393 }