|
- #pragma once
-
- #include <map>
- #include <vector>
- #include <memory>
- #include <cstring>
- #include <cppargs/group/group.h>
-
- namespace cppargs
- {
-
- /**
- * @brief Class to parse command line arguments.
- */
- struct parser
- {
- public:
- using option_type = option;
- using option_ptr_type = std::unique_ptr<option_type>;
- using option_map_type = std::map<std::string, option_type*>;
-
- private:
- group& _group;
- option_ptr_type _default; //!< Default option to parse unknown arguments.
- option_map_type _map; //!< Map of option name to option.
-
- protected:
- /**
- * @brief Add the passed group to the options map
- */
- inline void add_to_map(const group& g);
-
- /**
- * @brief Update the option map.
- */
- inline void update_map();
-
- /**
- * @brief Handle invalid argument (use default option or throw exception).
- */
- inline void handle_invalid_arg(context& c) const;
-
- /**
- * @brief Parse the command line arguments using the passed options.
- *
- * @param[in] argc Number of arguments in argv.
- * @param[in] argv Array of all arguments.
- */
- inline void parse(int argc, char const * argv[]) const;
-
- public:
- /**
- * @brief Constructor.
- *
- * @param[in] p_default Default option to use for unknown arguents (optional / can be null).
- * @param[in] p_group Group with options and subgroups.
- */
- inline parser(
- option_ptr_type&& p_default,
- group& p_group);
-
- /**
- * @brief Print the help of all options
- *
- * @param[in] os Stream to write help to.
- */
- inline void print_help(std::ostream& os) const;
- };
-
- }
|