#pragma once // Distributed under the 3-Clause BSD License. See accompanying // file LICENSE or https://github.com/CLIUtils/CLI11 for details. #include #include #include #include #include #include #include #include #include #include #include #include // CLI Library includes #include "CLI/ConfigFwd.hpp" #include "CLI/Error.hpp" #include "CLI/FormatterFwd.hpp" #include "CLI/Macros.hpp" #include "CLI/Option.hpp" #include "CLI/Split.hpp" #include "CLI/StringTools.hpp" #include "CLI/TypeTools.hpp" namespace CLI { #ifndef CLI11_PARSE #define CLI11_PARSE(app, argc, argv) \ try { \ (app).parse((argc), (argv)); \ } catch(const CLI::ParseError &e) { \ return (app).exit(e); \ } #endif namespace detail { enum class Classifier { NONE, POSITIONAL_MARK, SHORT, LONG, WINDOWS, SUBCOMMAND }; struct AppFriend; } // namespace detail namespace FailureMessage { std::string simple(const App *app, const Error &e); std::string help(const App *app, const Error &e); } // namespace FailureMessage class App; using App_p = std::shared_ptr; /// Creates a command line program, with very few defaults. /** To use, create a new `Program()` instance with `argc`, `argv`, and a help description. The templated * add_option methods make it easy to prepare options. Remember to call `.start` before starting your * program, so that the options can be evaluated and the help option doesn't accidentally run your program. */ class App { friend Option; friend detail::AppFriend; protected: // This library follows the Google style guide for member names ending in underscores /// @name Basics ///@{ /// Subcommand name or program name (from parser if name is empty) std::string name_; /// Description of the current program/subcommand std::string description_; /// If true, allow extra arguments (ie, don't throw an error). INHERITABLE bool allow_extras_{false}; /// If true, allow extra arguments in the ini file (ie, don't throw an error). INHERITABLE bool allow_config_extras_{false}; /// If true, return immediately on an unrecognized option (implies allow_extras) INHERITABLE bool prefix_command_{false}; /// if set to true the name was automatically generated from the command line vs a user set name bool has_automatic_name_{false}; /// This is a function that runs when complete. Great for subcommands. Can throw. std::function callback_; ///@} /// @name Options ///@{ /// The default values for options, customizable and changeable INHERITABLE OptionDefaults option_defaults_; /// The list of options, stored locally std::vector options_; ///@} /// @name Help ///@{ /// Footer to put after all options in the help output INHERITABLE std::string footer_; /// A pointer to the help flag if there is one INHERITABLE Option *help_ptr_{nullptr}; /// A pointer to the help all flag if there is one INHERITABLE Option *help_all_ptr_{nullptr}; /// This is the formatter for help printing. Default provided. INHERITABLE (same pointer) std::shared_ptr formatter_{new Formatter()}; /// The error message printing function INHERITABLE std::function failure_message_ = FailureMessage::simple; ///@} /// @name Parsing ///@{ using missing_t = std::vector>; /// Pair of classifier, string for missing options. (extra detail is removed on returning from parse) /// /// This is faster and cleaner than storing just a list of strings and reparsing. This may contain the -- separator. missing_t missing_; /// This is a list of pointers to options with the original parse order std::vector