SNode.C
Loading...
Searching...
No Matches
CLI::HelpFormatter Class Reference

#include <Formatter.h>

Inheritance diagram for CLI::HelpFormatter:
Collaboration diagram for CLI::HelpFormatter:

Public Member Functions

 ~HelpFormatter () override
 

Private Member Functions

std::string make_group (std::string group, bool is_positional, std::vector< const Option * > opts) const override
 
std::string make_description (const App *app) const override
 
std::string make_usage (const App *app, std::string name) const override
 
std::string make_subcommands (const App *app, AppFormatMode mode) const override
 
std::string make_subcommand (const App *sub) const override
 
std::string make_expanded (const App *sub) const override
 
std::string make_option_opts (const Option *opt) const override
 

Detailed Description

Definition at line 78 of file Formatter.h.

Constructor & Destructor Documentation

◆ ~HelpFormatter()

CLI::HelpFormatter::~HelpFormatter ( )
override

Definition at line 177 of file Formatter.cpp.

177 {
178 }

Member Function Documentation

◆ make_description()

CLI11_INLINE std::string CLI::HelpFormatter::make_description ( const App *  app) const
overrideprivate

Definition at line 192 of file Formatter.cpp.

192 {
193 std::string desc = app->get_description();
194 auto min_options = app->get_require_option_min();
195 auto max_options = app->get_require_option_max();
196 // ############## Next line changed (if statement removed)
197 if ((max_options == min_options) && (min_options > 0)) {
198 if (min_options == 1) {
199 desc += " \n[Exactly 1 of the following options is required]";
200 } else {
201 desc += " \n[Exactly " + std::to_string(min_options) + " options from the following list are required]";
202 }
203 } else if (max_options > 0) {
204 if (min_options > 0) {
205 desc += " \n[Between " + std::to_string(min_options) + " and " + std::to_string(max_options) +
206 " of the follow options are required]";
207 } else {
208 desc += " \n[At most " + std::to_string(max_options) + " of the following options are allowed]";
209 }
210 } else if (min_options > 0) {
211 desc += " \n[At least " + std::to_string(min_options) + " of the following options are required]";
212 }
213 return (!desc.empty()) ? desc + "\n" : std::string{};
214 }

Referenced by make_expanded().

Here is the caller graph for this function:

◆ make_expanded()

CLI11_INLINE std::string CLI::HelpFormatter::make_expanded ( const App *  sub) const
overrideprivate

Definition at line 346 of file Formatter.cpp.

346 {
347 std::stringstream out;
348 // ########## Next lines changed
349 const Option* disabledOpt = sub->get_option_no_throw("--disabled");
350 out << sub->get_display_name(true) + " [OPTIONS]" + (!sub->get_subcommands({}).empty() ? " [SECTIONS]" : "") +
351 ((disabledOpt != nullptr ? disabledOpt->as<bool>() : false) ? ""
352 : (sub->get_required() ? " " + get_label("REQUIRED") : ""))
353 << "\n";
354
355 out << make_description(sub);
356 if (sub->get_name().empty() && !sub->get_aliases().empty()) {
357 detail::format_aliases(out, sub->get_aliases(), column_width_ + 2);
358 }
359 out << make_positionals(sub);
360 out << make_groups(sub, AppFormatMode::Sub);
361 out << make_subcommands(sub, AppFormatMode::Sub);
362
363 // Drop blank spaces
364 std::string tmp = out.str();
365 tmp.pop_back();
366
367 // Indent all but the first line (the name)
368 return detail::find_and_replace(tmp, "\n", "\n ") + "\n";
369 }
std::string make_description(const App *app) const override
std::string make_subcommands(const App *app, AppFormatMode mode) const override

References make_description(), and make_subcommands().

Referenced by make_subcommands().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_group()

CLI11_INLINE std::string CLI::HelpFormatter::make_group ( std::string  group,
bool  is_positional,
std::vector< const Option * >  opts 
) const
overrideprivate

Definition at line 180 of file Formatter.cpp.

180 {
181 std::stringstream out;
182
183 // ############## Next line changed
184 out << group << ":\n";
185 for (const Option* opt : opts) {
186 out << make_option(opt, is_positional);
187 }
188
189 return out.str();
190 }

◆ make_option_opts()

CLI11_INLINE std::string CLI::HelpFormatter::make_option_opts ( const Option *  opt) const
overrideprivate

Definition at line 371 of file Formatter.cpp.

371 {
372 std::stringstream out;
373
374 if (!opt->get_option_text().empty()) {
375 out << " " << opt->get_option_text();
376 } else {
377 if (opt->get_type_size() != 0) {
378 if (!opt->get_type_name().empty()) {
379 // ########## Next line changed
380 out << ((opt->get_items_expected_max() == 0) ? "=" : " ") << get_label(opt->get_type_name());
381 }
382 if (!opt->get_default_str().empty()) {
383 out << " [" << opt->get_default_str() << "]";
384 }
385 if (opt->get_expected_max() == detail::expected_max_vector_size) {
386 out << " ... ";
387 } else if (opt->get_expected_min() > 1) {
388 out << " x " << opt->get_expected();
389 }
390 if (opt->get_required()) {
391 out << " " << get_label("REQUIRED");
392 }
393 if (opt->get_configurable()) {
394 out << " " << get_label("PERSISTENT");
395 }
396 }
397 if (!opt->get_envname().empty()) {
398 out << " (" << get_label("Env") << ":" << opt->get_envname() << ") ";
399 }
400 if (!opt->get_needs().empty()) {
401 out << " " << get_label("Needs") << ":";
402 for (const Option* op : opt->get_needs()) {
403 out << " " << op->get_name();
404 }
405 out << " ";
406 }
407 if (!opt->get_excludes().empty()) {
408 out << " " << get_label("Excludes") << ":";
409 for (const Option* op : opt->get_excludes()) {
410 out << " " << op->get_name();
411 }
412 out << " ";
413 }
414 }
415 return out.str();
416 }

◆ make_subcommand()

CLI11_INLINE std::string CLI::HelpFormatter::make_subcommand ( const App *  sub) const
overrideprivate

Definition at line 333 of file Formatter.cpp.

333 {
334 std::stringstream out;
335 // ########## Next lines changed
336 const Option* disabledOpt = sub->get_option_no_throw("--disabled");
337 detail::format_help(out,
338 sub->get_display_name(true) + ((disabledOpt != nullptr ? disabledOpt->as<bool>() : false)
339 ? ""
340 : (sub->get_required() ? " " + get_label("REQUIRED") : "")),
341 sub->get_description(),
342 column_width_);
343 return out.str();
344 }

Referenced by make_subcommands().

Here is the caller graph for this function:

◆ make_subcommands()

CLI11_INLINE std::string CLI::HelpFormatter::make_subcommands ( const App *  app,
AppFormatMode  mode 
) const
overrideprivate

Definition at line 278 of file Formatter.cpp.

278 {
279 std::stringstream out;
280
281 const std::vector<const App*> subcommands = app->get_subcommands([](const App* subc) {
282 return !subc->get_disabled() && !subc->get_name().empty();
283 });
284
285 // Make a list in alphabetic order of the groups seen
286 std::set<std::string> subcmd_groups_seen;
287 for (const App* com : subcommands) {
288 if (com->get_name().empty()) {
289 if (!com->get_group().empty()) {
290 out << make_expanded(com);
291 }
292 continue;
293 }
294 std::string group_key = com->get_group();
295 if (!group_key.empty() &&
296 std::find_if(subcmd_groups_seen.begin(), subcmd_groups_seen.end(), [&group_key](const std::string& a) {
297 return detail::to_lower(a) == detail::to_lower(group_key);
298 }) == subcmd_groups_seen.end()) {
299 subcmd_groups_seen.insert(group_key);
300 }
301 }
302
303 // For each group, filter out and print subcommands
304 for (const std::string& group : subcmd_groups_seen) {
305 out << "\n" << group << ":\n";
306 const std::vector<const App*> subcommands_group = app->get_subcommands([&group](const App* sub_app) {
307 return detail::to_lower(sub_app->get_group()) == detail::to_lower(group) && !sub_app->get_disabled() &&
308 !sub_app->get_name().empty();
309 });
310 for (const App* new_com : subcommands_group) {
311 if (new_com->get_name().empty()) {
312 continue;
313 }
314 if (mode != AppFormatMode::All) {
315 out << make_subcommand(new_com);
316 } else {
317 out << new_com->help(new_com->get_name(), AppFormatMode::Sub);
318 out << "\n";
319 }
320 }
321 }
322
323 // ########## Next line(s) changed
324
325 std::string tmp = out.str();
326 if (mode == AppFormatMode::All && !tmp.empty()) {
327 tmp.pop_back();
328 }
329
330 return tmp;
331 }
std::string make_subcommand(const App *sub) const override
std::string make_expanded(const App *sub) const override

References make_expanded(), and make_subcommand().

Referenced by make_expanded().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_usage()

CLI11_INLINE std::string CLI::HelpFormatter::make_usage ( const App *  app,
std::string  name 
) const
overrideprivate

Definition at line 216 of file Formatter.cpp.

216 {
217 const std::string usage = app->get_usage();
218 if (!usage.empty()) {
219 return usage + "\n";
220 }
221
222 std::stringstream out;
223
224 out << get_label("Usage") << ":" << (name.empty() ? "" : " ") << name;
225
226 // Print an Options badge if any options exist
227 const std::vector<const Option*> non_pos_options = app->get_options([](const Option* opt) {
228 return opt->nonpositional();
229 });
230 if (!non_pos_options.empty()) {
231 out << " [" << get_label("OPTIONS") << "]";
232 }
233
234 // Positionals need to be listed here
235 std::vector<const Option*> positionals = app->get_options([](const Option* opt) {
236 return opt->get_positional();
237 });
238
239 // Print out positionals if any are left
240 if (!positionals.empty()) {
241 // Convert to help names
242 std::vector<std::string> positional_names(positionals.size());
243 std::transform(positionals.begin(), positionals.end(), positional_names.begin(), [this](const Option* opt) {
244 return make_option_usage(opt);
245 });
246
247 out << " " << detail::join(positional_names, " ");
248 }
249
250 // Add a marker if subcommands are expected or optional
251 if (!app->get_subcommands([](const App* subc) {
252 return !subc->get_disabled() && !subc->get_name().empty();
253 })
254 .empty()) {
255 // ############## Next line changed
256 out << " ["
257 << get_label(app->get_subcommands([](const CLI::App* subc) {
258 return ((!subc->get_disabled()) && (!subc->get_name().empty()) /*&& subc->get_required()*/);
259 }).size() <= 1
260 ? "SUBCOMMAND"
261 : "SUBCOMMANDS")
262 << " [--help]"
263 << "]";
264 }
265
266 const Option* disabledOpt = app->get_option_no_throw("--disabled");
267 if (disabledOpt != nullptr ? disabledOpt->as<bool>() : false) {
268 out << " " << get_label("DISABLED");
269 } else if (app->get_required()) {
270 out << " " << get_label("REQUIRED");
271 }
272
273 out << std::endl << std::endl;
274
275 return out.str();
276 }

The documentation for this class was generated from the following files: