23 std::stringstream out;
25 out <<
"\n" << group <<
":\n";
26 for(
const Option *opt : opts) {
34 std::vector<const Option *> opts =
44 std::stringstream out;
45 std::vector<std::string> groups = app->
get_groups();
48 for(
const std::string &group : groups) {
49 std::vector<const Option *> opts = app->
get_options([app, mode, &group](
const Option *opt) {
56 if(!group.empty() && !opts.empty()) {
59 if(group != groups.back())
74 if((max_options == min_options) && (min_options > 0)) {
75 if(min_options == 1) {
76 desc +=
" \n[Exactly 1 of the following options is required]";
78 desc +=
" \n[Exactly " + std::to_string(min_options) +
"options from the following list are required]";
80 }
else if(max_options > 0) {
82 desc +=
" \n[Between " + std::to_string(min_options) +
" and " + std::to_string(max_options) +
83 " of the follow options are required]";
85 desc +=
" \n[At most " + std::to_string(max_options) +
" of the following options are allowed]";
87 }
else if(min_options > 0) {
88 desc +=
" \n[At least " + std::to_string(min_options) +
" of the following options are required]";
90 return (!desc.empty()) ? desc +
"\n" : std::string{};
94 std::stringstream out;
96 out <<
get_label(
"Usage") <<
":" << (name.empty() ?
"" :
" ") << name;
98 std::vector<std::string> groups = app->
get_groups();
101 std::vector<const Option *> non_pos_options =
103 if(!non_pos_options.empty())
104 out <<
" [" <<
get_label(
"OPTIONS") <<
"]";
110 if(!positionals.empty()) {
112 std::vector<std::string> positional_names(positionals.size());
113 std::transform(positionals.begin(), positionals.end(), positional_names.begin(), [
this](
const Option *opt) {
114 return make_option_usage(opt);
122 [](
const CLI::App *subc) { return ((!subc->get_disabled()) && (!subc->get_name().empty())); })
138 return std::string{};
140 return footer +
"\n";
150 std::stringstream out;
168 std::stringstream out;
173 std::vector<std::string> subcmd_groups_seen;
174 for(
const App *com : subcommands) {
175 if(com->get_name().empty()) {
176 if(!com->get_group().empty()) {
181 std::string group_key = com->get_group();
182 if(!group_key.empty() &&
183 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](std::string a) {
184 return detail::to_lower(a) == detail::to_lower(group_key);
185 }) == subcmd_groups_seen.end())
186 subcmd_groups_seen.push_back(group_key);
190 for(
const std::string &group : subcmd_groups_seen) {
191 out <<
"\n" << group <<
":\n";
194 for(
const App *new_com : subcommands_group) {
195 if(new_com->get_name().empty())
210 std::stringstream out;
216 std::stringstream out;
229 tmp = tmp.substr(0, tmp.size() - 1);
243 std::stringstream out;
266 out <<
" " << op->get_name();
269 out <<
" " <<
get_label(
"Excludes") <<
":";
271 out <<
" " << op->get_name();
281 std::stringstream out;
288 return opt->
get_required() ? out.str() :
"[" + out.str() +
"]";
Creates a command line program, with very few defaults.
Definition App.hpp:85
std::size_t get_require_option_min() const
Get the required min option value.
Definition App.hpp:1692
const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition App.hpp:1735
Option * get_help_ptr()
Get a pointer to the help flag.
Definition App.hpp:1729
App * get_parent()
Get the parent of this subcommand (or nullptr if main app)
Definition App.hpp:1750
const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition App.hpp:1759
std::vector< App * > get_subcommands() const
Definition App.hpp:1352
const std::string & get_group() const
Get the group of this subcommand.
Definition App.hpp:1680
bool get_required() const
Get the status of required.
Definition App.hpp:1704
std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition App.hpp:1689
std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
Definition App.hpp:1768
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.hpp:1567
std::string get_description() const
Get the app or subcommand description.
Definition App.hpp:1558
std::size_t get_require_option_max() const
Get the required max option value.
Definition App.hpp:1695
std::string get_footer() const
Generate and return the footer.
Definition App.hpp:1683
const std::string & get_name() const
Get the name of the current app.
Definition App.hpp:1756
std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition App.hpp:1814
std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition App.hpp:1686
bool get_required() const
True if this is a required option.
Definition Option.hpp:125
const std::string & get_group() const
Get the group of this option.
Definition Option.hpp:122
Definition Option.hpp:238
const std::string & get_option_text() const
Definition Option.hpp:773
int get_expected_min() const
The number of times the option expects to be included.
Definition Option.hpp:735
int get_expected_max() const
The max number of times the option expects to be included.
Definition Option.hpp:737
int get_expected() const
The number of times the option expects to be included.
Definition Option.hpp:732
std::string get_default_str() const
The default value (for help printing)
Definition Option.hpp:705
const std::string & get_description() const
Get the description.
Definition Option.hpp:760
std::set< Option * > get_excludes() const
The set of options excluded.
Definition Option.hpp:702
int get_type_size() const
The number of arguments the option expects.
Definition Option.hpp:685
std::string get_type_name() const
Get the full typename for this option.
Definition Option.hpp:1184
bool nonpositional() const
True if option has at least one non-positional name.
Definition Option.hpp:754
std::string get_envname() const
The environment variable associated to this value.
Definition Option.hpp:696
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.hpp:783
bool get_positional() const
True if the argument can be given directly.
Definition Option.hpp:751
std::set< Option * > get_needs() const
The set of options needed.
Definition Option.hpp:699
std::ostream & format_help(std::ostream &out, std::string name, const std::string &description, std::size_t wid)
Print a two part "help" string.
Definition StringTools.hpp:182
std::ostream & format_aliases(std::ostream &out, const std::vector< std::string > &aliases, std::size_t wid)
Print subcommand aliases.
Definition StringTools.hpp:200
constexpr int expected_max_vector_size
Definition StringTools.hpp:43
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition StringTools.hpp:63
std::string find_and_replace(std::string str, std::string from, std::string to)
Find and replace a substring with another substring.
Definition StringTools.hpp:273
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition StringTools.hpp:259
AppFormatMode
Definition FormatterFwd.hpp:29
@ All
A fully expanded help.
@ Sub
Used when printed as part of expanded subcommand.