9 #include "CLI/FormatterFwd.hpp" 15 std::stringstream out;
17 out <<
"\n" << group <<
":\n";
18 for(
const Option *opt : opts) {
26 std::vector<const Option *> opts =
36 std::stringstream out;
37 std::vector<std::string> groups = app->
get_groups();
40 for(
const std::string &group : groups) {
41 std::vector<const Option *> opts = app->
get_options([app, mode, &group](
const Option *opt) {
44 && (mode != AppFormatMode::Sub
48 if(!group.empty() && !opts.empty()) {
51 if(group != groups.back())
66 if((max_options == min_options) && (min_options > 0)) {
67 if(min_options == 1) {
68 desc +=
" \n[Exactly 1 of the following options is required]";
70 desc +=
" \n[Exactly " + std::to_string(min_options) +
"options from the following list are required]";
72 }
else if(max_options > 0) {
74 desc +=
" \n[Between " + std::to_string(min_options) +
" and " + std::to_string(max_options) +
75 " of the follow options are required]";
77 desc +=
" \n[At most " + std::to_string(max_options) +
" of the following options are allowed]";
79 }
else if(min_options > 0) {
80 desc +=
" \n[At least " + std::to_string(min_options) +
" of the following options are required]";
82 return (!desc.empty()) ? desc +
"\n" : std::string{};
86 std::stringstream out;
88 out <<
get_label(
"Usage") <<
":" << (name.empty() ?
"" :
" ") << name;
90 std::vector<std::string> groups = app->
get_groups();
93 std::vector<const Option *> non_pos_options =
95 if(!non_pos_options.empty())
96 out <<
" [" <<
get_label(
"OPTIONS") <<
"]";
102 if(!positionals.empty()) {
104 std::vector<std::string> positional_names(positionals.size());
105 std::transform(positionals.begin(), positionals.end(), positional_names.begin(), [
this](
const Option *opt) {
109 out <<
" " << detail::join(positional_names,
" ");
114 [](
const CLI::App *subc) { return ((!subc->get_disabled()) && (!subc->get_name().empty())); })
130 return footer +
"\n";
139 if(mode == AppFormatMode::Sub)
142 std::stringstream out;
160 std::stringstream out;
165 std::vector<std::string> subcmd_groups_seen;
166 for(
const App *com : subcommands) {
167 if(com->get_name().empty()) {
171 std::string group_key = com->get_group();
172 if(!group_key.empty() &&
173 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](std::string a) {
174 return detail::to_lower(a) == detail::to_lower(group_key);
175 }) == subcmd_groups_seen.end())
176 subcmd_groups_seen.push_back(group_key);
180 for(
const std::string &group : subcmd_groups_seen) {
181 out <<
"\n" << group <<
":\n";
183 [&group](
const App *sub_app) {
return detail::to_lower(sub_app->
get_group()) == detail::to_lower(group); });
184 for(
const App *new_com : subcommands_group) {
185 if(new_com->get_name().empty())
187 if(mode != AppFormatMode::All) {
190 out << new_com->help(new_com->get_name(), AppFormatMode::Sub);
200 std::stringstream out;
206 std::stringstream out;
215 std::string tmp = detail::find_and_replace(out.str(),
"\n\n",
"\n");
216 tmp = tmp.substr(0, tmp.size() - 1);
219 return detail::find_and_replace(tmp,
"\n",
"\n ") +
"\n";
230 std::stringstream out;
249 out <<
" " << op->get_name();
252 out <<
" " <<
get_label(
"Excludes") <<
":";
254 out <<
" " << op->get_name();
263 std::stringstream out;
267 out <<
"(" << std::to_string(opt->
get_expected()) <<
"x)";
270 return opt->
get_required() ? out.str() :
"[" + out.str() +
"]";
int get_type_size() const
The number of arguments the option expects.
Definition: Option.hpp:540
std::string get_type_name() const
Get the full typename for this option.
Definition: Option.hpp:969
size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition: App.hpp:1649
std::set< Option * > get_needs() const
The set of options needed.
Definition: Option.hpp:546
bool get_positional() const
True if the argument can be given directly.
Definition: Option.hpp:595
bool nonpositional() const
True if option has at least one non-positional name.
Definition: Option.hpp:598
size_t get_require_option_min() const
Get the required min option value.
Definition: App.hpp:1655
int get_expected() const
The number of times the option expects to be included.
Definition: Option.hpp:571
const std::string & get_group() const
Get the group of this option.
Definition: Option.hpp:105
const std::string & get_group() const
Get the group of this subcommand.
Definition: App.hpp:1643
size_t get_require_option_max() const
Get the required max option value.
Definition: App.hpp:1658
App * get_parent()
Get the parent of this subcommand (or nullptr if master app)
Definition: App.hpp:1702
std::string get_name() const
Get the name of the current app.
Definition: App.hpp:1708
std::set< Option * > get_excludes() const
The set of options excluded.
Definition: Option.hpp:549
std::vector< App * > get_subcommands() const
Definition: App.hpp:1405
const std::string & get_footer() const
Get footer.
Definition: App.hpp:1646
std::string get_default_str() const
The default value (for help printing)
Definition: Option.hpp:556
Creates a command line program, with very few defaults.
Definition: App.hpp:59
bool get_required() const
True if this is a required option.
Definition: Option.hpp:108
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:1549
Option * get_help_ptr()
Get a pointer to the help flag.
Definition: App.hpp:1687
std::string get_description() const
Get the app or subcommand description.
Definition: App.hpp:1540
size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition: App.hpp:1652
std::string get_display_name() const
Get a display name for an app.
Definition: App.hpp:1711
const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition: App.hpp:1693
bool get_required() const
Get the status of required.
Definition: App.hpp:1667
const std::string & get_description() const
Get the description.
Definition: Option.hpp:604
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:620
Definition: Option.hpp:206
std::string get_envname() const
The environment variable associated to this value.
Definition: Option.hpp:543
std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition: App.hpp:1729