Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-04 10:45:10

0001 // Copyright (c) 2017-2026, University of Cincinnati, developed by Henry Schreiner
0002 // under NSF AWARD 1414736 and by the respective contributors.
0003 // All rights reserved.
0004 //
0005 // SPDX-License-Identifier: BSD-3-Clause
0006 
0007 #pragma once
0008 
0009 // IWYU pragma: private, include "CLI/CLI.hpp"
0010 
0011 // [CLI11:public_includes:set]
0012 #include <algorithm>
0013 #include <cstdint>
0014 #include <functional>
0015 #include <iostream>
0016 #include <iterator>
0017 #include <memory>
0018 #include <numeric>
0019 #include <set>
0020 #include <sstream>
0021 #include <string>
0022 #include <utility>
0023 #include <vector>
0024 // [CLI11:public_includes:end]
0025 
0026 // CLI Library includes
0027 #include "ConfigFwd.hpp"
0028 #include "Error.hpp"
0029 #include "FormatterFwd.hpp"
0030 #include "Macros.hpp"
0031 #include "Option.hpp"
0032 #include "Split.hpp"
0033 #include "StringTools.hpp"
0034 #include "TypeTools.hpp"
0035 
0036 namespace CLI {
0037 // [CLI11:app_hpp:verbatim]
0038 
0039 #ifndef CLI11_PARSE
0040 #define CLI11_PARSE(app, ...)                                                                                          \
0041     try {                                                                                                              \
0042         (app).parse(__VA_ARGS__);                                                                                      \
0043     } catch(const CLI::ParseError &e) {                                                                                \
0044         return (app).exit(e);                                                                                          \
0045     }
0046 #endif
0047 
0048 namespace detail {
0049 enum class Classifier : std::uint8_t {
0050     NONE,
0051     POSITIONAL_MARK,
0052     SHORT,
0053     LONG,
0054     WINDOWS_STYLE,
0055     SUBCOMMAND,
0056     SUBCOMMAND_TERMINATOR
0057 };
0058 struct AppFriend;
0059 }  // namespace detail
0060 
0061 namespace FailureMessage {
0062 /// Printout a clean, simple message on error (the default in CLI11 1.5+)
0063 CLI11_INLINE std::string simple(const App *app, const Error &e);
0064 
0065 /// Printout the full help string on error (if this fn is set, the old default for CLI11)
0066 CLI11_INLINE std::string help(const App *app, const Error &e);
0067 }  // namespace FailureMessage
0068 
0069 /// enumeration of modes of how to deal with command line extras
0070 enum class ExtrasMode : std::uint8_t {
0071     Error = 0,
0072     ErrorImmediately,
0073     Ignore,
0074     AssumeSingleArgument,
0075     AssumeMultipleArguments,
0076     Capture
0077 };
0078 
0079 /// enumeration of modes of how to deal with extras in config files
0080 enum class ConfigExtrasMode : std::uint8_t { Error = 0, Ignore, IgnoreAll, Capture };
0081 
0082 /// @brief  enumeration of modes of how to deal with extras in config files
0083 enum class config_extras_mode : std::uint8_t { error = 0, ignore, ignore_all, capture };
0084 
0085 /// @brief  enumeration of prefix command modes, separator requires that the first extra argument be a "--", other
0086 /// unrecognized arguments will cause an error. on allows the first extra to trigger prefix mode regardless of other
0087 /// recognized options. positional_only triggers prefix mode only at the first positional argument (or "--");
0088 /// unrecognized options do not stop parsing and are collected as extras
0089 enum class PrefixCommandMode : std::uint8_t { Off = 0, SeparatorOnly = 1, On = 2, PositionalOnly = 3 };
0090 
0091 class App;
0092 
0093 using App_p = std::shared_ptr<App>;
0094 
0095 namespace detail {
0096 /// helper functions for adding in appropriate flag modifiers for add_flag
0097 
0098 template <typename T, enable_if_t<!std::is_integral<T>::value || (sizeof(T) <= 1U), detail::enabler> = detail::dummy>
0099 Option *default_flag_modifiers(Option *opt) {
0100     return opt->always_capture_default();
0101 }
0102 
0103 /// summing modifiers
0104 template <typename T, enable_if_t<std::is_integral<T>::value && (sizeof(T) > 1U), detail::enabler> = detail::dummy>
0105 Option *default_flag_modifiers(Option *opt) {
0106     return opt->multi_option_policy(MultiOptionPolicy::Sum)->default_str("0")->force_callback();
0107 }
0108 
0109 }  // namespace detail
0110 
0111 class Option_group;
0112 /// Creates a command line program, with very few defaults.
0113 /** To use, create a new `App` instance with a description, then call `parse(argc, argv)`. The templated
0114  *  add_option methods make it easy to prepare options. After parsing, bound variables hold the parsed values. */
0115 class App {
0116     friend Option;
0117     friend detail::AppFriend;
0118 
0119   protected:
0120     // This library follows the Google style guide for member names ending in underscores
0121 
0122     /// @name Basics
0123     ///@{
0124 
0125     /// Subcommand name or program name (from parser if name is empty)
0126     std::string name_{};
0127 
0128     /// Description of the current program/subcommand
0129     std::string description_{};
0130 
0131     /// If true, allow extra arguments (ie, don't throw an error). INHERITABLE
0132     ExtrasMode allow_extras_{ExtrasMode::Error};
0133 
0134     /// If ignore, allow extra arguments in the ini file (ie, don't throw an error). INHERITABLE
0135     /// if error, error on an extra argument, and if capture feed it to the app
0136     ConfigExtrasMode allow_config_extras_{ConfigExtrasMode::Ignore};
0137 
0138     ///  If true, cease processing on an unrecognized option (implies allow_extras) INHERITABLE
0139     PrefixCommandMode prefix_command_{PrefixCommandMode::Off};
0140 
0141     /// If set to true the name was automatically generated from the command line vs a user set name
0142     bool has_automatic_name_{false};
0143 
0144     /// If set to true the subcommand is required to be processed and used, ignored for main app
0145     bool required_{false};
0146 
0147     /// If set to true the subcommand is disabled and cannot be used, ignored for main app
0148     bool disabled_{false};
0149 
0150     /// Flag indicating that the pre_parse_callback has been triggered
0151     bool pre_parse_called_{false};
0152 
0153     /// Flag indicating that the callback for the subcommand should be executed immediately on parse completion which is
0154     /// before help or ini files are processed. INHERITABLE
0155     bool immediate_callback_{false};
0156 
0157     /// This is a function that runs prior to the start of parsing
0158     std::function<void(std::size_t)> pre_parse_callback_{};
0159 
0160     /// This is a function that runs when parsing has finished.
0161     std::function<void()> parse_complete_callback_{};
0162 
0163     /// This is a function that runs when all processing has completed
0164     std::function<void()> final_callback_{};
0165 
0166     ///@}
0167     /// @name Options
0168     ///@{
0169 
0170     /// The default values for options, customizable and changeable INHERITABLE
0171     OptionDefaults option_defaults_{};
0172 
0173     /// The list of options, stored locally
0174     std::vector<Option_p> options_{};
0175 
0176     ///@}
0177     /// @name Help
0178     ///@{
0179 
0180     /// Usage to put after program/subcommand description in the help output INHERITABLE
0181     std::string usage_{};
0182 
0183     /// This is a function that generates a usage to put after program/subcommand description in help output
0184     std::function<std::string()> usage_callback_{};
0185 
0186     /// Footer to put after all options in the help output INHERITABLE
0187     std::string footer_{};
0188 
0189     /// This is a function that generates a footer to put after all other options in help output
0190     std::function<std::string()> footer_callback_{};
0191 
0192     /// A pointer to the help flag if there is one INHERITABLE
0193     Option *help_ptr_{nullptr};
0194 
0195     /// A pointer to the help all flag if there is one INHERITABLE
0196     Option *help_all_ptr_{nullptr};
0197 
0198     /// A pointer to a version flag if there is one
0199     Option *version_ptr_{nullptr};
0200 
0201     /// This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
0202     std::shared_ptr<FormatterBase> formatter_{new Formatter()};
0203 
0204     /// The error message printing function INHERITABLE
0205     std::function<std::string(const App *, const Error &e)> failure_message_{FailureMessage::simple};
0206 
0207     ///@}
0208     /// @name Parsing
0209     ///@{
0210 
0211     using missing_t = std::vector<std::pair<detail::Classifier, std::string>>;
0212 
0213     /// Pair of classifier, string for missing options. (extra detail is removed on returning from parse)
0214     ///
0215     /// This is faster and cleaner than storing just a list of strings and reparsing. This may contain the -- separator.
0216     missing_t missing_{};
0217 
0218     /// This is a list of pointers to options with the original parse order
0219     std::vector<Option *> parse_order_{};
0220 
0221     /// This is a list of the subcommands collected, in order
0222     std::vector<App *> parsed_subcommands_{};
0223 
0224     /// this is a list of subcommands that are exclusionary to this one
0225     std::set<App *> exclude_subcommands_{};
0226 
0227     /// This is a list of options which are exclusionary to this App, if the options were used this subcommand should
0228     /// not be
0229     std::set<Option *> exclude_options_{};
0230 
0231     /// this is a list of subcommands or option groups that are required by this one, the list is not mutual,  the
0232     /// listed subcommands do not require this one
0233     std::set<App *> need_subcommands_{};
0234 
0235     /// This is a list of options which are required by this app, the list is not mutual, listed options do not need the
0236     /// subcommand not be
0237     std::set<Option *> need_options_{};
0238 
0239     ///@}
0240     /// @name Subcommands
0241     ///@{
0242 
0243     /// Storage for subcommand list
0244     std::vector<App_p> subcommands_{};
0245 
0246     /// If true, the program name is not case-sensitive INHERITABLE
0247     bool ignore_case_{false};
0248 
0249     /// If true, the program should ignore underscores INHERITABLE
0250     bool ignore_underscore_{false};
0251 
0252     /// Allow options or other arguments to fallthrough, so that parent commands can collect options after subcommand.
0253     /// INHERITABLE
0254     bool fallthrough_{false};
0255 
0256     /// Allow subcommands to fallthrough, so that parent commands can trigger other subcommands after subcommand.
0257     bool subcommand_fallthrough_{true};
0258 
0259     /// Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise. INHERITABLE
0260     bool allow_windows_style_options_{
0261 #ifdef _WIN32
0262         true
0263 #else
0264         false
0265 #endif
0266     };
0267     /// specify that positional arguments come at the end of the argument sequence not inheritable
0268     bool positionals_at_end_{false};
0269 
0270     enum class startup_mode : std::uint8_t { stable, enabled, disabled };
0271     /// specify the startup mode for the app
0272     /// stable=no change, enabled= startup enabled, disabled=startup disabled
0273     startup_mode default_startup{startup_mode::stable};
0274 
0275     /// if set to true the subcommand can be triggered via configuration files INHERITABLE
0276     bool configurable_{false};
0277 
0278     /// If set to true positional options are validated before assigning INHERITABLE
0279     bool validate_positionals_{false};
0280 
0281     /// If set to true optional vector arguments are validated before assigning INHERITABLE
0282     bool validate_optional_arguments_{false};
0283 
0284     /// indicator that the subcommand is silent and won't show up in subcommands list
0285     /// This is potentially useful as a modifier subcommand
0286     bool silent_{false};
0287 
0288     /// indicator that the subcommand should allow non-standard option arguments, such as -single_dash_flag
0289     bool allow_non_standard_options_{false};
0290 
0291     /// indicator to allow subcommands to match with prefix matching
0292     bool allow_prefix_matching_{false};
0293 
0294     /// Counts the number of times this command/subcommand was parsed
0295     std::uint32_t parsed_{0U};
0296 
0297     /// Minimum required subcommands (not inheritable!)
0298     std::size_t require_subcommand_min_{0};
0299 
0300     /// Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE
0301     std::size_t require_subcommand_max_{0};
0302 
0303     /// Minimum required options (not inheritable!)
0304     std::size_t require_option_min_{0};
0305 
0306     /// Max number of options allowed. 0 is unlimited (not inheritable)
0307     std::size_t require_option_max_{0};
0308 
0309     /// A pointer to the parent if this is a subcommand
0310     App *parent_{nullptr};
0311 
0312     /// The group membership INHERITABLE
0313     std::string group_{"SUBCOMMANDS"};
0314 
0315     /// Alias names for the subcommand
0316     std::vector<std::string> aliases_{};
0317 
0318     ///@}
0319     /// @name Config
0320     ///@{
0321 
0322     /// Pointer to the config option
0323     Option *config_ptr_{nullptr};
0324 
0325     /// This is the formatter for help printing. Default provided. INHERITABLE (same pointer)
0326     std::shared_ptr<Config> config_formatter_{new ConfigTOML()};
0327 
0328     ///@}
0329 
0330 #ifdef _WIN32
0331     /// When normalizing argv to UTF-8 on Windows, this is the storage for normalized args.
0332     std::vector<std::string> normalized_argv_{};
0333 
0334     /// When normalizing argv to UTF-8 on Windows, this is the `char**` value returned to the user.
0335     std::vector<char *> normalized_argv_view_{};
0336 #endif
0337 
0338     /// Special private constructor for subcommand
0339     App(std::string app_description, std::string app_name, App *parent);
0340 
0341   public:
0342     /// @name Basic
0343     ///@{
0344 
0345     /// Create a new program. Pass in the same arguments as main(), along with a help string.
0346     explicit App(std::string app_description = "", std::string app_name = "")
0347         : App(app_description, app_name, nullptr) {
0348         set_help_flag("-h,--help", "Print this help message and exit");
0349     }
0350 
0351     App(const App &) = delete;
0352     App &operator=(const App &) = delete;
0353 
0354     /// virtual destructor
0355     virtual ~App() = default;
0356 
0357     /// Convert the contents of argv to UTF-8. Only does something on Windows, does nothing elsewhere.
0358     CLI11_NODISCARD char **ensure_utf8(char **argv);
0359 
0360     /// Set a callback for execution when all parsing and processing has completed
0361     ///
0362     /// Due to a bug in c++11,
0363     /// it is not possible to overload on std::function (fixed in c++14
0364     /// and backported to c++11 on newer compilers). Use capture by reference
0365     /// to get a pointer to App if needed.
0366     App *callback(std::function<void()> app_callback) {
0367         if(immediate_callback_) {
0368             parse_complete_callback_ = std::move(app_callback);
0369         } else {
0370             final_callback_ = std::move(app_callback);
0371         }
0372         return this;
0373     }
0374 
0375     /// Set a callback for execution when all parsing and processing has completed
0376     /// aliased as callback
0377     App *final_callback(std::function<void()> app_callback) {
0378         final_callback_ = std::move(app_callback);
0379         return this;
0380     }
0381 
0382     /// Set a callback to execute when parsing has completed for the app
0383     ///
0384     App *parse_complete_callback(std::function<void()> pc_callback) {
0385         parse_complete_callback_ = std::move(pc_callback);
0386         return this;
0387     }
0388 
0389     /// Set a callback to execute prior to parsing.
0390     ///
0391     App *preparse_callback(std::function<void(std::size_t)> pp_callback) {
0392         pre_parse_callback_ = std::move(pp_callback);
0393         return this;
0394     }
0395 
0396     /// Set a name for the app (empty will use parser to set the name)
0397     App *name(std::string app_name = "");
0398 
0399     /// Set an alias for the app
0400     App *alias(std::string app_name);
0401 
0402     /// Remove the error when extras are left over on the command line.
0403     App *allow_extras(bool allow = true) {
0404         allow_extras_ = allow ? ExtrasMode::Capture : ExtrasMode::Error;
0405         return this;
0406     }
0407 
0408     /// Remove the error when extras are left over on the command line.
0409     App *allow_extras(ExtrasMode allow) {
0410         allow_extras_ = allow;
0411         return this;
0412     }
0413 
0414     /// Set whether this subcommand/option-group is required to be present on the command line.
0415     App *required(bool require = true) {
0416         required_ = require;
0417         return this;
0418     }
0419 
0420     /// Disable the subcommand or option group
0421     App *disabled(bool disable = true) {
0422         disabled_ = disable;
0423         return this;
0424     }
0425 
0426     /// silence the subcommand from showing up in the processed list
0427     App *silent(bool silence = true) {
0428         silent_ = silence;
0429         return this;
0430     }
0431 
0432     /// allow non standard option names
0433     App *allow_non_standard_option_names(bool allowed = true) {
0434         allow_non_standard_options_ = allowed;
0435         return this;
0436     }
0437 
0438     /// allow prefix matching for subcommands
0439     App *allow_subcommand_prefix_matching(bool allowed = true) {
0440         allow_prefix_matching_ = allowed;
0441         return this;
0442     }
0443     /// Set the subcommand to be disabled by default, so on clear(), at the start of each parse it is disabled
0444     App *disabled_by_default(bool disable = true) {
0445         if(disable) {
0446             default_startup = startup_mode::disabled;
0447         } else {
0448             default_startup = (default_startup == startup_mode::enabled) ? startup_mode::enabled : startup_mode::stable;
0449         }
0450         return this;
0451     }
0452 
0453     /// Set the subcommand to be enabled by default, so on clear(), at the start of each parse it is enabled (not
0454     /// disabled)
0455     App *enabled_by_default(bool enable = true) {
0456         if(enable) {
0457             default_startup = startup_mode::enabled;
0458         } else {
0459             default_startup =
0460                 (default_startup == startup_mode::disabled) ? startup_mode::disabled : startup_mode::stable;
0461         }
0462         return this;
0463     }
0464 
0465     /// Set the subcommand callback to be executed immediately on subcommand completion
0466     App *immediate_callback(bool immediate = true);
0467 
0468     /// Set the subcommand to validate positional arguments before assigning
0469     App *validate_positionals(bool validate = true) {
0470         validate_positionals_ = validate;
0471         return this;
0472     }
0473 
0474     /// Set the subcommand to validate optional vector arguments before assigning
0475     App *validate_optional_arguments(bool validate = true) {
0476         validate_optional_arguments_ = validate;
0477         return this;
0478     }
0479 
0480     /// ignore extras in config files
0481     App *allow_config_extras(bool allow = true) {
0482         if(allow) {
0483             allow_config_extras_ = ConfigExtrasMode::Capture;
0484             allow_extras_ = ExtrasMode::Capture;
0485         } else {
0486             allow_config_extras_ = ConfigExtrasMode::Error;
0487         }
0488         return this;
0489     }
0490 
0491     /// ignore extras in config files
0492     App *allow_config_extras(config_extras_mode mode) {
0493         allow_config_extras_ = static_cast<ConfigExtrasMode>(mode);
0494         return this;
0495     }
0496 
0497     /// ignore extras in config files
0498     App *allow_config_extras(ConfigExtrasMode mode) {
0499         allow_config_extras_ = mode;
0500         return this;
0501     }
0502 
0503     /// Enable or disable prefix command mode. If enabled, parsing stops at the
0504     /// first unrecognized option and all remaining arguments are stored in
0505     /// remaining args. Use PrefixCommandMode::PositionalOnly to only stop at
0506     /// positional arguments (or the `--` separator).
0507     App *prefix_command(bool is_prefix = true) {
0508         prefix_command_ = is_prefix ? PrefixCommandMode::On : PrefixCommandMode::Off;
0509         return this;
0510     }
0511 
0512     /// Set the prefix command mode directly.
0513     App *prefix_command(PrefixCommandMode mode) {
0514         prefix_command_ = mode;
0515         return this;
0516     }
0517 
0518     /// Ignore case. Subcommands inherit value.
0519     App *ignore_case(bool value = true);
0520 
0521     /// Allow windows style options, such as `/opt`. First matching short or long name used. Subcommands inherit
0522     /// value.
0523     App *allow_windows_style_options(bool value = true) {
0524         allow_windows_style_options_ = value;
0525         return this;
0526     }
0527 
0528     /// Specify that the positional arguments are only at the end of the sequence
0529     App *positionals_at_end(bool value = true) {
0530         positionals_at_end_ = value;
0531         return this;
0532     }
0533 
0534     /// Specify that the subcommand can be triggered by a config file
0535     App *configurable(bool value = true) {
0536         configurable_ = value;
0537         return this;
0538     }
0539 
0540     /// Ignore underscore. Subcommands inherit value.
0541     App *ignore_underscore(bool value = true);
0542 
0543     /// Set the help formatter
0544     App *formatter(std::shared_ptr<FormatterBase> fmt) {
0545         formatter_ = std::move(fmt);
0546         return this;
0547     }
0548 
0549     /// Set the help formatter
0550     App *formatter_fn(std::function<std::string(const App *, std::string, AppFormatMode)> fmt) {
0551         formatter_ = std::make_shared<FormatterLambda>(fmt);
0552         return this;
0553     }
0554 
0555     /// Set the config formatter
0556     App *config_formatter(std::shared_ptr<Config> fmt) {
0557         config_formatter_ = std::move(fmt);
0558         return this;
0559     }
0560 
0561     /// Check to see if this subcommand was parsed, true only if received on command line.
0562     CLI11_NODISCARD bool parsed() const { return parsed_ > 0; }
0563 
0564     /// Get the OptionDefault object, to set option defaults
0565     OptionDefaults *option_defaults() { return &option_defaults_; }
0566 
0567     ///@}
0568     /// @name Adding options
0569     ///@{
0570 
0571     /// Add an option, will automatically understand the type for common types.
0572     ///
0573     /// To use, create a variable with the expected type, and pass it in after the name.
0574     /// After start is called, you can use count to see if the value was passed, and
0575     /// the value will be initialized properly. Numbers, vectors, and strings are supported.
0576     ///
0577     /// ->required(), ->default, and the validators are options,
0578     /// The positional options take an optional number of arguments.
0579     ///
0580     /// For example,
0581     ///
0582     ///     std::string filename;
0583     ///     program.add_option("filename", filename, "description of filename");
0584     ///
0585     Option *add_option(std::string option_name,
0586                        callback_t option_callback,
0587                        std::string option_description = "",
0588                        bool defaulted = false,
0589                        std::function<std::string()> func = {});
0590 
0591     /// Add option for assigning to a variable
0592     template <typename AssignTo,
0593               typename ConvertTo = AssignTo,
0594               enable_if_t<!std::is_const<ConvertTo>::value, detail::enabler> = detail::dummy>
0595     Option *add_option(std::string option_name,
0596                        AssignTo &variable,  ///< The variable to set
0597                        std::string option_description = "") {
0598 
0599         auto fun = [&variable](const CLI::results_t &res) {  // comment for spacing
0600             return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
0601         };
0602 
0603         Option *opt = add_option(option_name, fun, option_description, false, [&variable]() {
0604             return CLI::detail::checked_to_string<AssignTo, ConvertTo>(variable);
0605         });
0606         opt->type_name(detail::type_name<ConvertTo>());
0607         // these must be actual lvalues since (std::max) sometimes is defined in terms of references and references
0608         // to structs used in the evaluation can be temporary so that would cause issues.
0609         auto Tcount = detail::type_count<AssignTo>::value;
0610         auto XCcount = detail::type_count<ConvertTo>::value;
0611         opt->type_size(detail::type_count_min<ConvertTo>::value, (std::max)(Tcount, XCcount));
0612         opt->expected(detail::expected_count<ConvertTo>::value);
0613         opt->run_callback_for_default();
0614         return opt;
0615     }
0616 
0617     /// Add option for assigning to a variable
0618     template <typename AssignTo, enable_if_t<!std::is_const<AssignTo>::value, detail::enabler> = detail::dummy>
0619     Option *add_option_no_stream(std::string option_name,
0620                                  AssignTo &variable,  ///< The variable to set
0621                                  std::string option_description = "") {
0622 
0623         auto fun = [&variable](const CLI::results_t &res) {  // comment for spacing
0624             return detail::lexical_conversion<AssignTo, AssignTo>(res, variable);
0625         };
0626 
0627         Option *opt = add_option(option_name, fun, option_description, false, []() { return std::string{}; });
0628         opt->type_name(detail::type_name<AssignTo>());
0629         opt->type_size(detail::type_count_min<AssignTo>::value, detail::type_count<AssignTo>::value);
0630         opt->expected(detail::expected_count<AssignTo>::value);
0631         opt->run_callback_for_default();
0632         return opt;
0633     }
0634 
0635     /// Add option for a callback of a specific type
0636     template <typename ArgType>
0637     Option *add_option_function(std::string option_name,
0638                                 const std::function<void(const ArgType &)> &func,  ///< the callback to execute
0639                                 std::string option_description = "") {
0640 
0641         auto fun = [func](const CLI::results_t &res) {
0642             ArgType variable;
0643             bool result = detail::lexical_conversion<ArgType, ArgType>(res, variable);
0644             if(result) {
0645                 func(variable);
0646             }
0647             return result;
0648         };
0649 
0650         Option *opt = add_option(option_name, std::move(fun), option_description, false);
0651         opt->type_name(detail::type_name<ArgType>());
0652         opt->type_size(detail::type_count_min<ArgType>::value, detail::type_count<ArgType>::value);
0653         opt->expected(detail::expected_count<ArgType>::value);
0654         return opt;
0655     }
0656 
0657     /// Add option with no description or variable assignment
0658     Option *add_option(std::string option_name) {
0659         return add_option(option_name, CLI::callback_t{}, std::string{}, false);
0660     }
0661 
0662     /// Add option with description but with no variable assignment or callback
0663     template <typename T,
0664               enable_if_t<std::is_const<T>::value && std::is_constructible<std::string, T>::value, detail::enabler> =
0665                   detail::dummy>
0666     Option *add_option(std::string option_name, T &option_description) {
0667         return add_option(option_name, CLI::callback_t(), option_description, false);
0668     }
0669 
0670     /// Set a help flag, replace the existing one if present
0671     Option *set_help_flag(std::string flag_name = "", const std::string &help_description = "");
0672 
0673     /// Set a help all flag, replaced the existing one if present
0674     Option *set_help_all_flag(std::string help_name = "", const std::string &help_description = "");
0675 
0676     /// Set a version flag and version display string, replace the existing one if present
0677     Option *set_version_flag(std::string flag_name = "",
0678                              const std::string &versionString = "",
0679                              const std::string &version_help = "Display program version information and exit");
0680 
0681     /// Generate the version string through a callback function
0682     Option *set_version_flag(std::string flag_name,
0683                              std::function<std::string()> vfunc,
0684                              const std::string &version_help = "Display program version information and exit");
0685 
0686   private:
0687     /// Internal function for adding a flag
0688     Option *_add_flag_internal(std::string flag_name, CLI::callback_t fun, std::string flag_description);
0689 
0690   public:
0691     /// Add a flag with no description or variable assignment
0692     Option *add_flag(std::string flag_name) { return _add_flag_internal(flag_name, CLI::callback_t(), std::string{}); }
0693 
0694     /// Add flag with description but with no variable assignment or callback
0695     /// takes a constant string or a rvalue reference to a string,  if a variable string is passed that variable will be
0696     /// assigned the results from the flag
0697     template <typename T,
0698               enable_if_t<(std::is_const<typename std::remove_reference<T>::type>::value ||
0699                            std::is_rvalue_reference<T &&>::value) &&
0700                               std::is_constructible<std::string, typename std::remove_reference<T>::type>::value,
0701                           detail::enabler> = detail::dummy>
0702     Option *add_flag(std::string flag_name, T &&flag_description) {
0703         return _add_flag_internal(flag_name, CLI::callback_t(), std::forward<T>(flag_description));
0704     }
0705 
0706     /// Other type version accepts all other types that are not vectors such as bool, enum, string or other classes
0707     /// that can be converted from a string
0708     template <typename T,
0709               enable_if_t<!detail::is_mutable_container<T>::value && !std::is_const<T>::value &&
0710                               !std::is_constructible<std::function<void(int)>, T>::value,
0711                           detail::enabler> = detail::dummy>
0712     Option *add_flag(std::string flag_name,
0713                      T &flag_result,  ///< A variable holding the flag result
0714                      std::string flag_description = "") {
0715 
0716         CLI::callback_t fun = [&flag_result](const CLI::results_t &res) {
0717             using CLI::detail::lexical_cast;
0718             return lexical_cast(res[0], flag_result);
0719         };
0720         auto *opt = _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
0721         return detail::default_flag_modifiers<T>(opt);
0722     }
0723 
0724     /// Vector version to capture multiple flags.
0725     template <typename T,
0726               enable_if_t<!std::is_assignable<std::function<void(std::int64_t)> &, T>::value, detail::enabler> =
0727                   detail::dummy>
0728     Option *add_flag(std::string flag_name,
0729                      std::vector<T> &flag_results,  ///< A vector of values with the flag results
0730                      std::string flag_description = "") {
0731         CLI::callback_t fun = [&flag_results](const CLI::results_t &res) {
0732             bool retval = true;
0733             for(const auto &elem : res) {
0734                 using CLI::detail::lexical_cast;
0735                 flag_results.emplace_back();
0736                 retval &= lexical_cast(elem, flag_results.back());
0737             }
0738             return retval;
0739         };
0740         return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
0741             ->multi_option_policy(MultiOptionPolicy::TakeAll)
0742             ->run_callback_for_default();
0743     }
0744 
0745     /// Add option for callback that is triggered with a true flag and takes no arguments
0746     Option *add_flag_callback(std::string flag_name,
0747                               std::function<void(void)> function,  ///< A function to call, void(void)
0748                               std::string flag_description = "");
0749 
0750     /// Add option for callback with an integer value
0751     Option *add_flag_function(std::string flag_name,
0752                               std::function<void(std::int64_t)> function,  ///< A function to call, void(int)
0753                               std::string flag_description = "");
0754 
0755 #ifdef CLI11_CPP14
0756     /// Add option for callback (C++14 or better only)
0757     Option *add_flag(std::string flag_name,
0758                      std::function<void(std::int64_t)> function,  ///< A function to call, void(std::int64_t)
0759                      std::string flag_description = "") {
0760         return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description));
0761     }
0762 #endif
0763 
0764     /// Set a configuration ini file option, or clear it if no name passed
0765     Option *set_config(std::string option_name = "",
0766                        std::string default_filename = "",
0767                        const std::string &help_message = "Read an ini file",
0768                        bool config_required = false);
0769 
0770     /// Removes an option from the App. Takes an option pointer. Returns true if found and removed.
0771     bool remove_option(Option *opt);
0772 
0773     /// creates an option group as part of the given app
0774     template <typename T = Option_group>
0775     T *add_option_group(std::string group_name, std::string group_description = "") {
0776         if(!detail::valid_alias_name_string(group_name)) {
0777             throw IncorrectConstruction("option group names may not contain newlines or null characters");
0778         }
0779         auto option_group = std::make_shared<T>(std::move(group_description), group_name, this);
0780         option_group->fallthrough(false);
0781         auto *ptr = option_group.get();
0782         // move to App_p for overload resolution on older gcc versions
0783         App_p app_ptr = std::static_pointer_cast<App>(option_group);
0784         // don't inherit the footer in option groups and clear the help flag by default
0785         app_ptr->footer_ = "";
0786         app_ptr->set_help_flag();
0787         add_subcommand(std::move(app_ptr));
0788         return ptr;
0789     }
0790 
0791     ///@}
0792     /// @name Subcommands
0793     ///@{
0794 
0795     /// Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag
0796     App *add_subcommand(std::string subcommand_name = "", std::string subcommand_description = "");
0797 
0798     /// Add a previously created app as a subcommand
0799     App *add_subcommand(CLI::App_p subcom);
0800 
0801     /// Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed.
0802     bool remove_subcommand(App *subcom);
0803 
0804     /// Check to see if a subcommand is part of this command (doesn't have to be in command line)
0805     /// returns the first subcommand if passed a nullptr
0806     App *get_subcommand(const App *subcom) const;
0807 
0808     /// Check to see if a subcommand is part of this command (text version)
0809     CLI11_NODISCARD App *get_subcommand(std::string subcom) const;
0810 
0811     /// Get a subcommand by name (noexcept non-const version)
0812     /// returns null if subcommand doesn't exist
0813     CLI11_NODISCARD App *get_subcommand_no_throw(std::string subcom) const noexcept;
0814 
0815     /// Get a pointer to subcommand by index
0816     CLI11_NODISCARD App *get_subcommand(int index = 0) const;
0817 
0818     /// Check to see if a subcommand is part of this command and get a shared_ptr to it
0819     CLI::App_p get_subcommand_ptr(App *subcom) const;
0820 
0821     /// Check to see if a subcommand is part of this command (text version)
0822     CLI11_NODISCARD CLI::App_p get_subcommand_ptr(std::string subcom) const;
0823 
0824     /// Get an owning pointer to subcommand by index
0825     CLI11_NODISCARD CLI::App_p get_subcommand_ptr(int index = 0) const;
0826 
0827     /// Check to see if an option group is part of this App
0828     CLI11_NODISCARD App *get_option_group(std::string group_name) const;
0829 
0830     /// No argument version of count counts the number of times this subcommand was
0831     /// passed in. The main app will return 1. Unnamed subcommands will also return 1 unless
0832     /// otherwise modified in a callback
0833     CLI11_NODISCARD std::size_t count() const { return parsed_; }
0834 
0835     /// Get a count of all the arguments processed in options and subcommands, this excludes arguments which were
0836     /// treated as extras.
0837     CLI11_NODISCARD std::size_t count_all() const;
0838 
0839     /// Changes the group membership
0840     App *group(std::string group_name) {
0841         group_ = std::move(group_name);
0842         return this;
0843     }
0844 
0845     /// The argumentless form of require subcommand requires 1 or more subcommands
0846     App *require_subcommand() {
0847         require_subcommand_min_ = 1;
0848         require_subcommand_max_ = 0;
0849         return this;
0850     }
0851 
0852     /// Require a subcommand to be given (does not affect help call)
0853     /// The number required can be given. Negative values indicate maximum
0854     /// number allowed (0 for any number). Max number inheritable.
0855     App *require_subcommand(int value) {
0856         if(value < 0) {
0857             require_subcommand_min_ = 0;
0858             require_subcommand_max_ = static_cast<std::size_t>(-value);
0859         } else {
0860             require_subcommand_min_ = static_cast<std::size_t>(value);
0861             require_subcommand_max_ = static_cast<std::size_t>(value);
0862         }
0863         return this;
0864     }
0865 
0866     /// Explicitly control the number of subcommands required. Setting 0
0867     /// for the max means unlimited number allowed. Max number inheritable.
0868     App *require_subcommand(std::size_t min, std::size_t max) {
0869         require_subcommand_min_ = min;
0870         require_subcommand_max_ = max;
0871         return this;
0872     }
0873 
0874     /// The argumentless form of require option requires 1 or more options be used
0875     App *require_option() {
0876         require_option_min_ = 1;
0877         require_option_max_ = 0;
0878         return this;
0879     }
0880 
0881     /// Require an option to be given (does not affect help call)
0882     /// The number required can be given. Negative values indicate maximum
0883     /// number allowed (0 for any number).
0884     App *require_option(int value) {
0885         if(value < 0) {
0886             require_option_min_ = 0;
0887             require_option_max_ = static_cast<std::size_t>(-value);
0888         } else {
0889             require_option_min_ = static_cast<std::size_t>(value);
0890             require_option_max_ = static_cast<std::size_t>(value);
0891         }
0892         return this;
0893     }
0894 
0895     /// Explicitly control the number of options required. Setting 0
0896     /// for the max means unlimited number allowed. Max number inheritable.
0897     App *require_option(std::size_t min, std::size_t max) {
0898         require_option_min_ = min;
0899         require_option_max_ = max;
0900         return this;
0901     }
0902 
0903     /// Set fallthrough, set to true so that options will fallthrough to parent if not recognized in a subcommand
0904     /// Default from parent, usually set on parent.
0905     App *fallthrough(bool value = true) {
0906         fallthrough_ = value;
0907         return this;
0908     }
0909 
0910     /// Set subcommand fallthrough, set to true so that subcommands on parents are recognized
0911     App *subcommand_fallthrough(bool value = true) {
0912         subcommand_fallthrough_ = value;
0913         return this;
0914     }
0915 
0916     /// Check to see if this subcommand was parsed, true only if received on command line.
0917     /// This allows the subcommand to be directly checked.
0918     explicit operator bool() const { return parsed_ > 0; }
0919 
0920     ///@}
0921     /// @name Extras for subclassing
0922     ///@{
0923 
0924     /// This allows subclasses to inject code before callbacks but after parse.
0925     ///
0926     /// This does not run if any errors or help is thrown.
0927     virtual void pre_callback() {}
0928 
0929     ///@}
0930     /// @name Parsing
0931     ///@{
0932     //
0933     /// Reset the parsed data
0934     void clear();
0935 
0936     /// Parses the command line - throws errors.
0937     /// This must be called after the options are in but before the rest of the program.
0938     void parse(int argc, const char *const *argv);
0939     void parse(int argc, const wchar_t *const *argv);
0940 
0941   private:
0942     template <class CharT> void parse_char_t(int argc, const CharT *const *argv);
0943 
0944   public:
0945     /// Parse a single string as if it contained command line arguments.
0946     /// This function splits the string into arguments then calls parse(std::vector<std::string> &)
0947     /// the function takes an optional boolean argument specifying if the programName is included in the string to
0948     /// process
0949     void parse(std::string commandline, bool program_name_included = false);
0950     void parse(std::wstring commandline, bool program_name_included = false);
0951 
0952     /// The real work is done here. Expects a reversed vector.
0953     /// Changes the vector to the remaining options.
0954     void parse(std::vector<std::string> &args);
0955 
0956     /// The real work is done here. Expects a reversed vector.
0957     void parse(std::vector<std::string> &&args);
0958 
0959     void parse_from_stream(std::istream &input);
0960 
0961     /// Provide a function to print a help message. The function gets access to the App pointer and error.
0962     void failure_message(std::function<std::string(const App *, const Error &e)> function) {
0963         failure_message_ = std::move(function);
0964     }
0965 
0966     /// Print a nice error message and return the exit code
0967     int exit(const Error &e, std::ostream &out = std::cout, std::ostream &err = std::cerr) const;
0968 
0969     ///@}
0970     /// @name Post parsing
0971     ///@{
0972 
0973     /// Counts the number of times the given option was passed.
0974     CLI11_NODISCARD std::size_t count(std::string option_name) const { return get_option(option_name)->count(); }
0975 
0976     /// Get a subcommand pointer list to the currently selected subcommands (after parsing by default, in command
0977     /// line order; use parsed = false to get the original definition list.)
0978     CLI11_NODISCARD std::vector<App *> get_subcommands() const { return parsed_subcommands_; }
0979 
0980     /// Get a filtered subcommand pointer list from the original definition list. An empty function will provide all
0981     /// subcommands (const)
0982     std::vector<const App *> get_subcommands(const std::function<bool(const App *)> &filter) const;
0983 
0984     /// Get a filtered subcommand pointer list from the original definition list. An empty function will provide all
0985     /// subcommands
0986     std::vector<App *> get_subcommands(const std::function<bool(App *)> &filter);
0987 
0988     /// Check to see if given subcommand was selected
0989     bool got_subcommand(const App *subcom) const {
0990         // get subcom needed to verify that this was a real subcommand
0991         return get_subcommand(subcom)->parsed_ > 0;
0992     }
0993 
0994     /// Check with name instead of pointer to see if subcommand was selected
0995     CLI11_NODISCARD bool got_subcommand(std::string subcommand_name) const noexcept {
0996         App *sub = get_subcommand_no_throw(subcommand_name);
0997         return (sub != nullptr) ? (sub->parsed_ > 0) : false;
0998     }
0999 
1000     /// Sets excluded options for the subcommand
1001     App *excludes(Option *opt) {
1002         if(opt == nullptr) {
1003             throw OptionNotFound("nullptr passed");
1004         }
1005         exclude_options_.insert(opt);
1006         return this;
1007     }
1008 
1009     /// Sets excluded subcommands for the subcommand
1010     App *excludes(App *app) {
1011         if(app == nullptr) {
1012             throw OptionNotFound("nullptr passed");
1013         }
1014         if(app == this) {
1015             throw OptionNotFound("cannot self reference in excludes");
1016         }
1017         auto res = exclude_subcommands_.insert(app);
1018         // subcommand exclusion should be symmetric
1019         if(res.second) {
1020             app->exclude_subcommands_.insert(this);
1021         }
1022         return this;
1023     }
1024 
1025     App *needs(Option *opt) {
1026         if(opt == nullptr) {
1027             throw OptionNotFound("nullptr passed");
1028         }
1029         need_options_.insert(opt);
1030         return this;
1031     }
1032 
1033     App *needs(App *app) {
1034         if(app == nullptr) {
1035             throw OptionNotFound("nullptr passed");
1036         }
1037         if(app == this) {
1038             throw OptionNotFound("cannot self reference in needs");
1039         }
1040         need_subcommands_.insert(app);
1041         return this;
1042     }
1043 
1044     /// Removes an option from the excludes list of this subcommand
1045     bool remove_excludes(Option *opt);
1046 
1047     /// Removes a subcommand from the excludes list of this subcommand
1048     bool remove_excludes(App *app);
1049 
1050     /// Removes an option from the needs list of this subcommand
1051     bool remove_needs(Option *opt);
1052 
1053     /// Removes a subcommand from the needs list of this subcommand
1054     bool remove_needs(App *app);
1055     ///@}
1056     /// @name Help
1057     ///@{
1058 
1059     /// Set usage.
1060     App *usage(std::string usage_string) {
1061         usage_ = std::move(usage_string);
1062         return this;
1063     }
1064     /// Set usage.
1065     App *usage(std::function<std::string()> usage_function) {
1066         usage_callback_ = std::move(usage_function);
1067         return this;
1068     }
1069     /// Set footer.
1070     App *footer(std::string footer_string) {
1071         footer_ = std::move(footer_string);
1072         return this;
1073     }
1074     /// Set footer.
1075     App *footer(std::function<std::string()> footer_function) {
1076         footer_callback_ = std::move(footer_function);
1077         return this;
1078     }
1079     /// Produce a string that could be read in as a config of the current values of the App. Set default_also to
1080     /// include default arguments. write_descriptions will print a description for the App and for each option.
1081     CLI11_NODISCARD std::string config_to_str() const { return config_to_str(ConfigOutputMode::Active, false); }
1082 
1083     /// Produce a string that could be read in as a config of the current values of the App.
1084     CLI11_NODISCARD std::string config_to_str(ConfigOutputMode mode, bool write_description = false) const {
1085         return config_formatter_->to_config(this, mode, write_description, "");
1086     }
1087 
1088     /// Produce a string that could be read in as a config of the current values of the App. Set default_also to
1089     /// include default arguments. write_descriptions will print a description for the App and for each option.
1090     /// This will be deprecated soon, use the version that takes a ConfigOutputMode instead.
1091     CLI11_NODISCARD std::string config_to_str(bool default_also, bool write_description = false) const {
1092         return config_to_str(default_also ? ConfigOutputMode::AllDefaults : ConfigOutputMode::Active,
1093                              write_description);
1094     }
1095 
1096     /// Makes a help message, using the currently configured formatter
1097     /// Will only do one subcommand at a time
1098     CLI11_NODISCARD std::string help(std::string prev = "", AppFormatMode mode = AppFormatMode::Normal) const;
1099 
1100     /// Displays a version string
1101     CLI11_NODISCARD std::string version() const;
1102     ///@}
1103     /// @name Getters
1104     ///@{
1105 
1106     /// Access the formatter
1107     CLI11_NODISCARD std::shared_ptr<FormatterBase> get_formatter() const { return formatter_; }
1108 
1109     /// Access the config formatter
1110     CLI11_NODISCARD std::shared_ptr<Config> get_config_formatter() const { return config_formatter_; }
1111 
1112     /// Access the config formatter as a configBase pointer
1113     CLI11_NODISCARD std::shared_ptr<ConfigBase> get_config_formatter_base() const {
1114         // This is safer as a dynamic_cast if we have RTTI, as Config -> ConfigBase
1115 #if CLI11_USE_STATIC_RTTI == 0
1116         return std::dynamic_pointer_cast<ConfigBase>(config_formatter_);
1117 #else
1118         return std::static_pointer_cast<ConfigBase>(config_formatter_);
1119 #endif
1120     }
1121 
1122     /// Get the app or subcommand description
1123     CLI11_NODISCARD std::string get_description() const { return description_; }
1124 
1125     /// Set the description of the app
1126     App *description(std::string app_description) {
1127         description_ = std::move(app_description);
1128         return this;
1129     }
1130 
1131     /// Get the list of options (user facing function, so returns raw pointers), has optional filter function
1132     std::vector<const Option *> get_options(const std::function<bool(const Option *)> filter = {}) const;
1133 
1134     /// Non-const version of the above
1135     std::vector<Option *> get_options(const std::function<bool(Option *)> filter = {});
1136 
1137     /// Get an option by name (noexcept non-const version)
1138     CLI11_NODISCARD Option *get_option_no_throw(std::string option_name) noexcept;
1139 
1140     /// Get an option by name (noexcept const version)
1141     CLI11_NODISCARD const Option *get_option_no_throw(std::string option_name) const noexcept;
1142 
1143     /// Get an option by name
1144     CLI11_NODISCARD const Option *get_option(std::string option_name) const;
1145 
1146     /// Get an option by name (non-const version)
1147     CLI11_NODISCARD Option *get_option(std::string option_name);
1148 
1149     /// Shortcut bracket operator for getting a pointer to an option
1150     const Option *operator[](const std::string &option_name) const { return get_option(option_name); }
1151 
1152     /// Shortcut bracket operator for getting a pointer to an option
1153     const Option *operator[](const char *option_name) const { return get_option(option_name); }
1154 
1155     /// Check the status of ignore_case
1156     CLI11_NODISCARD bool get_ignore_case() const { return ignore_case_; }
1157 
1158     /// Check the status of ignore_underscore
1159     CLI11_NODISCARD bool get_ignore_underscore() const { return ignore_underscore_; }
1160 
1161     /// Check the status of fallthrough
1162     CLI11_NODISCARD bool get_fallthrough() const { return fallthrough_; }
1163 
1164     /// Check the status of subcommand fallthrough
1165     CLI11_NODISCARD bool get_subcommand_fallthrough() const { return subcommand_fallthrough_; }
1166 
1167     /// Check the status of the allow windows style options
1168     CLI11_NODISCARD bool get_allow_windows_style_options() const { return allow_windows_style_options_; }
1169 
1170     /// Check the status of the allow windows style options
1171     CLI11_NODISCARD bool get_positionals_at_end() const { return positionals_at_end_; }
1172 
1173     /// Check the status of the allow windows style options
1174     CLI11_NODISCARD bool get_configurable() const { return configurable_; }
1175 
1176     /// Get the group of this subcommand
1177     CLI11_NODISCARD const std::string &get_group() const { return group_; }
1178 
1179     /// Generate and return the usage.
1180     CLI11_NODISCARD std::string get_usage() const {
1181         return (usage_callback_) ? usage_callback_() + '\n' + usage_ : usage_;
1182     }
1183 
1184     /// Generate and return the footer.
1185     CLI11_NODISCARD std::string get_footer() const {
1186         return (footer_callback_) ? footer_callback_() + '\n' + footer_ : footer_;
1187     }
1188 
1189     /// Get the required min subcommand value
1190     CLI11_NODISCARD std::size_t get_require_subcommand_min() const { return require_subcommand_min_; }
1191 
1192     /// Get the required max subcommand value
1193     CLI11_NODISCARD std::size_t get_require_subcommand_max() const { return require_subcommand_max_; }
1194 
1195     /// Get the required min option value
1196     CLI11_NODISCARD std::size_t get_require_option_min() const { return require_option_min_; }
1197 
1198     /// Get the required max option value
1199     CLI11_NODISCARD std::size_t get_require_option_max() const { return require_option_max_; }
1200 
1201     /// Get the prefix command status
1202     CLI11_NODISCARD bool get_prefix_command() const { return static_cast<bool>(prefix_command_); }
1203 
1204     /// Get the prefix command status
1205     CLI11_NODISCARD PrefixCommandMode get_prefix_command_mode() const { return prefix_command_; }
1206 
1207     /// Get the status of allow extras
1208     CLI11_NODISCARD bool get_allow_extras() const { return allow_extras_ > ExtrasMode::Ignore; }
1209 
1210     /// Get the mode of allow_extras
1211     CLI11_NODISCARD ExtrasMode get_allow_extras_mode() const { return allow_extras_; }
1212 
1213     /// Get the status of required
1214     CLI11_NODISCARD bool get_required() const { return required_; }
1215 
1216     /// Get the status of disabled
1217     CLI11_NODISCARD bool get_disabled() const { return disabled_; }
1218 
1219     /// Get the status of silence
1220     CLI11_NODISCARD bool get_silent() const { return silent_; }
1221 
1222     /// Get the status of allowing non standard option names
1223     CLI11_NODISCARD bool get_allow_non_standard_option_names() const { return allow_non_standard_options_; }
1224 
1225     /// Get the status of allowing prefix matching for subcommands
1226     CLI11_NODISCARD bool get_allow_subcommand_prefix_matching() const { return allow_prefix_matching_; }
1227 
1228     /// Get the status of disabled
1229     CLI11_NODISCARD bool get_immediate_callback() const { return immediate_callback_; }
1230 
1231     /// Get the status of disabled by default
1232     CLI11_NODISCARD bool get_disabled_by_default() const { return (default_startup == startup_mode::disabled); }
1233 
1234     /// Get the status of disabled by default
1235     CLI11_NODISCARD bool get_enabled_by_default() const { return (default_startup == startup_mode::enabled); }
1236     /// Get the status of validating positionals
1237     CLI11_NODISCARD bool get_validate_positionals() const { return validate_positionals_; }
1238     /// Get the status of validating optional vector arguments
1239     CLI11_NODISCARD bool get_validate_optional_arguments() const { return validate_optional_arguments_; }
1240 
1241     /// Get the status of allow extras
1242     CLI11_NODISCARD config_extras_mode get_allow_config_extras() const {
1243         return static_cast<config_extras_mode>(allow_config_extras_);
1244     }
1245 
1246     /// Get a pointer to the help flag.
1247     Option *get_help_ptr() { return help_ptr_; }
1248 
1249     /// Get a pointer to the help flag. (const)
1250     CLI11_NODISCARD const Option *get_help_ptr() const { return help_ptr_; }
1251 
1252     /// Get a pointer to the help all flag. (const)
1253     CLI11_NODISCARD const Option *get_help_all_ptr() const { return help_all_ptr_; }
1254 
1255     /// Get a pointer to the config option.
1256     Option *get_config_ptr() { return config_ptr_; }
1257 
1258     /// Get a pointer to the config option. (const)
1259     CLI11_NODISCARD const Option *get_config_ptr() const { return config_ptr_; }
1260 
1261     /// Get a pointer to the version option.
1262     Option *get_version_ptr() { return version_ptr_; }
1263 
1264     /// Get a pointer to the version option. (const)
1265     CLI11_NODISCARD const Option *get_version_ptr() const { return version_ptr_; }
1266 
1267     /// Get the parent of this subcommand (or nullptr if main app)
1268     App *get_parent() { return parent_; }
1269 
1270     /// Get the parent of this subcommand (or nullptr if main app) (const version)
1271     CLI11_NODISCARD const App *get_parent() const { return parent_; }
1272 
1273     /// Get the name of the current app
1274     CLI11_NODISCARD const std::string &get_name() const { return name_; }
1275 
1276     /// Get the aliases of the current app
1277     CLI11_NODISCARD const std::vector<std::string> &get_aliases() const { return aliases_; }
1278 
1279     /// clear all the aliases of the current App
1280     App *clear_aliases() {
1281         aliases_.clear();
1282         return this;
1283     }
1284 
1285     /// Get a display name for an app
1286     CLI11_NODISCARD std::string get_display_name(bool with_aliases = false) const;
1287 
1288     /// Check the name, case-insensitive and underscore insensitive, and prefix matching if set
1289     /// @return true if matched
1290     CLI11_NODISCARD bool check_name(std::string name_to_check) const;
1291 
1292     /// @brief  enumeration of matching possibilities
1293     enum class NameMatch : std::uint8_t { none = 0, exact = 1, prefix = 2 };
1294 
1295     /// Check the name, case-insensitive and underscore insensitive if set
1296     /// @return NameMatch::none if no match, NameMatch::exact if the match is exact NameMatch::prefix if prefix is
1297     /// enabled and a prefix matches
1298     CLI11_NODISCARD NameMatch check_name_detail(std::string name_to_check) const;
1299 
1300     /// Get the groups available directly from this option (in order)
1301     CLI11_NODISCARD std::vector<std::string> get_groups() const;
1302 
1303     /// This gets a vector of pointers with the original parse order
1304     CLI11_NODISCARD const std::vector<Option *> &parse_order() const { return parse_order_; }
1305 
1306     /// This returns the missing options from the current subcommand
1307     CLI11_NODISCARD std::vector<std::string> remaining(bool recurse = false) const;
1308 
1309     /// This returns the missing options in a form ready for processing by another command line program
1310     CLI11_NODISCARD std::vector<std::string> remaining_for_passthrough(bool recurse = false) const;
1311 
1312     /// This returns the number of remaining options, minus the -- separator
1313     CLI11_NODISCARD std::size_t remaining_size(bool recurse = false) const;
1314 
1315     ///@}
1316 
1317   protected:
1318     /// Check the options to make sure there are no conflicts.
1319     ///
1320     /// Currently checks to see if multiple positionals exist with unlimited args and checks if the min and max options
1321     /// are feasible
1322     void _validate() const;
1323 
1324     /// configure subcommands to enable parsing through the current object
1325     /// set the correct fallthrough and prefix for nameless subcommands and manage the automatic enable or disable
1326     /// makes sure parent is set correctly
1327     void _configure();
1328 
1329     /// Internal function to run (App) callback, bottom up
1330     void run_callback(bool final_mode = false, bool suppress_final_callback = false);
1331 
1332     /// Check to see if a subcommand is valid. Give up immediately if subcommand max has been reached.
1333     CLI11_NODISCARD bool _valid_subcommand(const std::string &current, bool ignore_used = true) const;
1334 
1335     /// Selects a Classifier enum based on the type of the current argument
1336     CLI11_NODISCARD detail::Classifier _recognize(const std::string &current,
1337                                                   bool ignore_used_subcommands = true) const;
1338 
1339     // The parse function is now broken into several parts, and part of process
1340 
1341     /// Read and process a configuration file (main app only)
1342     void _process_config_file();
1343 
1344     /// Read and process a particular configuration file
1345     bool _process_config_file(const std::string &config_file, bool throw_error);
1346 
1347     /// Get envname options if not yet passed. Runs on *all* subcommands.
1348     void _process_env();
1349 
1350     /// Process callbacks. Runs on *all* subcommands.
1351     void _process_callbacks(CallbackPriority priority);
1352 
1353     /// Run help flag processing if any are found.
1354     ///
1355     /// The flags allow recursive calls to remember if there was a help flag on a parent.
1356     void _process_help_flags(CallbackPriority priority, bool trigger_help = false, bool trigger_all_help = false) const;
1357 
1358     /// Run the full priority-ordered callback/help-flag pipeline used when a parse-complete callback fires.
1359     ///
1360     /// When @p with_help_flags is true the help-flag passes and environment processing are included
1361     /// (the option/dot-notation paths); when false they are omitted (the config-section-close path).
1362     void _process_completion_callbacks(bool with_help_flags);
1363 
1364     /// Verify required options and cross requirements. Subcommands too (only if selected).
1365     void _process_requirements();
1366 
1367     /// Process callbacks and such.
1368     void _process();
1369 
1370     /// Throw an error if anything is left over and should not be.
1371     void _process_extras();
1372 
1373     /// Internal function to recursively increment the parsed counter on the current app as well unnamed subcommands
1374     void increment_parsed();
1375 
1376     /// Shared prologue for the public parse() overloads: clears prior state, validates and configures,
1377     /// and marks this app as the top-level app.
1378     void _parse_setup();
1379 
1380     /// Internal parse function
1381     void _parse(std::vector<std::string> &args);
1382 
1383     /// Internal parse function
1384     void _parse(std::vector<std::string> &&args);
1385 
1386     /// Internal function to parse a stream
1387     void _parse_stream(std::istream &input);
1388 
1389     /// Parse one config param, return false if not found in any subcommand, remove if it is
1390     ///
1391     /// If this has more than one dot.separated.name, go into the subcommand matching it
1392     /// Returns true if it managed to find the option, if false you'll need to remove the arg manually.
1393     void _parse_config(const std::vector<ConfigItem> &args);
1394 
1395     /// Fill in a single config option
1396     bool _parse_single_config(const ConfigItem &item, std::size_t level = 0);
1397 
1398     /// @brief store the results for a flag like option
1399     bool _add_flag_like_result(Option *op, const ConfigItem &item, const std::vector<std::string> &inputs);
1400 
1401     /// Parse "one" argument (some may eat more than one), delegate to parent if fails, add to missing if missing
1402     /// from main return false if the parse has failed and needs to return to parent
1403     bool _parse_single(std::vector<std::string> &args, bool &positional_only);
1404 
1405     /// Count the required remaining positional arguments
1406     CLI11_NODISCARD std::size_t _count_remaining_positionals(bool required_only = false) const;
1407 
1408     /// Count the required remaining positional arguments
1409     CLI11_NODISCARD bool _has_remaining_positionals() const;
1410 
1411     /// Parse a positional, go up the tree to check
1412     /// @param haltOnSubcommand if set to true the operation will not process subcommands merely return false
1413     /// Return true if the positional was used false otherwise
1414     bool _parse_positional(std::vector<std::string> &args, bool haltOnSubcommand);
1415 
1416     /// Locate a subcommand by name with two conditions, should disabled subcommands be ignored, and should used
1417     /// subcommands be ignored
1418     CLI11_NODISCARD App *
1419     _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept;
1420 
1421     /// Parse a subcommand, modify args and continue
1422     ///
1423     /// Unlike the others, this one will always allow fallthrough
1424     /// return true if the subcommand was processed false otherwise
1425     bool _parse_subcommand(std::vector<std::string> &args);
1426 
1427     /// Parse a short (false) or long (true) argument, must be at the top of the list
1428     /// if local_processing_only is set to true then fallthrough is disabled will return false if not found
1429     /// return true if the argument was processed or false if nothing was done
1430     bool _parse_arg(std::vector<std::string> &args, detail::Classifier current_type, bool local_processing_only);
1431 
1432     /// Trigger the pre_parse callback if needed
1433     void _trigger_pre_parse(std::size_t remaining_args);
1434 
1435     /// Get the appropriate parent to fallthrough to which is the first one that has a name or the main app
1436     CLI11_NODISCARD App *_get_fallthrough_parent() noexcept;
1437 
1438     /// Get the appropriate parent to fallthrough to which is the first one that has a name or the main app
1439     CLI11_NODISCARD const App *_get_fallthrough_parent() const noexcept;
1440 
1441     /// Helper function to run through all possible comparisons of subcommand names to check there is no overlap
1442     CLI11_NODISCARD const std::string &_compare_subcommand_names(const App &subcom, const App &base) const;
1443 
1444     /// Helper function to place extra values in the most appropriate position
1445     void _move_to_missing(detail::Classifier val_type, const std::string &val);
1446 
1447   public:
1448     /// function that could be used by subclasses of App to shift options around into subcommands
1449     void _move_option(Option *opt, App *app);
1450 };  // namespace CLI
1451 
1452 /// Extension of App to better manage groups of options
1453 class Option_group : public App {
1454   public:
1455     Option_group(std::string group_description, std::string group_name, App *parent)
1456         : App(std::move(group_description), "", parent) {
1457         group(group_name);
1458         // option groups should have automatic fallthrough
1459         if(group_name.empty() || group_name.front() == '+') {
1460             // help will not be used by default in these contexts
1461             set_help_flag("");
1462             set_help_all_flag("");
1463         }
1464     }
1465     using App::add_option;
1466     /// Add an existing option to the Option_group
1467     Option *add_option(Option *opt) {
1468         if(get_parent() == nullptr) {
1469             throw OptionNotFound("Unable to locate the specified option");
1470         }
1471         get_parent()->_move_option(opt, this);
1472         return opt;
1473     }
1474     /// Add an existing option to the Option_group
1475     void add_options(Option *opt) { add_option(opt); }
1476     /// Add a bunch of options to the group
1477     template <typename... Args> void add_options(Option *opt, Args... args) {
1478         add_option(opt);
1479         add_options(args...);
1480     }
1481     using App::add_subcommand;
1482     /// Add an existing subcommand to be a member of an option_group
1483     App *add_subcommand(App *subcom) {
1484         App_p subc = subcom->get_parent()->get_subcommand_ptr(subcom);
1485         subc->get_parent()->remove_subcommand(subcom);
1486         add_subcommand(std::move(subc));
1487         return subcom;
1488     }
1489 };
1490 
1491 /// Helper function to enable one option group/subcommand when another is used
1492 CLI11_INLINE void TriggerOn(App *trigger_app, App *app_to_enable);
1493 
1494 /// Helper function to enable one option group/subcommand when another is used
1495 CLI11_INLINE void TriggerOn(App *trigger_app, std::vector<App *> apps_to_enable);
1496 
1497 /// Helper function to disable one option group/subcommand when another is used
1498 CLI11_INLINE void TriggerOff(App *trigger_app, App *app_to_enable);
1499 
1500 /// Helper function to disable one option group/subcommand when another is used
1501 CLI11_INLINE void TriggerOff(App *trigger_app, std::vector<App *> apps_to_enable);
1502 
1503 /// Helper function to mark an option as deprecated
1504 CLI11_INLINE void deprecate_option(Option *opt, const std::string &replacement = "");
1505 
1506 /// Helper function to mark an option as deprecated
1507 inline void deprecate_option(App *app, const std::string &option_name, const std::string &replacement = "") {
1508     auto *opt = app->get_option(option_name);
1509     deprecate_option(opt, replacement);
1510 }
1511 
1512 /// Helper function to mark an option as deprecated
1513 inline void deprecate_option(App &app, const std::string &option_name, const std::string &replacement = "") {
1514     auto *opt = app.get_option(option_name);
1515     deprecate_option(opt, replacement);
1516 }
1517 
1518 /// Helper function to mark an option as retired
1519 CLI11_INLINE void retire_option(App *app, Option *opt);
1520 
1521 /// Helper function to mark an option as retired
1522 CLI11_INLINE void retire_option(App &app, Option *opt);
1523 
1524 /// Helper function to mark an option as retired
1525 CLI11_INLINE void retire_option(App *app, const std::string &option_name);
1526 
1527 /// Helper function to mark an option as retired
1528 CLI11_INLINE void retire_option(App &app, const std::string &option_name);
1529 
1530 namespace detail {
1531 /// This class is simply to allow tests access to App's protected functions
1532 struct AppFriend {
1533 #ifdef CLI11_CPP14
1534 
1535     /// Wrap _parse_short, perfectly forward arguments and return
1536     template <typename... Args> static decltype(auto) parse_arg(App *app, Args &&...args) {
1537         return app->_parse_arg(std::forward<Args>(args)...);
1538     }
1539 
1540     /// Wrap _parse_subcommand, perfectly forward arguments and return
1541     template <typename... Args> static decltype(auto) parse_subcommand(App *app, Args &&...args) {
1542         return app->_parse_subcommand(std::forward<Args>(args)...);
1543     }
1544 #else
1545     /// Wrap _parse_short, perfectly forward arguments and return
1546     template <typename... Args>
1547     static auto parse_arg(App *app, Args &&...args) ->
1548         typename std::result_of<decltype (&App::_parse_arg)(App, Args...)>::type {
1549         return app->_parse_arg(std::forward<Args>(args)...);
1550     }
1551 
1552     /// Wrap _parse_subcommand, perfectly forward arguments and return
1553     template <typename... Args>
1554     static auto parse_subcommand(App *app, Args &&...args) ->
1555         typename std::result_of<decltype (&App::_parse_subcommand)(App, Args...)>::type {
1556         return app->_parse_subcommand(std::forward<Args>(args)...);
1557     }
1558 #endif
1559     /// Wrap the fallthrough parent function to make sure that is working correctly
1560     static App *get_fallthrough_parent(App *app) { return app->_get_fallthrough_parent(); }
1561 
1562     /// Wrap the const fallthrough parent function to make sure that is working correctly
1563     static const App *get_fallthrough_parent(const App *app) { return app->_get_fallthrough_parent(); }
1564 };
1565 }  // namespace detail
1566 
1567 // [CLI11:app_hpp:end]
1568 }  // namespace CLI
1569 
1570 #ifndef CLI11_COMPILE
1571 #include "impl/App_inl.hpp"  // IWYU pragma: export
1572 #endif