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 =
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) {
54 && (mode != AppFormatMode::Sub
58 if(!group.empty() && !opts.empty()) {
76 desc +=
" " +
get_label(
"REQUIRED") +
" ";
80 if(max_options == min_options) {
81 desc +=
" \n[Exactly " + std::to_string(min_options) +
" of the following options are required]";
82 }
else if(max_options > 0) {
83 desc +=
" \n[Between " + std::to_string(min_options) +
" and " + std::to_string(max_options) +
84 " of the following options are required]";
86 desc +=
" \n[At least " + std::to_string(min_options) +
" of the following options are required]";
88 }
else if(max_options > 0) {
89 desc +=
" \n[At most " + std::to_string(max_options) +
" of the following options are allowed]";
92 return (!desc.empty()) ? desc +
"\n\n" : std::string{};
98 return usage +
"\n\n";
101 std::stringstream out;
109 std::vector<std::string> groups = app->
get_groups();
112 std::vector<const Option *> non_pos_options =
114 if(!non_pos_options.empty())
115 out <<
" [" <<
get_label(
"OPTIONS") <<
"]";
121 if(!positionals.empty()) {
123 std::vector<std::string> positional_names(positionals.size());
124 std::transform(positionals.begin(), positionals.end(), positional_names.begin(), [
this](
const Option *opt) {
125 return make_option_usage(opt);
128 out <<
" " << detail::join(positional_names,
" ");
133 [](
const CLI::App *subc) { return ((!subc->get_disabled()) && (!subc->get_name().empty())); })
148 return std::string{};
150 return '\n' + footer +
"\n\n";
156 if(mode == AppFormatMode::Sub)
159 std::stringstream out;
166 detail::streamOutAsParagraph(
180 out << footer_string <<
'\n';
187 std::stringstream out;
192 std::vector<std::string> subcmd_groups_seen;
193 for(
const App *com : subcommands) {
194 if(com->get_name().empty()) {
195 if(!com->get_group().empty() && com->get_group().front() !=
'+') {
200 std::string group_key = com->get_group();
201 if(!group_key.empty() &&
202 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](std::string a) {
203 return detail::to_lower(a) == detail::to_lower(group_key);
204 }) == subcmd_groups_seen.end())
205 subcmd_groups_seen.push_back(group_key);
209 for(
const std::string &group : subcmd_groups_seen) {
210 out <<
'\n' << group <<
":\n";
212 [&group](
const App *sub_app) {
return detail::to_lower(sub_app->
get_group()) == detail::to_lower(group); });
213 for(
const App *new_com : subcommands_group) {
214 if(new_com->get_name().empty())
216 if(mode != AppFormatMode::All) {
219 out << new_com->help(new_com->get_name(), AppFormatMode::Sub);
229 std::stringstream out;
232 out << std::setw(static_cast<int>(
column_width_)) << std::left << name;
233 detail::streamOutAsParagraph(
240 std::stringstream out;
244 detail::streamOutAsParagraph(
259 if(mode == AppFormatMode::Sub && !footer_string.empty()) {
262 if(footer_string == parent_footer) {
269 out << footer_string <<
'\n';
276 std::stringstream out;
280 out << std::setw(static_cast<int>(
column_width_)) << std::left << left;
283 bool skipFirstLinePrefix =
true;
286 skipFirstLinePrefix =
false;
288 detail::streamOutAsParagraph(
297 const auto names = detail::split(namesCombined,
',');
298 std::vector<std::string> vshortNames;
299 std::vector<std::string> vlongNames;
300 std::for_each(names.begin(), names.end(), [&vshortNames, &vlongNames](
const std::string &name) {
301 if(name.find(
"--", 0) != std::string::npos)
302 vlongNames.push_back(name);
304 vshortNames.push_back(name);
308 std::string shortNames = detail::join(vshortNames,
", ");
309 std::string longNames = detail::join(vlongNames,
", ");
313 const auto shortNamesColumnWidth =
315 const auto longNamesColumnWidth =
static_cast<int>(
column_width_) - shortNamesColumnWidth;
316 int shortNamesOverSize = 0;
319 if(!shortNames.empty()) {
320 shortNames =
" " + shortNames;
321 if(longNames.empty() && !opts.empty())
323 if(!longNames.empty())
325 if(
static_cast<int>(shortNames.length()) >= shortNamesColumnWidth) {
327 shortNamesOverSize =
static_cast<int>(shortNames.length()) - shortNamesColumnWidth;
329 out << std::setw(shortNamesColumnWidth) << std::left << shortNames;
331 out << std::setw(shortNamesColumnWidth) << std::left <<
"";
336 (std::min)(shortNamesOverSize, longNamesColumnWidth);
337 const auto adjustedLongNamesColumnWidth = longNamesColumnWidth - shortNamesOverSize;
340 if(!longNames.empty()) {
343 if(
static_cast<int>(longNames.length()) >= adjustedLongNamesColumnWidth)
346 out << std::setw(adjustedLongNamesColumnWidth) << std::left << longNames;
348 out << std::setw(adjustedLongNamesColumnWidth) << std::left <<
"";
352 bool skipFirstLinePrefix =
true;
355 skipFirstLinePrefix =
false;
357 detail::streamOutAsParagraph(
374 std::stringstream out;
376 if(!opt->get_option_text().empty()) {
377 out <<
" " << opt->get_option_text();
397 out <<
" " << op->get_name();
400 out <<
" " <<
get_label(
"Excludes") <<
":";
402 out <<
" " << op->get_name();
412 std::stringstream out;
419 return opt->
get_required() ? out.str() :
"[" + out.str() +
"]";
Creates a command line program, with very few defaults.
Definition App.hpp:98
CLI11_NODISCARD std::string get_usage() const
Generate and return the usage.
Definition App.hpp:1143
CLI11_NODISCARD std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition App.hpp:1156
Option * get_help_ptr()
Get a pointer to the help flag.
Definition App.hpp:1202
CLI11_NODISCARD std::string get_footer() const
Generate and return the footer.
Definition App.hpp:1148
CLI11_NODISCARD const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition App.hpp:1208
App * get_parent()
Get the parent of this subcommand (or nullptr if main app)
Definition App.hpp:1223
CLI11_NODISCARD std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
Definition App_inl.hpp:909
CLI11_NODISCARD std::size_t get_require_option_max() const
Get the required max option value.
Definition App.hpp:1162
CLI11_NODISCARD bool get_required() const
Get the status of required.
Definition App.hpp:1171
CLI11_NODISCARD std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition App_inl.hpp:968
CLI11_NODISCARD const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition App.hpp:1232
CLI11_NODISCARD std::size_t get_require_option_min() const
Get the required min option value.
Definition App.hpp:1159
CLI11_NODISCARD const std::string & get_group() const
Get the group of this subcommand.
Definition App.hpp:1140
CLI11_NODISCARD std::vector< App * > get_subcommands() const
Definition App.hpp:940
std::vector< const Option * > get_options(const std::function< bool(const Option *)> filter={}) const
Get the list of options (user facing function, so returns raw pointers), has optional filter function...
Definition App_inl.hpp:831
CLI11_NODISCARD std::string get_description() const
Get the app or subcommand description.
Definition App.hpp:1074
CLI11_NODISCARD std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition App.hpp:1153
CLI11_NODISCARD const std::string & get_name() const
Get the name of the current app.
Definition App.hpp:1229
CLI11_NODISCARD bool get_required() const
True if this is a required option.
Definition Option.hpp:122
CLI11_NODISCARD const std::string & get_group() const
Get the group of this option.
Definition Option.hpp:119
Definition Option.hpp:235
CLI11_NODISCARD bool get_positional() const
True if the argument can be given directly.
Definition Option.hpp:598
CLI11_NODISCARD std::string get_envname() const
The environment variable associated to this value.
Definition Option.hpp:543
CLI11_NODISCARD std::string get_type_name() const
Get the full typename for this option.
Definition Option_inl.hpp:533
CLI11_NODISCARD std::string get_name(bool positional=false, bool all_options=false) const
Gets a comma separated list of names. Will include / prefer the positional name if positional is true...
Definition Option_inl.hpp:256
CLI11_NODISCARD std::string get_default_str() const
The default value (for help printing)
Definition Option.hpp:552
CLI11_NODISCARD bool nonpositional() const
True if option has at least one non-positional name.
Definition Option.hpp:601
CLI11_NODISCARD std::set< Option * > get_excludes() const
The set of options excluded.
Definition Option.hpp:549
CLI11_NODISCARD std::set< Option * > get_needs() const
The set of options needed.
Definition Option.hpp:546
CLI11_NODISCARD const std::string & get_description() const
Get the description.
Definition Option.hpp:607
CLI11_NODISCARD int get_expected() const
The number of times the option expects to be included.
Definition Option.hpp:579
CLI11_NODISCARD int get_expected_min() const
The number of times the option expects to be included.
Definition Option.hpp:582
CLI11_NODISCARD int get_expected_max() const
The max number of times the option expects to be included.
Definition Option.hpp:584
CLI11_NODISCARD int get_type_size() const
The number of arguments the option expects.
Definition Option.hpp:532