12#include "../Formatter.hpp"
23CLI11_INLINE std::string
25 std::stringstream out;
27 out <<
"\n" << group <<
":\n";
28 for(
const Option *opt : opts) {
36 std::vector<const Option *> opts =
37 app->get_options([](
const Option *opt) {
return !opt->get_group().empty() && opt->get_positional(); });
46 std::stringstream out;
47 std::vector<std::string> groups = app->get_groups();
50 for(
const std::string &group : groups) {
51 std::vector<const Option *> opts = app->get_options([app, mode, &group](
const Option *opt) {
52 return opt->get_group() == group
53 && opt->nonpositional()
54 && (mode != AppFormatMode::Sub
55 || (app->get_help_ptr() != opt
56 && app->get_help_all_ptr() != opt));
58 if(!group.empty() && !opts.empty()) {
61 if(group != groups.back())
70 std::string desc = app->get_description();
71 auto min_options = app->get_require_option_min();
72 auto max_options = app->get_require_option_max();
73 if(app->get_required()) {
74 desc +=
" " +
get_label(
"REQUIRED") +
" ";
76 if((max_options == min_options) && (min_options > 0)) {
77 if(min_options == 1) {
78 desc +=
" \n[Exactly 1 of the following options is required]";
80 desc +=
" \n[Exactly " + std::to_string(min_options) +
" options from the following list are required]";
82 }
else if(max_options > 0) {
84 desc +=
" \n[Between " + std::to_string(min_options) +
" and " + std::to_string(max_options) +
85 " of the follow options are required]";
87 desc +=
" \n[At most " + std::to_string(max_options) +
" of the following options are allowed]";
89 }
else if(min_options > 0) {
90 desc +=
" \n[At least " + std::to_string(min_options) +
" of the following options are required]";
92 return (!desc.empty()) ? desc +
"\n" : std::string{};
96 std::string usage = app->get_usage();
101 std::stringstream out;
103 out <<
get_label(
"Usage") <<
":" << (name.empty() ?
"" :
" ") << name;
105 std::vector<std::string> groups = app->get_groups();
108 std::vector<const Option *> non_pos_options =
109 app->get_options([](
const Option *opt) {
return opt->nonpositional(); });
110 if(!non_pos_options.empty())
111 out <<
" [" <<
get_label(
"OPTIONS") <<
"]";
114 std::vector<const Option *> positionals = app->get_options([](
const Option *opt) {
return opt->get_positional(); });
117 if(!positionals.empty()) {
119 std::vector<std::string> positional_names(positionals.size());
120 std::transform(positionals.begin(), positionals.end(), positional_names.begin(), [
this](
const Option *opt) {
121 return make_option_usage(opt);
124 out <<
" " << detail::join(positional_names,
" ");
128 if(!app->get_subcommands(
129 [](
const CLI::App *subc) { return ((!subc->get_disabled()) && (!subc->get_name().empty())); })
131 out <<
" " << (app->get_require_subcommand_min() == 0 ?
"[" :
"")
132 <<
get_label(app->get_require_subcommand_max() < 2 || app->get_require_subcommand_min() > 1 ?
"SUBCOMMAND"
134 << (app->get_require_subcommand_min() == 0 ?
"]" :
"");
143 std::string footer = app->get_footer();
145 return std::string{};
147 return "\n" + footer +
"\n";
154 if(mode == AppFormatMode::Sub)
157 std::stringstream out;
158 if((app->get_name().empty()) && (app->get_parent() !=
nullptr)) {
159 if(app->get_group() !=
"Subcommands") {
160 out << app->get_group() <<
':';
175 std::stringstream out;
177 std::vector<const App *> subcommands = app->get_subcommands({});
180 std::vector<std::string> subcmd_groups_seen;
181 for(
const App *com : subcommands) {
182 if(com->get_name().empty()) {
183 if(!com->get_group().empty()) {
188 std::string group_key = com->get_group();
189 if(!group_key.empty() &&
190 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](std::string a) {
191 return detail::to_lower(a) == detail::to_lower(group_key);
192 }) == subcmd_groups_seen.end())
193 subcmd_groups_seen.push_back(group_key);
197 for(
const std::string &group : subcmd_groups_seen) {
198 out <<
"\n" << group <<
":\n";
199 std::vector<const App *> subcommands_group = app->get_subcommands(
200 [&group](
const App *sub_app) {
return detail::to_lower(sub_app->get_group()) == detail::to_lower(group); });
201 for(
const App *new_com : subcommands_group) {
202 if(new_com->get_name().empty())
204 if(mode != AppFormatMode::All) {
207 out << new_com->help(new_com->get_name(), AppFormatMode::Sub);
217 std::stringstream out;
218 detail::format_help(out,
219 sub->get_display_name(
true) + (sub->get_required() ?
" " +
get_label(
"REQUIRED") :
""),
220 sub->get_description(),
226 std::stringstream out;
227 out << sub->get_display_name(
true) <<
"\n";
230 if(sub->get_name().empty() && !sub->get_aliases().empty()) {
231 detail::format_aliases(out, sub->get_aliases(),
column_width_ + 2);
238 std::string tmp = detail::find_and_replace(out.str(),
"\n\n",
"\n");
239 tmp = tmp.substr(0, tmp.size() - 1);
242 return detail::find_and_replace(tmp,
"\n",
"\n ") +
"\n";
247 return opt->get_name(
true,
false);
249 return opt->get_name(
false,
true);
253 std::stringstream out;
255 if(!opt->get_option_text().empty()) {
256 out <<
" " << opt->get_option_text();
258 if(opt->get_type_size() != 0) {
259 if(!opt->get_type_name().empty())
260 out <<
" " <<
get_label(opt->get_type_name());
261 if(!opt->get_default_str().empty())
262 out <<
" [" << opt->get_default_str() <<
"] ";
263 if(opt->get_expected_max() == detail::expected_max_vector_size)
265 else if(opt->get_expected_min() > 1)
266 out <<
" x " << opt->get_expected();
268 if(opt->get_required())
271 if(!opt->get_envname().empty())
272 out <<
" (" <<
get_label(
"Env") <<
":" << opt->get_envname() <<
")";
273 if(!opt->get_needs().empty()) {
275 for(
const Option *op : opt->get_needs())
276 out <<
" " << op->get_name();
278 if(!opt->get_excludes().empty()) {
279 out <<
" " <<
get_label(
"Excludes") <<
":";
280 for(
const Option *op : opt->get_excludes())
281 out <<
" " << op->get_name();
291 std::stringstream out;
293 if(opt->get_expected_max() >= detail::expected_max_vector_size)
295 else if(opt->get_expected_max() > 1)
296 out <<
"(" << opt->get_expected() <<
"x)";
298 return opt->get_required() ? out.str() :
"[" + out.str() +
"]";
Creates a command line program, with very few defaults.
Definition App.hpp:90
Definition Option.hpp:231