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())); })
149 return std::string{};
151 return '\n' + footer +
"\n\n";
157 if(mode == AppFormatMode::Sub)
160 std::stringstream out;
167 detail::streamOutAsParagraph(
179 std::stringstream out;
184 std::vector<std::string> subcmd_groups_seen;
185 for(
const App *com : subcommands) {
186 if(com->get_name().empty()) {
187 if(!com->get_group().empty() && com->get_group().front() !=
'+') {
192 std::string group_key = com->get_group();
193 if(!group_key.empty() &&
194 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](std::string a) {
195 return detail::to_lower(a) == detail::to_lower(group_key);
196 }) == subcmd_groups_seen.end())
197 subcmd_groups_seen.push_back(group_key);
201 for(
const std::string &group : subcmd_groups_seen) {
202 out <<
'\n' << group <<
":\n";
204 [&group](
const App *sub_app) {
return detail::to_lower(sub_app->
get_group()) == detail::to_lower(group); });
205 for(
const App *new_com : subcommands_group) {
206 if(new_com->get_name().empty())
208 if(mode != AppFormatMode::All) {
211 out << new_com->help(new_com->get_name(), AppFormatMode::Sub);
221 std::stringstream out;
224 out << std::setw(static_cast<int>(
column_width_)) << std::left << name;
225 detail::streamOutAsParagraph(
232 std::stringstream out;
235 detail::streamOutAsParagraph(
252 std::stringstream out;
256 out << std::setw(static_cast<int>(
column_width_)) << std::left << left;
259 bool skipFirstLinePrefix =
true;
262 skipFirstLinePrefix =
false;
264 detail::streamOutAsParagraph(
273 const auto names = detail::split(namesCombined,
',');
274 std::vector<std::string> vshortNames;
275 std::vector<std::string> vlongNames;
276 std::for_each(names.begin(), names.end(), [&vshortNames, &vlongNames](
const std::string &name) {
277 if(name.find(
"--", 0) != std::string::npos)
278 vlongNames.push_back(name);
280 vshortNames.push_back(name);
284 std::string shortNames = detail::join(vshortNames,
", ");
285 std::string longNames = detail::join(vlongNames,
", ");
288 const auto shortNamesColumnWidth =
static_cast<int>(
column_width_ / 3);
289 const auto longNamesColumnWidth =
static_cast<int>(std::ceil(
291 int shortNamesOverSize = 0;
294 if(shortNames.length() > 0) {
295 shortNames =
" " + shortNames;
296 if(longNames.length() == 0 && opts.length() > 0)
298 if(longNames.length() > 0)
300 if(
static_cast<int>(shortNames.length()) >= shortNamesColumnWidth) {
302 shortNamesOverSize =
static_cast<int>(shortNames.length()) - shortNamesColumnWidth;
304 out << std::setw(shortNamesColumnWidth) << std::left << shortNames;
306 out << std::setw(shortNamesColumnWidth) << std::left <<
"";
311 (std::min)(shortNamesOverSize, longNamesColumnWidth);
312 const auto adjustedLongNamesColumnWidth = longNamesColumnWidth - shortNamesOverSize;
315 if(longNames.length() > 0) {
316 if(opts.length() > 0)
318 if(
static_cast<int>(longNames.length()) >= adjustedLongNamesColumnWidth)
321 out << std::setw(adjustedLongNamesColumnWidth) << std::left << longNames;
323 out << std::setw(adjustedLongNamesColumnWidth) << std::left <<
"";
327 bool skipFirstLinePrefix =
true;
330 skipFirstLinePrefix =
false;
332 detail::streamOutAsParagraph(
349 std::stringstream out;
351 if(!opt->get_option_text().empty()) {
352 out <<
" " << opt->get_option_text();
372 out <<
" " << op->get_name();
375 out <<
" " <<
get_label(
"Excludes") <<
":";
377 out <<
" " << op->get_name();
387 std::stringstream out;
394 return opt->
get_required() ? out.str() :
"[" + out.str() +
"]";
Creates a command line program, with very few defaults.
Definition App.hpp:90
CLI11_NODISCARD std::string get_usage() const
Generate and return the usage.
Definition App.hpp:1122
CLI11_NODISCARD std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition App.hpp:1135
Option * get_help_ptr()
Get a pointer to the help flag.
Definition App.hpp:1178
CLI11_NODISCARD std::string get_footer() const
Generate and return the footer.
Definition App.hpp:1127
CLI11_NODISCARD const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition App.hpp:1184
App * get_parent()
Get the parent of this subcommand (or nullptr if main app)
Definition App.hpp:1199
CLI11_NODISCARD std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
Definition App_inl.hpp:880
CLI11_NODISCARD std::size_t get_require_option_max() const
Get the required max option value.
Definition App.hpp:1141
CLI11_NODISCARD bool get_required() const
Get the status of required.
Definition App.hpp:1150
CLI11_NODISCARD std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition App_inl.hpp:924
CLI11_NODISCARD const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition App.hpp:1208
CLI11_NODISCARD std::size_t get_require_option_min() const
Get the required min option value.
Definition App.hpp:1138
CLI11_NODISCARD const std::string & get_group() const
Get the group of this subcommand.
Definition App.hpp:1119
CLI11_NODISCARD std::vector< App * > get_subcommands() const
Definition App.hpp:919
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:802
CLI11_NODISCARD std::string get_description() const
Get the app or subcommand description.
Definition App.hpp:1053
CLI11_NODISCARD std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition App.hpp:1132
CLI11_NODISCARD const std::string & get_name() const
Get the name of the current app.
Definition App.hpp:1205
CLI11_NODISCARD bool get_required() const
True if this is a required option.
Definition Option.hpp:118
CLI11_NODISCARD const std::string & get_group() const
Get the group of this option.
Definition Option.hpp:115
Definition Option.hpp:231
CLI11_NODISCARD bool get_positional() const
True if the argument can be given directly.
Definition Option.hpp:587
CLI11_NODISCARD std::string get_envname() const
The environment variable associated to this value.
Definition Option.hpp:532
CLI11_NODISCARD std::string get_type_name() const
Get the full typename for this option.
Definition Option_inl.hpp:510
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:233
CLI11_NODISCARD std::string get_default_str() const
The default value (for help printing)
Definition Option.hpp:541
CLI11_NODISCARD bool nonpositional() const
True if option has at least one non-positional name.
Definition Option.hpp:590
CLI11_NODISCARD std::set< Option * > get_excludes() const
The set of options excluded.
Definition Option.hpp:538
CLI11_NODISCARD std::set< Option * > get_needs() const
The set of options needed.
Definition Option.hpp:535
CLI11_NODISCARD const std::string & get_description() const
Get the description.
Definition Option.hpp:596
CLI11_NODISCARD int get_expected() const
The number of times the option expects to be included.
Definition Option.hpp:568
CLI11_NODISCARD int get_expected_min() const
The number of times the option expects to be included.
Definition Option.hpp:571
CLI11_NODISCARD int get_expected_max() const
The max number of times the option expects to be included.
Definition Option.hpp:573
CLI11_NODISCARD int get_type_size() const
The number of arguments the option expects.
Definition Option.hpp:521