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