CLI11  2.3.2
App.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2023, University of Cincinnati, developed by Henry Schreiner
2 // under NSF AWARD 1414736 and by the respective contributors.
3 // All rights reserved.
4 //
5 // SPDX-License-Identifier: BSD-3-Clause
6 
7 #pragma once
8 
9 // [CLI11:public_includes:set]
10 #include <algorithm>
11 #include <cstdint>
12 #include <functional>
13 #include <iostream>
14 #include <iterator>
15 #include <memory>
16 #include <numeric>
17 #include <set>
18 #include <sstream>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 // [CLI11:public_includes:end]
23 
24 // CLI Library includes
25 #include "ConfigFwd.hpp"
26 #include "Error.hpp"
27 #include "FormatterFwd.hpp"
28 #include "Macros.hpp"
29 #include "Option.hpp"
30 #include "Split.hpp"
31 #include "StringTools.hpp"
32 #include "TypeTools.hpp"
33 
34 namespace CLI {
35 // [CLI11:app_hpp:verbatim]
36 
37 #ifndef CLI11_PARSE
38 #define CLI11_PARSE(app, argc, argv) \
39  try { \
40  (app).parse((argc), (argv)); \
41  } catch(const CLI::ParseError &e) { \
42  return (app).exit(e); \
43  }
44 #endif
45 
46 namespace detail {
48 struct AppFriend;
49 } // namespace detail
50 
51 namespace FailureMessage {
53 CLI11_INLINE std::string simple(const App *app, const Error &e);
54 
56 CLI11_INLINE std::string help(const App *app, const Error &e);
57 } // namespace FailureMessage
58 
60 
61 enum class config_extras_mode : char { error = 0, ignore, ignore_all, capture };
62 
63 class App;
64 
65 using App_p = std::shared_ptr<App>;
66 
67 namespace detail {
69 
70 template <typename T, enable_if_t<!std::is_integral<T>::value || (sizeof(T) <= 1U), detail::enabler> = detail::dummy>
72  return opt->always_capture_default();
73 }
74 
76 template <typename T, enable_if_t<std::is_integral<T>::value && (sizeof(T) > 1U), detail::enabler> = detail::dummy>
79 }
80 
81 } // namespace detail
82 
83 class Option_group;
85 
88 class App {
89  friend Option;
90  friend detail::AppFriend;
91 
92  protected:
93  // This library follows the Google style guide for member names ending in underscores
94 
97 
99  std::string name_{};
100 
102  std::string description_{};
103 
105  bool allow_extras_{false};
106 
110 
112  bool prefix_command_{false};
113 
115  bool has_automatic_name_{false};
116 
118  bool required_{false};
119 
121  bool disabled_{false};
122 
124  bool pre_parse_called_{false};
125 
128  bool immediate_callback_{false};
129 
131  std::function<void(std::size_t)> pre_parse_callback_{};
132 
134  std::function<void()> parse_complete_callback_{};
135 
137  std::function<void()> final_callback_{};
138 
142 
145 
147  std::vector<Option_p> options_{};
148 
152 
154  std::string footer_{};
155 
157  std::function<std::string()> footer_callback_{};
158 
160  Option *help_ptr_{nullptr};
161 
164 
166  Option *version_ptr_{nullptr};
167 
169  std::shared_ptr<FormatterBase> formatter_{new Formatter()};
170 
172  std::function<std::string(const App *, const Error &e)> failure_message_{FailureMessage::simple};
173 
177 
178  using missing_t = std::vector<std::pair<detail::Classifier, std::string>>;
179 
184 
186  std::vector<Option *> parse_order_{};
187 
189  std::vector<App *> parsed_subcommands_{};
190 
192  std::set<App *> exclude_subcommands_{};
193 
196  std::set<Option *> exclude_options_{};
197 
200  std::set<App *> need_subcommands_{};
201 
204  std::set<Option *> need_options_{};
205 
209 
211  std::vector<App_p> subcommands_{};
212 
214  bool ignore_case_{false};
215 
217  bool ignore_underscore_{false};
218 
220  bool fallthrough_{false};
221 
224 #ifdef _WIN32
225  true
226 #else
227  false
228 #endif
229  };
231  bool positionals_at_end_{false};
232 
233  enum class startup_mode : char { stable, enabled, disabled };
237 
239  bool configurable_{false};
240 
243 
246 
249  bool silent_{false};
250 
252  std::uint32_t parsed_{0U};
253 
255  std::size_t require_subcommand_min_{0};
256 
258  std::size_t require_subcommand_max_{0};
259 
261  std::size_t require_option_min_{0};
262 
264  std::size_t require_option_max_{0};
265 
267  App *parent_{nullptr};
268 
270  std::string group_{"Subcommands"};
271 
273  std::vector<std::string> aliases_{};
274 
278 
280  Option *config_ptr_{nullptr};
281 
283  std::shared_ptr<Config> config_formatter_{new ConfigTOML()};
284 
286 
288  App(std::string app_description, std::string app_name, App *parent);
289 
290  public:
293 
295  explicit App(std::string app_description = "", std::string app_name = "")
296  : App(app_description, app_name, nullptr) {
297  set_help_flag("-h,--help", "Print this help message and exit");
298  }
299 
300  App(const App &) = delete;
301  App &operator=(const App &) = delete;
302 
304  virtual ~App() = default;
305 
312  App *callback(std::function<void()> app_callback) {
313  if(immediate_callback_) {
314  parse_complete_callback_ = std::move(app_callback);
315  } else {
316  final_callback_ = std::move(app_callback);
317  }
318  return this;
319  }
320 
323  App *final_callback(std::function<void()> app_callback) {
324  final_callback_ = std::move(app_callback);
325  return this;
326  }
327 
330  App *parse_complete_callback(std::function<void()> pc_callback) {
331  parse_complete_callback_ = std::move(pc_callback);
332  return this;
333  }
334 
337  App *preparse_callback(std::function<void(std::size_t)> pp_callback) {
338  pre_parse_callback_ = std::move(pp_callback);
339  return this;
340  }
341 
343  App *name(std::string app_name = "");
344 
346  App *alias(std::string app_name);
347 
349  App *allow_extras(bool allow = true) {
350  allow_extras_ = allow;
351  return this;
352  }
353 
355  App *required(bool require = true) {
356  required_ = require;
357  return this;
358  }
359 
361  App *disabled(bool disable = true) {
362  disabled_ = disable;
363  return this;
364  }
365 
367  App *silent(bool silence = true) {
368  silent_ = silence;
369  return this;
370  }
371 
373  App *disabled_by_default(bool disable = true) {
374  if(disable) {
376  } else {
378  }
379  return this;
380  }
381 
384  App *enabled_by_default(bool enable = true) {
385  if(enable) {
387  } else {
390  }
391  return this;
392  }
393 
395  App *immediate_callback(bool immediate = true);
396 
398  App *validate_positionals(bool validate = true) {
399  validate_positionals_ = validate;
400  return this;
401  }
402 
404  App *validate_optional_arguments(bool validate = true) {
405  validate_optional_arguments_ = validate;
406  return this;
407  }
408 
410  App *allow_config_extras(bool allow = true) {
411  if(allow) {
413  allow_extras_ = true;
414  } else {
416  }
417  return this;
418  }
419 
422  allow_config_extras_ = mode;
423  return this;
424  }
425 
427  App *prefix_command(bool allow = true) {
428  prefix_command_ = allow;
429  return this;
430  }
431 
433  App *ignore_case(bool value = true);
434 
437  App *allow_windows_style_options(bool value = true) {
439  return this;
440  }
441 
443  App *positionals_at_end(bool value = true) {
444  positionals_at_end_ = value;
445  return this;
446  }
447 
449  App *configurable(bool value = true) {
450  configurable_ = value;
451  return this;
452  }
453 
455  App *ignore_underscore(bool value = true);
456 
458  App *formatter(std::shared_ptr<FormatterBase> fmt) {
459  formatter_ = fmt;
460  return this;
461  }
462 
464  App *formatter_fn(std::function<std::string(const App *, std::string, AppFormatMode)> fmt) {
465  formatter_ = std::make_shared<FormatterLambda>(fmt);
466  return this;
467  }
468 
470  App *config_formatter(std::shared_ptr<Config> fmt) {
471  config_formatter_ = fmt;
472  return this;
473  }
474 
476  CLI11_NODISCARD bool parsed() const { return parsed_ > 0; }
477 
480 
484 
499  Option *add_option(std::string option_name,
500  callback_t option_callback,
501  std::string option_description = "",
502  bool defaulted = false,
503  std::function<std::string()> func = {});
504 
506  template <typename AssignTo,
507  typename ConvertTo = AssignTo,
508  enable_if_t<!std::is_const<ConvertTo>::value, detail::enabler> = detail::dummy>
509  Option *add_option(std::string option_name,
510  AssignTo &variable,
511  std::string option_description = "") {
512 
513  auto fun = [&variable](const CLI::results_t &res) { // comment for spacing
514  return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
515  };
516 
517  Option *opt = add_option(option_name, fun, option_description, false, [&variable]() {
518  return CLI::detail::checked_to_string<AssignTo, ConvertTo>(variable);
519  });
520  opt->type_name(detail::type_name<ConvertTo>());
521  // these must be actual lvalues since (std::max) sometimes is defined in terms of references and references
522  // to structs used in the evaluation can be temporary so that would cause issues.
525  opt->type_size(detail::type_count_min<ConvertTo>::value, (std::max)(Tcount, XCcount));
526  opt->expected(detail::expected_count<ConvertTo>::value);
528  return opt;
529  }
530 
532  template <typename AssignTo, enable_if_t<!std::is_const<AssignTo>::value, detail::enabler> = detail::dummy>
533  Option *add_option_no_stream(std::string option_name,
534  AssignTo &variable,
535  std::string option_description = "") {
536 
537  auto fun = [&variable](const CLI::results_t &res) { // comment for spacing
538  return detail::lexical_conversion<AssignTo, AssignTo>(res, variable);
539  };
540 
541  Option *opt = add_option(option_name, fun, option_description, false, []() { return std::string{}; });
542  opt->type_name(detail::type_name<AssignTo>());
543  opt->type_size(detail::type_count_min<AssignTo>::value, detail::type_count<AssignTo>::value);
544  opt->expected(detail::expected_count<AssignTo>::value);
546  return opt;
547  }
548 
550  template <typename ArgType>
551  Option *add_option_function(std::string option_name,
552  const std::function<void(const ArgType &)> &func,
553  std::string option_description = "") {
554 
555  auto fun = [func](const CLI::results_t &res) {
556  ArgType variable;
557  bool result = detail::lexical_conversion<ArgType, ArgType>(res, variable);
558  if(result) {
559  func(variable);
560  }
561  return result;
562  };
563 
564  Option *opt = add_option(option_name, std::move(fun), option_description, false);
565  opt->type_name(detail::type_name<ArgType>());
566  opt->type_size(detail::type_count_min<ArgType>::value, detail::type_count<ArgType>::value);
567  opt->expected(detail::expected_count<ArgType>::value);
568  return opt;
569  }
570 
572  Option *add_option(std::string option_name) {
573  return add_option(option_name, CLI::callback_t{}, std::string{}, false);
574  }
575 
577  template <typename T,
578  enable_if_t<std::is_const<T>::value && std::is_constructible<std::string, T>::value, detail::enabler> =
580  Option *add_option(std::string option_name, T &option_description) {
581  return add_option(option_name, CLI::callback_t(), option_description, false);
582  }
583 
585  Option *set_help_flag(std::string flag_name = "", const std::string &help_description = "");
586 
588  Option *set_help_all_flag(std::string help_name = "", const std::string &help_description = "");
589 
591  Option *set_version_flag(std::string flag_name = "",
592  const std::string &versionString = "",
593  const std::string &version_help = "Display program version information and exit");
594 
596  Option *set_version_flag(std::string flag_name,
597  std::function<std::string()> vfunc,
598  const std::string &version_help = "Display program version information and exit");
599 
600  private:
602  Option *_add_flag_internal(std::string flag_name, CLI::callback_t fun, std::string flag_description);
603 
604  public:
606  Option *add_flag(std::string flag_name) { return _add_flag_internal(flag_name, CLI::callback_t(), std::string{}); }
607 
611  template <typename T,
612  enable_if_t<std::is_const<T>::value && std::is_constructible<std::string, T>::value, detail::enabler> =
614  Option *add_flag(std::string flag_name, T &flag_description) {
615  return _add_flag_internal(flag_name, CLI::callback_t(), flag_description);
616  }
617 
620  template <typename T,
621  enable_if_t<!detail::is_mutable_container<T>::value && !std::is_const<T>::value &&
622  !std::is_constructible<std::function<void(int)>, T>::value,
624  Option *add_flag(std::string flag_name,
625  T &flag_result,
626  std::string flag_description = "") {
627 
628  CLI::callback_t fun = [&flag_result](const CLI::results_t &res) {
630  return lexical_cast(res[0], flag_result);
631  };
632  auto *opt = _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
633  return detail::default_flag_modifiers<T>(opt);
634  }
635 
637  template <typename T,
640  Option *add_flag(std::string flag_name,
641  std::vector<T> &flag_results,
642  std::string flag_description = "") {
643  CLI::callback_t fun = [&flag_results](const CLI::results_t &res) {
644  bool retval = true;
645  for(const auto &elem : res) {
647  flag_results.emplace_back();
648  retval &= lexical_cast(elem, flag_results.back());
649  }
650  return retval;
651  };
652  return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
655  }
656 
658  Option *add_flag_callback(std::string flag_name,
659  std::function<void(void)> function,
660  std::string flag_description = "");
661 
663  Option *add_flag_function(std::string flag_name,
664  std::function<void(std::int64_t)> function,
665  std::string flag_description = "");
666 
667 #ifdef CLI11_CPP14
668  Option *add_flag(std::string flag_name,
670  std::function<void(std::int64_t)> function,
671  std::string flag_description = "") {
672  return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description));
673  }
674 #endif
675 
677  Option *set_config(std::string option_name = "",
678  std::string default_filename = "",
679  const std::string &help_message = "Read an ini file",
680  bool config_required = false);
681 
683  bool remove_option(Option *opt);
684 
686  template <typename T = Option_group>
687  T *add_option_group(std::string group_name, std::string group_description = "") {
688  if(!detail::valid_alias_name_string(group_name)) {
689  throw IncorrectConstruction("option group names may not contain newlines or null characters");
690  }
691  auto option_group = std::make_shared<T>(std::move(group_description), group_name, this);
692  auto *ptr = option_group.get();
693  // move to App_p for overload resolution on older gcc versions
694  App_p app_ptr = std::dynamic_pointer_cast<App>(option_group);
695  add_subcommand(std::move(app_ptr));
696  return ptr;
697  }
698 
702 
704  App *add_subcommand(std::string subcommand_name = "", std::string subcommand_description = "");
705 
707  App *add_subcommand(CLI::App_p subcom);
708 
710  bool remove_subcommand(App *subcom);
711 
714  App *get_subcommand(const App *subcom) const;
715 
717  CLI11_NODISCARD App *get_subcommand(std::string subcom) const;
718 
720  CLI11_NODISCARD App *get_subcommand(int index = 0) const;
721 
723  CLI::App_p get_subcommand_ptr(App *subcom) const;
724 
726  CLI11_NODISCARD CLI::App_p get_subcommand_ptr(std::string subcom) const;
727 
729  CLI11_NODISCARD CLI::App_p get_subcommand_ptr(int index = 0) const;
730 
732  CLI11_NODISCARD App *get_option_group(std::string group_name) const;
733 
737  CLI11_NODISCARD std::size_t count() const { return parsed_; }
738 
741  CLI11_NODISCARD std::size_t count_all() const;
742 
744  App *group(std::string group_name) {
745  group_ = group_name;
746  return this;
747  }
748 
753  return this;
754  }
755 
759  App *require_subcommand(int value) {
760  if(value < 0) {
762  require_subcommand_max_ = static_cast<std::size_t>(-value);
763  } else {
764  require_subcommand_min_ = static_cast<std::size_t>(value);
765  require_subcommand_max_ = static_cast<std::size_t>(value);
766  }
767  return this;
768  }
769 
772  App *require_subcommand(std::size_t min, std::size_t max) {
775  return this;
776  }
777 
782  return this;
783  }
784 
788  App *require_option(int value) {
789  if(value < 0) {
791  require_option_max_ = static_cast<std::size_t>(-value);
792  } else {
793  require_option_min_ = static_cast<std::size_t>(value);
794  require_option_max_ = static_cast<std::size_t>(value);
795  }
796  return this;
797  }
798 
801  App *require_option(std::size_t min, std::size_t max) {
802  require_option_min_ = min;
803  require_option_max_ = max;
804  return this;
805  }
806 
809  App *fallthrough(bool value = true) {
810  fallthrough_ = value;
811  return this;
812  }
813 
816  explicit operator bool() const { return parsed_ > 0; }
817 
821 
825  virtual void pre_callback() {}
826 
830  //
832  void clear();
833 
836  void parse(int argc, const char *const *argv);
837 
842  void parse(std::string commandline, bool program_name_included = false);
843 
846  void parse(std::vector<std::string> &args);
847 
849  void parse(std::vector<std::string> &&args);
850 
851  void parse_from_stream(std::istream &input);
852 
854  void failure_message(std::function<std::string(const App *, const Error &e)> function) {
855  failure_message_ = function;
856  }
857 
859  int exit(const Error &e, std::ostream &out = std::cout, std::ostream &err = std::cerr) const;
860 
864 
866  CLI11_NODISCARD std::size_t count(std::string option_name) const { return get_option(option_name)->count(); }
867 
870  CLI11_NODISCARD std::vector<App *> get_subcommands() const { return parsed_subcommands_; }
871 
874  std::vector<const App *> get_subcommands(const std::function<bool(const App *)> &filter) const;
875 
878  std::vector<App *> get_subcommands(const std::function<bool(App *)> &filter);
879 
881  bool got_subcommand(const App *subcom) const {
882  // get subcom needed to verify that this was a real subcommand
883  return get_subcommand(subcom)->parsed_ > 0;
884  }
885 
887  CLI11_NODISCARD bool got_subcommand(std::string subcommand_name) const {
888  return get_subcommand(subcommand_name)->parsed_ > 0;
889  }
890 
892  App *excludes(Option *opt) {
893  if(opt == nullptr) {
894  throw OptionNotFound("nullptr passed");
895  }
896  exclude_options_.insert(opt);
897  return this;
898  }
899 
901  App *excludes(App *app) {
902  if(app == nullptr) {
903  throw OptionNotFound("nullptr passed");
904  }
905  if(app == this) {
906  throw OptionNotFound("cannot self reference in needs");
907  }
908  auto res = exclude_subcommands_.insert(app);
909  // subcommand exclusion should be symmetric
910  if(res.second) {
911  app->exclude_subcommands_.insert(this);
912  }
913  return this;
914  }
915 
916  App *needs(Option *opt) {
917  if(opt == nullptr) {
918  throw OptionNotFound("nullptr passed");
919  }
920  need_options_.insert(opt);
921  return this;
922  }
923 
924  App *needs(App *app) {
925  if(app == nullptr) {
926  throw OptionNotFound("nullptr passed");
927  }
928  if(app == this) {
929  throw OptionNotFound("cannot self reference in needs");
930  }
931  need_subcommands_.insert(app);
932  return this;
933  }
934 
936  bool remove_excludes(Option *opt);
937 
939  bool remove_excludes(App *app);
940 
942  bool remove_needs(Option *opt);
943 
945  bool remove_needs(App *app);
949 
951  App *footer(std::string footer_string) {
952  footer_ = std::move(footer_string);
953  return this;
954  }
956  App *footer(std::function<std::string()> footer_function) {
957  footer_callback_ = std::move(footer_function);
958  return this;
959  }
962  CLI11_NODISCARD std::string config_to_str(bool default_also = false, bool write_description = false) const {
963  return config_formatter_->to_config(this, default_also, write_description, "");
964  }
965 
968  CLI11_NODISCARD std::string help(std::string prev = "", AppFormatMode mode = AppFormatMode::Normal) const;
969 
971  CLI11_NODISCARD std::string version() const;
975 
977  CLI11_NODISCARD std::shared_ptr<FormatterBase> get_formatter() const { return formatter_; }
978 
980  CLI11_NODISCARD std::shared_ptr<Config> get_config_formatter() const { return config_formatter_; }
981 
983  CLI11_NODISCARD std::shared_ptr<ConfigBase> get_config_formatter_base() const {
984  // This is safer as a dynamic_cast if we have RTTI, as Config -> ConfigBase
985 #if CLI11_USE_STATIC_RTTI == 0
986  return std::dynamic_pointer_cast<ConfigBase>(config_formatter_);
987 #else
988  return std::static_pointer_cast<ConfigBase>(config_formatter_);
989 #endif
990  }
991 
993  CLI11_NODISCARD std::string get_description() const { return description_; }
994 
996  App *description(std::string app_description) {
997  description_ = std::move(app_description);
998  return this;
999  }
1000 
1002  std::vector<const Option *> get_options(const std::function<bool(const Option *)> filter = {}) const;
1003 
1005  std::vector<Option *> get_options(const std::function<bool(Option *)> filter = {});
1006 
1008  Option *get_option_no_throw(std::string option_name) noexcept;
1009 
1011  CLI11_NODISCARD const Option *get_option_no_throw(std::string option_name) const noexcept;
1012 
1014  CLI11_NODISCARD const Option *get_option(std::string option_name) const {
1015  const auto *opt = get_option_no_throw(option_name);
1016  if(opt == nullptr) {
1017  throw OptionNotFound(option_name);
1018  }
1019  return opt;
1020  }
1021 
1023  Option *get_option(std::string option_name) {
1024  auto *opt = get_option_no_throw(option_name);
1025  if(opt == nullptr) {
1026  throw OptionNotFound(option_name);
1027  }
1028  return opt;
1029  }
1030 
1032  const Option *operator[](const std::string &option_name) const { return get_option(option_name); }
1033 
1035  const Option *operator[](const char *option_name) const { return get_option(option_name); }
1036 
1039 
1042 
1045 
1048 
1051 
1054 
1056  CLI11_NODISCARD const std::string &get_group() const { return group_; }
1057 
1059  CLI11_NODISCARD std::string get_footer() const {
1060  return (footer_callback_) ? footer_callback_() + '\n' + footer_ : footer_;
1061  }
1062 
1065 
1068 
1071 
1074 
1077 
1080 
1082  CLI11_NODISCARD bool get_required() const { return required_; }
1083 
1085  CLI11_NODISCARD bool get_disabled() const { return disabled_; }
1086 
1088  CLI11_NODISCARD bool get_silent() const { return silent_; }
1089 
1092 
1095 
1102 
1105 
1108 
1110  CLI11_NODISCARD const Option *get_help_ptr() const { return help_ptr_; }
1111 
1114 
1117 
1120 
1123 
1126 
1128  App *get_parent() { return parent_; }
1129 
1131  CLI11_NODISCARD const App *get_parent() const { return parent_; }
1132 
1134  CLI11_NODISCARD const std::string &get_name() const { return name_; }
1135 
1137  CLI11_NODISCARD const std::vector<std::string> &get_aliases() const { return aliases_; }
1138 
1141  aliases_.clear();
1142  return this;
1143  }
1144 
1146  CLI11_NODISCARD std::string get_display_name(bool with_aliases = false) const;
1147 
1149  CLI11_NODISCARD bool check_name(std::string name_to_check) const;
1150 
1152  CLI11_NODISCARD std::vector<std::string> get_groups() const;
1153 
1155  CLI11_NODISCARD const std::vector<Option *> &parse_order() const { return parse_order_; }
1156 
1158  CLI11_NODISCARD std::vector<std::string> remaining(bool recurse = false) const;
1159 
1161  CLI11_NODISCARD std::vector<std::string> remaining_for_passthrough(bool recurse = false) const;
1162 
1164  CLI11_NODISCARD std::size_t remaining_size(bool recurse = false) const;
1165 
1167 
1168  protected:
1173  void _validate() const;
1174 
1178  void _configure();
1179 
1181  void run_callback(bool final_mode = false, bool suppress_final_callback = false);
1182 
1184  CLI11_NODISCARD bool _valid_subcommand(const std::string &current, bool ignore_used = true) const;
1185 
1187  CLI11_NODISCARD detail::Classifier _recognize(const std::string &current,
1188  bool ignore_used_subcommands = true) const;
1189 
1190  // The parse function is now broken into several parts, and part of process
1191 
1193  void _process_config_file();
1194 
1196  void _process_env();
1197 
1199  void _process_callbacks();
1200 
1204  void _process_help_flags(bool trigger_help = false, bool trigger_all_help = false) const;
1205 
1207  void _process_requirements();
1208 
1210  void _process();
1211 
1213  void _process_extras();
1214 
1217  void _process_extras(std::vector<std::string> &args);
1218 
1220  void increment_parsed();
1221 
1223  void _parse(std::vector<std::string> &args);
1224 
1226  void _parse(std::vector<std::string> &&args);
1227 
1229  void _parse_stream(std::istream &input);
1230 
1235  void _parse_config(const std::vector<ConfigItem> &args);
1236 
1238  bool _parse_single_config(const ConfigItem &item, std::size_t level = 0);
1239 
1242  bool _parse_single(std::vector<std::string> &args, bool &positional_only);
1243 
1245  CLI11_NODISCARD std::size_t _count_remaining_positionals(bool required_only = false) const;
1246 
1249 
1253  bool _parse_positional(std::vector<std::string> &args, bool haltOnSubcommand);
1254 
1258  _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept;
1259 
1264  bool _parse_subcommand(std::vector<std::string> &args);
1265 
1268  bool _parse_arg(std::vector<std::string> &args, detail::Classifier current_type);
1269 
1271  void _trigger_pre_parse(std::size_t remaining_args);
1272 
1275 
1277  CLI11_NODISCARD const std::string &_compare_subcommand_names(const App &subcom, const App &base) const;
1278 
1280  void _move_to_missing(detail::Classifier val_type, const std::string &val);
1281 
1282  public:
1284  void _move_option(Option *opt, App *app);
1285 }; // namespace CLI
1286 
1288 class Option_group : public App {
1289  public:
1290  Option_group(std::string group_description, std::string group_name, App *parent)
1291  : App(std::move(group_description), "", parent) {
1292  group(group_name);
1293  // option groups should have automatic fallthrough
1294  }
1295  using App::add_option;
1298  if(get_parent() == nullptr) {
1299  throw OptionNotFound("Unable to locate the specified option");
1300  }
1301  get_parent()->_move_option(opt, this);
1302  return opt;
1303  }
1305  void add_options(Option *opt) { add_option(opt); }
1307  template <typename... Args> void add_options(Option *opt, Args... args) {
1308  add_option(opt);
1309  add_options(args...);
1310  }
1311  using App::add_subcommand;
1313  App *add_subcommand(App *subcom) {
1314  App_p subc = subcom->get_parent()->get_subcommand_ptr(subcom);
1315  subc->get_parent()->remove_subcommand(subcom);
1316  add_subcommand(std::move(subc));
1317  return subcom;
1318  }
1319 };
1320 
1322 CLI11_INLINE void TriggerOn(App *trigger_app, App *app_to_enable);
1323 
1325 CLI11_INLINE void TriggerOn(App *trigger_app, std::vector<App *> apps_to_enable);
1326 
1328 CLI11_INLINE void TriggerOff(App *trigger_app, App *app_to_enable);
1329 
1331 CLI11_INLINE void TriggerOff(App *trigger_app, std::vector<App *> apps_to_enable);
1332 
1334 CLI11_INLINE void deprecate_option(Option *opt, const std::string &replacement = "");
1335 
1337 inline void deprecate_option(App *app, const std::string &option_name, const std::string &replacement = "") {
1338  auto *opt = app->get_option(option_name);
1339  deprecate_option(opt, replacement);
1340 }
1341 
1343 inline void deprecate_option(App &app, const std::string &option_name, const std::string &replacement = "") {
1344  auto *opt = app.get_option(option_name);
1345  deprecate_option(opt, replacement);
1346 }
1347 
1349 CLI11_INLINE void retire_option(App *app, Option *opt);
1350 
1352 CLI11_INLINE void retire_option(App &app, Option *opt);
1353 
1355 CLI11_INLINE void retire_option(App *app, const std::string &option_name);
1356 
1358 CLI11_INLINE void retire_option(App &app, const std::string &option_name);
1359 
1360 namespace detail {
1362 struct AppFriend {
1363 #ifdef CLI11_CPP14
1364 
1366  template <typename... Args> static decltype(auto) parse_arg(App *app, Args &&...args) {
1367  return app->_parse_arg(std::forward<Args>(args)...);
1368  }
1369 
1371  template <typename... Args> static decltype(auto) parse_subcommand(App *app, Args &&...args) {
1372  return app->_parse_subcommand(std::forward<Args>(args)...);
1373  }
1374 #else
1375  template <typename... Args>
1377  static auto parse_arg(App *app, Args &&...args) ->
1378  typename std::result_of<decltype (&App::_parse_arg)(App, Args...)>::type {
1379  return app->_parse_arg(std::forward<Args>(args)...);
1380  }
1381 
1383  template <typename... Args>
1384  static auto parse_subcommand(App *app, Args &&...args) ->
1385  typename std::result_of<decltype (&App::_parse_subcommand)(App, Args...)>::type {
1386  return app->_parse_subcommand(std::forward<Args>(args)...);
1387  }
1388 #endif
1389  static App *get_fallthrough_parent(App *app) { return app->_get_fallthrough_parent(); }
1391 };
1392 } // namespace detail
1393 
1394 // [CLI11:app_hpp:end]
1395 } // namespace CLI
1396 
1397 #ifndef CLI11_COMPILE
1398 #include "impl/App_inl.hpp"
1399 #endif
App * clear_aliases()
clear all the aliases of the current App
Definition: App.hpp:1140
void _move_option(Option *opt, App *app)
function that could be used by subclasses of App to shift options around into subcommands ...
void failure_message(std::function< std::string(const App *, const Error &e)> function)
Provide a function to print a help message. The function gets access to the App pointer and error...
Definition: App.hpp:854
CLI11_NODISCARD std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition: App.hpp:1064
CLI11_NODISCARD std::string config_to_str(bool default_also=false, bool write_description=false) const
Definition: App.hpp:962
void run_callback(bool final_mode=false, bool suppress_final_callback=false)
Internal function to run (App) callback, bottom up.
CLI11_NODISCARD bool check_name(std::string name_to_check) const
Check the name, case insensitive and underscore insensitive if set.
CLI11_NODISCARD std::shared_ptr< FormatterBase > get_formatter() const
Access the formatter.
Definition: App.hpp:977
CLI11_NODISCARD config_extras_mode get_allow_config_extras() const
Get the status of allow extras.
Definition: App.hpp:1104
This class is simply to allow tests access to App&#39;s protected functions.
Definition: App.hpp:1362
CLI11_NODISCARD std::size_t count_all() const
std::size_t require_subcommand_min_
Minimum required subcommands (not inheritable!)
Definition: App.hpp:255
bool disabled_
If set to true the subcommand is disabled and cannot be used, ignored for main app.
Definition: App.hpp:121
App * prefix_command(bool allow=true)
Do not parse anything after the first unrecognized option and return.
Definition: App.hpp:427
CLI11_INLINE std::string help(const App *app, const Error &e)
Printout the full help string on error (if this fn is set, the old default for CLI11) ...
bool _parse_subcommand(std::vector< std::string > &args)
App * config_formatter(std::shared_ptr< Config > fmt)
Set the config formatter.
Definition: App.hpp:470
const Option * operator[](const char *option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition: App.hpp:1035
bool has_automatic_name_
If set to true the name was automatically generated from the command line vs a user set name...
Definition: App.hpp:115
config_extras_mode
enumeration of modes of how to deal with extras in config files
Definition: App.hpp:61
App * needs(App *app)
Definition: App.hpp:924
App * require_option()
The argumentless form of require option requires 1 or more options be used.
Definition: App.hpp:779
App * require_option(std::size_t min, std::size_t max)
Definition: App.hpp:801
startup_mode default_startup
Definition: App.hpp:236
CLI11_NODISCARD bool get_validate_positionals() const
Get the status of validating positionals.
Definition: App.hpp:1099
Definition: App.hpp:34
void clear()
Reset the parsed data.
Option * set_version_flag(std::string flag_name="", const std::string &versionString="", const std::string &version_help="Display program version information and exit")
Set a version flag and version display string, replace the existing one if present.
Option * add_option(std::string option_name, T &option_description)
Add option with description but with no variable assignment or callback.
Definition: App.hpp:580
Classifier
Definition: App.hpp:47
CLI11_NODISCARD std::string version() const
Displays a version string.
std::vector< std::string > aliases_
Alias names for the subcommand.
Definition: App.hpp:273
App * parent_
A pointer to the parent if this is a subcommand.
Definition: App.hpp:267
App * silent(bool silence=true)
silence the subcommand from showing up in the processed list
Definition: App.hpp:367
bool remove_excludes(Option *opt)
Removes an option from the excludes list of this subcommand.
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition: App.hpp:211
std::string description_
Description of the current program/subcommand.
Definition: App.hpp:102
std::string footer_
Footer to put after all options in the help output INHERITABLE.
Definition: App.hpp:154
CLI11_NODISCARD const std::string & _compare_subcommand_names(const App &subcom, const App &base) const
Helper function to run through all possible comparisons of subcommand names to check there is no over...
App * allow_extras(bool allow=true)
Remove the error when extras are left over on the command line.
Definition: App.hpp:349
std::set< Option * > need_options_
Definition: App.hpp:204
Option * version_ptr_
A pointer to a version flag if there is one.
Definition: App.hpp:166
App(std::string app_description="", std::string app_name="")
Create a new program. Pass in the same arguments as main(), along with a help string.
Definition: App.hpp:295
Option * get_config_ptr()
Get a pointer to the config option.
Definition: App.hpp:1116
std::vector< Option_p > options_
The list of options, stored locally.
Definition: App.hpp:147
CLI11_INLINE void TriggerOff(App *trigger_app, App *app_to_enable)
Helper function to disable one option group/subcommand when another is used.
enabler
Simple empty scoped class.
Definition: TypeTools.hpp:32
CLI11_NODISCARD bool get_enabled_by_default() const
Get the status of disabled by default.
Definition: App.hpp:1097
std::set< Option * > exclude_options_
Definition: App.hpp:196
Option * add_option_no_stream(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition: App.hpp:533
Option * add_option(std::string option_name)
Add option with no description or variable assignment.
Definition: App.hpp:572
bool _parse_single_config(const ConfigItem &item, std::size_t level=0)
Fill in a single config option.
CLI11_NODISCARD const std::vector< Option * > & parse_order() const
This gets a vector of pointers with the original parse order.
Definition: App.hpp:1155
CLI11_INLINE void deprecate_option(Option *opt, const std::string &replacement="")
Helper function to mark an option as deprecated.
CLI11_NODISCARD bool get_prefix_command() const
Get the prefix command status.
Definition: App.hpp:1076
App * preparse_callback(std::function< void(std::size_t)> pp_callback)
Definition: App.hpp:337
std::size_t require_option_min_
Minimum required options (not inheritable!)
Definition: App.hpp:261
void _trigger_pre_parse(std::size_t remaining_args)
Trigger the pre_parse callback if needed.
CLI11_NODISCARD App * get_option_group(std::string group_name) const
Check to see if an option group is part of this App.
App * validate_optional_arguments(bool validate=true)
Set the subcommand to validate optional vector arguments before assigning.
Definition: App.hpp:404
bool remove_needs(Option *opt)
Removes an option from the needs list of this subcommand.
CLI11_NODISCARD std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order)
Definition: Option.hpp:228
void _process_extras()
Throw an error if anything is left over and should not be.
std::vector< Option * > parse_order_
This is a list of pointers to options with the original parse order.
Definition: App.hpp:186
void _process_callbacks()
Process callbacks. Runs on all subcommands.
STL namespace.
CLI11_NODISCARD std::vector< App * > get_subcommands() const
Definition: App.hpp:870
CLI11_NODISCARD std::string get_footer() const
Generate and return the footer.
Definition: App.hpp:1059
bool _parse_arg(std::vector< std::string > &args, detail::Classifier current_type)
App * ignore_case(bool value=true)
Ignore case. Subcommands inherit value.
bool _parse_positional(std::vector< std::string > &args, bool haltOnSubcommand)
void _move_to_missing(detail::Classifier val_type, const std::string &val)
Helper function to place extra values in the most appropriate position.
CLI11_NODISCARD std::size_t get_require_option_min() const
Get the required min option value.
Definition: App.hpp:1070
CLI11_NODISCARD bool parsed() const
Check to see if this subcommand was parsed, true only if received on command line.
Definition: App.hpp:476
CLI11_NODISCARD App * _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
Extension of App to better manage groups of options.
Definition: App.hpp:1288
void _process_env()
Get envname options if not yet passed. Runs on all subcommands.
App * formatter(std::shared_ptr< FormatterBase > fmt)
Set the help formatter.
Definition: App.hpp:458
CLI11_NODISCARD const std::string & get_group() const
Get the group of this subcommand.
Definition: App.hpp:1056
App(std::string app_description, std::string app_name, App *parent)
Special private constructor for subcommand.
Option * add_flag_callback(std::string flag_name, std::function< void(void)> function, std::string flag_description="")
Add option for callback that is triggered with a true flag and takes no arguments.
CLI11_NODISCARD bool get_required() const
Get the status of required.
Definition: App.hpp:1082
bool _parse_single(std::vector< std::string > &args, bool &positional_only)
ConfigBase ConfigTOML
the default Config is the TOML file format
Definition: ConfigFwd.hpp:170
const Option * operator[](const std::string &option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition: App.hpp:1032
App * callback(std::function< void()> app_callback)
Definition: App.hpp:312
std::function< void()> parse_complete_callback_
This is a function that runs when parsing has finished.
Definition: App.hpp:134
T * add_option_group(std::string group_name, std::string group_description="")
creates an option group as part of the given app
Definition: App.hpp:687
bool lexical_cast(const std::string &input, T &output)
Integer conversion.
Definition: TypeTools.hpp:913
constexpr enabler dummy
An instance to use in EnableIf.
Definition: TypeTools.hpp:35
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition: App.hpp:606
static auto parse_arg(App *app, Args &&...args) -> typename std::result_of< decltype(&App::_parse_arg)(App, Args...)>::type
Wrap _parse_short, perfectly forward arguments and return.
Definition: App.hpp:1377
bool remove_subcommand(App *subcom)
Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed...
CLI11_NODISCARD const App * get_parent() const
Get the parent of this subcommand (or nullptr if main app) (const version)
Definition: App.hpp:1131
CLI11_NODISCARD std::size_t count(std::string option_name) const
Counts the number of times the given option was passed.
Definition: App.hpp:866
CLI11_INLINE void TriggerOn(App *trigger_app, App *app_to_enable)
Helper function to enable one option group/subcommand when another is used.
App * get_parent()
Get the parent of this subcommand (or nullptr if main app)
Definition: App.hpp:1128
Option * help_ptr_
A pointer to the help flag if there is one INHERITABLE.
Definition: App.hpp:160
Option * add_flag(std::string flag_name, T &flag_description)
Definition: App.hpp:614
CLI11_NODISCARD std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
bool allow_extras_
If true, allow extra arguments (ie, don&#39;t throw an error). INHERITABLE.
Definition: App.hpp:105
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy)
CLI11_NODISCARD std::vector< std::string > remaining_for_passthrough(bool recurse=false) const
This returns the missing options in a form ready for processing by another command line program...
Option * get_option(std::string option_name)
Get an option by name (non-const version)
Definition: App.hpp:1023
std::string group_
The group membership INHERITABLE.
Definition: App.hpp:270
bool pre_parse_called_
Flag indicating that the pre_parse_callback has been triggered.
Definition: App.hpp:124
CLI11_NODISCARD std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition: App.hpp:1067
App * enabled_by_default(bool enable=true)
Definition: App.hpp:384
App * disabled(bool disable=true)
Disable the subcommand or option group.
Definition: App.hpp:361
bool validate_positionals_
If set to true positional options are validated before assigning INHERITABLE.
Definition: App.hpp:242
CLI::App_p get_subcommand_ptr(App *subcom) const
Check to see if a subcommand is part of this command and get a shared_ptr to it.
Option * add_flag_function(std::string flag_name, std::function< void(std::int64_t)> function, std::string flag_description="")
Add option for callback with an integer value.
CLI11_NODISCARD const Option * get_help_ptr() const
Get a pointer to the help flag. (const)
Definition: App.hpp:1110
CLI11_INLINE std::string simple(const App *app, const Error &e)
Printout a clean, simple message on error (the default in CLI11 1.5+)
OptionDefaults * option_defaults()
Get the OptionDefault object, to set option defaults.
Definition: App.hpp:479
#define CLI11_INLINE
Definition: Macros.hpp:73
App * allow_config_extras(config_extras_mode mode)
ignore extras in config files
Definition: App.hpp:421
Option * help_all_ptr_
A pointer to the help all flag if there is one INHERITABLE.
Definition: App.hpp:163
Option * get_version_ptr()
Get a pointer to the version option.
Definition: App.hpp:1122
void _parse(std::vector< std::string > &args)
Internal parse function.
bool allow_windows_style_options_
Allow &#39;/&#39; for options for Windows like options. Defaults to true on Windows, false otherwise...
Definition: App.hpp:223
App * configurable(bool value=true)
Specify that the subcommand can be triggered by a config file.
Definition: App.hpp:449
bool fallthrough_
Allow subcommand fallthrough, so that parent commands can collect commands after subcommand. INHERITABLE.
Definition: App.hpp:220
std::vector< std::string > results_t
Definition: Option.hpp:29
App * description(std::string app_description)
Set the description of the app.
Definition: App.hpp:996
Option * add_option(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition: App.hpp:509
CLI11_NODISCARD bool get_fallthrough() const
Check the status of fallthrough.
Definition: App.hpp:1044
std::function< std::string()> footer_callback_
This is a function that generates a footer to put after all other options in help output...
Definition: App.hpp:157
static auto parse_subcommand(App *app, Args &&...args) -> typename std::result_of< decltype(&App::_parse_subcommand)(App, Args...)>::type
Wrap _parse_subcommand, perfectly forward arguments and return.
Definition: App.hpp:1384
Option * run_callback_for_default(bool value=true)
Definition: Option.hpp:404
App * require_subcommand()
The argumentless form of require subcommand requires 1 or more subcommands.
Definition: App.hpp:750
App * add_subcommand(App *subcom)
Add an existing subcommand to be a member of an option_group.
Definition: App.hpp:1313
CLI11_NODISCARD const Option * get_version_ptr() const
Get a pointer to the version option. (const)
Definition: App.hpp:1125
CLI11_INLINE void retire_option(App *app, Option *opt)
Helper function to mark an option as retired.
AppFormatMode
Definition: FormatterFwd.hpp:30
OptionDefaults option_defaults_
The default values for options, customizable and changeable INHERITABLE.
Definition: App.hpp:144
CLI11_NODISCARD std::shared_ptr< Config > get_config_formatter() const
Access the config formatter.
Definition: App.hpp:980
CLI11_NODISCARD bool get_positionals_at_end() const
Check the status of the allow windows style options.
Definition: App.hpp:1050
void _parse_stream(std::istream &input)
Internal function to parse a stream.
All errors derive from this one.
Definition: Error.hpp:71
CLI11_NODISCARD bool get_configurable() const
Check the status of the allow windows style options.
Definition: App.hpp:1053
CLI11_NODISCARD detail::Classifier _recognize(const std::string &current, bool ignore_used_subcommands=true) const
Selects a Classifier enum based on the type of the current argument.
bool prefix_command_
If true, return immediately on an unrecognized option (implies allow_extras) INHERITABLE.
Definition: App.hpp:112
missing_t missing_
Definition: App.hpp:183
App * allow_windows_style_options(bool value=true)
Definition: App.hpp:437
void _process_config_file()
Read and process a configuration file (main app only)
void _configure()
void add_options(Option *opt)
Add an existing option to the Option_group.
Definition: App.hpp:1305
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...
App * required(bool require=true)
Remove the error when extras are left over on the command line.
Definition: App.hpp:355
std::shared_ptr< Config > config_formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer) ...
Definition: App.hpp:283
std::set< App * > need_subcommands_
Definition: App.hpp:200
CLI11_NODISCARD bool _valid_subcommand(const std::string &current, bool ignore_used=true) const
Check to see if a subcommand is valid. Give up immediately if subcommand max has been reached...
std::string name_
Subcommand name or program name (from parser if name is empty)
Definition: App.hpp:99
Definition: Option.hpp:191
typename std::enable_if< B, T >::type enable_if_t
Definition: TypeTools.hpp:43
App * alias(std::string app_name)
Set an alias for the app.
App * formatter_fn(std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
Set the help formatter.
Definition: App.hpp:464
The normal, detailed help.
CLI11_NODISCARD const std::string & get_name() const
Get the name of the current app.
Definition: App.hpp:1134
CLI11_NODISCARD bool get_allow_windows_style_options() const
Check the status of the allow windows style options.
Definition: App.hpp:1047
CLI11_NODISCARD const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const)
Definition: App.hpp:1113
CLI11_NODISCARD std::size_t _count_remaining_positionals(bool required_only=false) const
Count the required remaining positional arguments.
Option * get_help_ptr()
Get a pointer to the help flag.
Definition: App.hpp:1107
bool silent_
Definition: App.hpp:249
Option * set_config(std::string option_name="", std::string default_filename="", const std::string &help_message="Read an ini file", bool config_required=false)
Set a configuration ini file option, or clear it if no name passed.
Option * type_size(int option_type_size)
Set a custom option size.
App & operator=(const App &)=delete
App * immediate_callback(bool immediate=true)
Set the subcommand callback to be executed immediately on subcommand completion.
int exit(const Error &e, std::ostream &out=std::cout, std::ostream &err=std::cerr) const
Print a nice error message and return the exit code.
CLI11_NODISCARD bool get_ignore_underscore() const
Check the status of ignore_underscore.
Definition: App.hpp:1041
App * footer(std::string footer_string)
Set footer.
Definition: App.hpp:951
App * allow_config_extras(bool allow=true)
ignore extras in config files
Definition: App.hpp:410
App * require_subcommand(int value)
Definition: App.hpp:759
Option * config_ptr_
Pointer to the config option.
Definition: App.hpp:280
void parse(int argc, const char *const *argv)
Option * force_callback(bool value=true)
Set the value of force_callback.
Definition: Option.hpp:395
CLI11_NODISCARD std::size_t get_require_option_max() const
Get the required max option value.
Definition: App.hpp:1073
void increment_parsed()
Internal function to recursively increment the parsed counter on the current app as well unnamed subc...
CLI11_NODISCARD bool get_ignore_case() const
Check the status of ignore_case.
Definition: App.hpp:1038
#define CLI11_NODISCARD
Definition: Macros.hpp:47
App * final_callback(std::function< void()> app_callback)
Definition: App.hpp:323
bool ignore_underscore_
If true, the program should ignore underscores INHERITABLE.
Definition: App.hpp:217
This will only trigger for actual void type.
Definition: TypeTools.hpp:409
CLI11_NODISCARD bool get_immediate_callback() const
Get the status of disabled.
Definition: App.hpp:1091
CLI11_NODISCARD bool get_allow_extras() const
Get the status of allow extras.
Definition: App.hpp:1079
App * name(std::string app_name="")
Set a name for the app (empty will use parser to set the name)
std::function< void(std::size_t)> pre_parse_callback_
This is a function that runs prior to the start of parsing.
Definition: App.hpp:131
bool validate_optional_arguments_
If set to true optional vector arguments are validated before assigning INHERITABLE.
Definition: App.hpp:245
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
std::size_t require_subcommand_max_
Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE...
Definition: App.hpp:258
CLI11_NODISCARD bool get_silent() const
Get the status of silence.
Definition: App.hpp:1088
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
CLI11_NODISCARD std::string get_description() const
Get the app or subcommand description.
Definition: App.hpp:993
CLI11_NODISCARD std::size_t count() const
Count the total number of times an option was passed.
Definition: Option.hpp:354
Option * add_option_function(std::string option_name, const std::function< void(const ArgType &)> &func, std::string option_description="")
Add option for a callback of a specific type.
Definition: App.hpp:551
bool got_subcommand(const App *subcom) const
Check to see if given subcommand was selected.
Definition: App.hpp:881
App * excludes(App *app)
Sets excluded subcommands for the subcommand.
Definition: App.hpp:901
App * validate_positionals(bool validate=true)
Set the subcommand to validate positional arguments before assigning.
Definition: App.hpp:398
bool remove_option(Option *opt)
Removes an option from the App. Takes an option pointer. Returns true if found and removed...
App * positionals_at_end(bool value=true)
Specify that the positional arguments are only at the end of the sequence.
Definition: App.hpp:443
CLI11_NODISCARD bool got_subcommand(std::string subcommand_name) const
Check with name instead of pointer to see if subcommand was selected.
Definition: App.hpp:887
App * ignore_underscore(bool value=true)
Ignore underscore. Subcommands inherit value.
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition: Option.hpp:721
virtual ~App()=default
virtual destructor
Option * add_flag(std::string flag_name, std::vector< T > &flag_results, std::string flag_description="")
Vector version to capture multiple flags.
Definition: App.hpp:640
static App * get_fallthrough_parent(App *app)
Wrap the fallthrough parent function to make sure that is working correctly.
Definition: App.hpp:1390
CLI11_NODISCARD std::size_t remaining_size(bool recurse=false) const
This returns the number of remaining options, minus the – separator.
void _process_requirements()
Verify required options and cross requirements. Subcommands too (only if selected).
App * needs(Option *opt)
Definition: App.hpp:916
App * require_option(int value)
Definition: App.hpp:788
CLI11_NODISCARD std::string help(std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
Holds values to load into Options.
Definition: ConfigFwd.hpp:26
config_extras_mode allow_config_extras_
Definition: App.hpp:109
CLI11_NODISCARD const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition: App.hpp:1137
Definition: FormatterFwd.hpp:118
std::vector< App * > parsed_subcommands_
This is a list of the subcommands collected, in order.
Definition: App.hpp:189
std::vector< std::pair< detail::Classifier, std::string > > missing_t
Definition: App.hpp:178
void add_options(Option *opt, Args... args)
Add a bunch of options to the group.
Definition: App.hpp:1307
std::shared_ptr< FormatterBase > formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer) ...
Definition: App.hpp:169
std::function< bool(const results_t &)> callback_t
callback function definition
Definition: Option.hpp:31
startup_mode
Definition: App.hpp:233
CRTP * always_capture_default(bool value=true)
Definition: Option.hpp:104
App * excludes(Option *opt)
Sets excluded options for the subcommand.
Definition: App.hpp:892
bool ignore_case_
If true, the program name is not case sensitive INHERITABLE.
Definition: App.hpp:214
App * footer(std::function< std::string()> footer_function)
Set footer.
Definition: App.hpp:956
Option * add_flag(std::string flag_name, T &flag_result, std::string flag_description="")
Definition: App.hpp:624
void _validate() const
bool required_
If set to true the subcommand is required to be processed and used, ignored for main app...
Definition: App.hpp:118
Creates a command line program, with very few defaults.
Definition: App.hpp:88
App * group(std::string group_name)
Changes the group membership.
Definition: App.hpp:744
just get all the passed argument regardless
Option * get_option_no_throw(std::string option_name) noexcept
Get an option by name (noexcept non-const version)
CLI11_NODISCARD bool get_disabled_by_default() const
Get the status of disabled by default.
Definition: App.hpp:1094
Option * set_help_flag(std::string flag_name="", const std::string &help_description="")
Set a help flag, replace the existing one if present.
std::function< std::string(const App *, const Error &e)> failure_message_
The error message printing function INHERITABLE.
Definition: App.hpp:172
CLI11_NODISCARD const Option * get_option(std::string option_name) const
Get an option by name.
Definition: App.hpp:1014
bool configurable_
if set to true the subcommand can be triggered via configuration files INHERITABLE ...
Definition: App.hpp:239
This converter works with INI/TOML files; to write INI files use ConfigINI.
Definition: ConfigFwd.hpp:81
App * require_subcommand(std::size_t min, std::size_t max)
Definition: App.hpp:772
void parse_from_stream(std::istream &input)
bool immediate_callback_
Definition: App.hpp:128
CLI11_NODISCARD bool get_disabled() const
Get the status of disabled.
Definition: App.hpp:1085
Option * default_flag_modifiers(Option *opt)
helper functions for adding in appropriate flag modifiers for add_flag
Definition: App.hpp:71
std::set< App * > exclude_subcommands_
this is a list of subcommands that are exclusionary to this one
Definition: App.hpp:192
App * _get_fallthrough_parent()
Get the appropriate parent to fallthrough to which is the first one that has a name or the main app...
App * parse_complete_callback(std::function< void()> pc_callback)
Definition: App.hpp:330
sum all the arguments together if numerical or concatenate directly without delimiter ...
Option * expected(int value)
Set the number of expected arguments.
CLI11_NODISCARD const Option * get_config_ptr() const
Get a pointer to the config option. (const)
Definition: App.hpp:1119
CLI11_NODISCARD bool get_validate_optional_arguments() const
Get the status of validating optional vector arguments.
Definition: App.hpp:1101
CLI11_NODISCARD std::shared_ptr< ConfigBase > get_config_formatter_base() const
Access the config formatter as a configBase pointer.
Definition: App.hpp:983
bool valid_alias_name_string(const std::string &str)
Verify an app name.
Definition: StringTools.hpp:157
std::uint32_t parsed_
Counts the number of times this command/subcommand was parsed.
Definition: App.hpp:252
Option * default_str(std::string val)
Set the default value string representation (does not change the contained value) ...
Definition: Option.hpp:750
std::shared_ptr< App > App_p
Definition: App.hpp:65
bool positionals_at_end_
specify that positional arguments come at the end of the argument sequence not inheritable ...
Definition: App.hpp:231
App * get_subcommand(const App *subcom) const
CLI11_NODISCARD std::size_t count() const
Definition: App.hpp:737
Option * add_option(Option *opt)
Add an existing option to the Option_group.
Definition: App.hpp:1297
CLI11_NODISCARD std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
App * disabled_by_default(bool disable=true)
Set the subcommand to be disabled by default, so on clear(), at the start of each parse it is disable...
Definition: App.hpp:373
void _process()
Process callbacks and such.
CLI11_NODISCARD bool _has_remaining_positionals() const
Count the required remaining positional arguments.
App * fallthrough(bool value=true)
Definition: App.hpp:809
Option_group(std::string group_description, std::string group_name, App *parent)
Definition: App.hpp:1290
std::size_t require_option_max_
Max number of options allowed. 0 is unlimited (not inheritable)
Definition: App.hpp:264
void _parse_config(const std::vector< ConfigItem > &args)
virtual void pre_callback()
Definition: App.hpp:825
Option * set_help_all_flag(std::string help_name="", const std::string &help_description="")
Set a help all flag, replaced the existing one if present.
void _process_help_flags(bool trigger_help=false, bool trigger_all_help=false) const
std::function< void()> final_callback_
This is a function that runs when all processing has completed.
Definition: App.hpp:137