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