Go to the documentation of this file.
20 std::stringstream out;
22 out <<
"\n" << group <<
":\n";
23 for(
const Option *opt : opts) {
31 std::vector<const Option *> opts =
41 std::stringstream out;
42 std::vector<std::string> groups = app->
get_groups();
45 for(
const std::string &group : groups) {
46 std::vector<const Option *> opts = app->
get_options([app, mode, &group](
const Option *opt) {
53 if(!group.empty() && !opts.empty()) {
56 if(group != groups.back())
71 if((max_options == min_options) && (min_options > 0)) {
72 if(min_options == 1) {
73 desc +=
" \n[Exactly 1 of the following options is required]";
75 desc +=
" \n[Exactly " +
std::to_string(min_options) +
"options from the following list are required]";
77 }
else if(max_options > 0) {
80 " of the follow options are required]";
82 desc +=
" \n[At most " +
std::to_string(max_options) +
" of the following options are allowed]";
84 }
else if(min_options > 0) {
85 desc +=
" \n[At least " +
std::to_string(min_options) +
" of the following options are required]";
87 return (!desc.empty()) ? desc +
"\n" : std::string{};
91 std::stringstream out;
93 out <<
get_label(
"Usage") <<
":" << (name.empty() ?
"" :
" ") << name;
95 std::vector<std::string> groups = app->
get_groups();
98 std::vector<const Option *> non_pos_options =
100 if(!non_pos_options.empty())
101 out <<
" [" <<
get_label(
"OPTIONS") <<
"]";
107 if(!positionals.empty()) {
109 std::vector<std::string> positional_names(positionals.size());
110 std::transform(positionals.begin(), positionals.end(), positional_names.begin(), [
this](
const Option *opt) {
111 return make_option_usage(opt);
119 [](
const CLI::App *subc) { return ((!subc->get_disabled()) && (!subc->get_name().empty())); })
135 return std::string{};
137 return footer +
"\n";
147 std::stringstream out;
165 std::stringstream out;
170 std::vector<std::string> subcmd_groups_seen;
171 for(
const App *com : subcommands) {
172 if(com->get_name().empty()) {
173 if(!com->get_group().empty()) {
178 std::string group_key = com->get_group();
179 if(!group_key.empty() &&
180 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](std::string a) {
181 return detail::to_lower(a) == detail::to_lower(group_key);
182 }) == subcmd_groups_seen.end())
183 subcmd_groups_seen.push_back(group_key);
187 for(
const std::string &group : subcmd_groups_seen) {
188 out <<
"\n" << group <<
":\n";
191 for(
const App *new_com : subcommands_group) {
192 if(new_com->get_name().empty())
207 std::stringstream out;
213 std::stringstream out;
223 tmp = tmp.substr(0, tmp.size() - 1);
237 std::stringstream out;
257 out <<
" " << op->get_name();
260 out <<
" " <<
get_label(
"Excludes") <<
":";
262 out <<
" " << op->get_name();
271 std::stringstream out;
278 return opt->
get_required() ? out.str() :
"[" + out.str() +
"]";
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:213
std::string get_envname() const
The environment variable associated to this value.
Definition: Option.hpp:662
std::string get_default_str() const
The default value (for help printing)
Definition: Option.hpp:671
bool get_required() const
True if this is a required option.
Definition: Option.hpp:118
constexpr int expected_max_vector_size
Definition: StringTools.hpp:39
std::set< Option * > get_needs() const
The set of options needed.
Definition: Option.hpp:665
Option * get_help_ptr()
Get a pointer to the help flag.
Definition: App.hpp:1702
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:1545
const std::string & get_name() const
Get the name of the current app.
Definition: App.hpp:1723
std::string get_display_name() const
Get a display name for an app.
Definition: App.hpp:1735
const std::string & get_group() const
Get the group of this subcommand.
Definition: App.hpp:1658
bool get_positional() const
True if the argument can be given directly.
Definition: Option.hpp:705
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:730
int get_expected_max() const
The max number of times the option expects to be included.
Definition: Option.hpp:691
std::string join(const T &v, std::string delim=",")
Simple function to join a string.
Definition: StringTools.hpp:59
auto to_string(T &&value) -> decltype(std::forward< T >(value))
Convert an object to a string (directly forward if this can become a string)
Definition: TypeTools.hpp:226
bool get_required() const
Get the status of required.
Definition: App.hpp:1682
const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition: App.hpp:1708
std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition: App.hpp:1664
bool nonpositional() const
True if option has at least one non-positional name.
Definition: Option.hpp:708
@ Sub
Used when printed as part of expanded subcommand.
std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition: App.hpp:1767
std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition: App.hpp:1667
std::string get_description() const
Get the app or subcommand description.
Definition: App.hpp:1536
std::size_t get_require_option_min() const
Get the required min option value.
Definition: App.hpp:1670
std::ostream & format_help(std::ostream &out, std::string name, std::string description, std::size_t wid)
Print a two part "help" string.
Definition: StringTools.hpp:158
Definition: Option.hpp:231
std::string get_footer() const
Generate and return the footer.
Definition: App.hpp:1661
std::size_t get_require_option_max() const
Get the required max option value.
Definition: App.hpp:1673
std::string to_lower(std::string str)
Return a lower case version of a string.
Definition: StringTools.hpp:199
AppFormatMode
Definition: FormatterFwd.hpp:26
const std::string & get_description() const
Get the description.
Definition: Option.hpp:714
std::vector< App * > get_subcommands() const
Definition: App.hpp:1347
Creates a command line program, with very few defaults.
Definition: App.hpp:66
int get_type_size() const
The number of arguments the option expects.
Definition: Option.hpp:654
@ All
A fully expanded help.
const std::string & get_group() const
Get the group of this option.
Definition: Option.hpp:115
std::string get_type_name() const
Get the full typename for this option.
Definition: Option.hpp:1111
int get_expected() const
The number of times the option expects to be included.
Definition: Option.hpp:686
std::set< Option * > get_excludes() const
The set of options excluded.
Definition: Option.hpp:668
int get_expected_min() const
The number of times the option expects to be included.
Definition: Option.hpp:689
App * get_parent()
Get the parent of this subcommand (or nullptr if master app)
Definition: App.hpp:1717