302 {
303 std::stringstream out;
304
305 const std::vector<const App*> subcommands = app->get_subcommands([](const App* subc) {
306 if (subc->get_group() == "Instances") {
307 if (subc->get_option("--disabled")->as<bool>()) {
308 const_cast<CLI::App*>(subc)->group(subc->get_group() + " (disabled)");
309 }
310 }
311 return !subc->get_disabled() && !subc->get_name().empty();
312 });
313
314
315 std::set<std::string> subcmd_groups_seen;
316 for (const App* com : subcommands) {
317 if (com->get_name().empty()) {
318 if (!com->get_group().empty()) {
320 }
321 continue;
322 }
323 std::string group_key = com->get_group();
324 if (!group_key.empty() &&
325 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](const std::string& a) {
326 return detail::to_lower(a) == detail::to_lower(group_key);
327 }) == subcmd_groups_seen.end()) {
328 subcmd_groups_seen.insert(group_key);
329 }
330 }
331
332
333 const Option* disabledOpt = app->get_option_no_throw("--disabled");
334 bool disabled = false;
335 if (disabledOpt != nullptr) {
336 disabled = disabledOpt->as<bool>();
337 }
338
339 if (!disabled) {
340 for (const std::string& group : subcmd_groups_seen) {
341 out << "\n" << group << ":\n";
342 const std::vector<const App*> subcommands_group = app->get_subcommands([&group](const App* sub_app) {
343 return detail::to_lower(sub_app->get_group()) == detail::to_lower(group) && !sub_app->get_disabled() &&
344 !sub_app->get_name().empty();
345 });
346 for (const App* new_com : subcommands_group) {
347 if (new_com->get_name().empty()) {
348 continue;
349 }
350 if (mode != AppFormatMode::All) {
352 } else {
353 out << new_com->help(disabledOpt != nullptr && (app->get_help_ptr()->as<std::string>() == "exact" ||
354 app->get_help_ptr()->as<std::string>() == "expanded")
355 ? new_com
356 : nullptr,
357 new_com->get_name(),
358 AppFormatMode::Sub);
359 out << "\n";
360 }
361 }
362 }
363 }
364
365
366
367 std::string tmp = out.str();
368 if (mode == AppFormatMode::All && !tmp.empty()) {
369 tmp.pop_back();
370 }
371
372 out.str(tmp);
373 out.clear();
374
375 return out.str();
376 }