diff options
Diffstat (limited to 'src/common/cli_wrapper.h')
-rw-r--r-- | src/common/cli_wrapper.h | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/src/common/cli_wrapper.h b/src/common/cli_wrapper.h index 349d353b..da8ebd6d 100644 --- a/src/common/cli_wrapper.h +++ b/src/common/cli_wrapper.h @@ -44,7 +44,7 @@ struct CLIAliasTuple { class CLIFormatter : public CLI::Formatter { public: CLIFormatter(size_t columnWidth, size_t screenWidth); - virtual std::string make_option_desc(const CLI::Option *) const override; + virtual std::string make_option_desc(const CLI::Option*) const override; private: size_t screenWidth_{0}; @@ -85,12 +85,7 @@ private: // Extract option name from a comma-separated list of long and short options, e.g. 'help' from // '--help,-h' - std::string keyName(const std::string &args) const { - // re-use existing functions from CLI11 to keep option names consistent - return std::get<1>( - CLI::detail::get_names(CLI::detail::split_names(args))) // get long names only - .front(); // get first long name - } + std::string keyName(const std::string &args) const; // Get names of options passed via command-line std::unordered_set<std::string> getParsedOptionNames() const; @@ -134,7 +129,7 @@ public: * @return Option object */ template <typename T> - CLI::Option *add(const std::string &args, const std::string &help, T val) { + CLI::Option* add(const std::string& args, const std::string& help, T val) { return addOption<T>(keyName(args), args, help, @@ -159,7 +154,7 @@ public: * @TODO: require to always state the default value creating the parser as this will be clearer */ template <typename T> - CLI::Option *add(const std::string &args, const std::string &help) { + CLI::Option* add(const std::string& args, const std::string& help) { return addOption<T>(keyName(args), args, help, @@ -206,7 +201,7 @@ public: std::string switchGroup(std::string name = ""); // Parse command-line arguments. Handles --help and --version options - void parse(int argc, char **argv); + void parse(int argc, char** argv); /** * @brief Expand aliases based on arguments parsed with parse(int, char**) @@ -240,11 +235,12 @@ public: std::string dumpConfig(bool skipUnmodified = false) const; private: - template <typename T, - // options with numeric and string-like values - CLI::enable_if_t<!CLI::is_bool<T>::value && !CLI::is_vector<T>::value, - CLI::detail::enabler> = CLI::detail::dummy> - CLI::Option *addOption(const std::string &key, + template <typename T> + using EnableIfNumbericOrString = CLI::enable_if_t<!CLI::is_bool<T>::value + && !CLI::is_vector<T>::value, CLI::detail::enabler>; + + template <typename T, EnableIfNumbericOrString<T> = CLI::detail::dummy> + CLI::Option* addOption(const std::string &key, const std::string &args, const std::string &help, T val, @@ -261,7 +257,7 @@ private: CLI::callback_t fun = [this, key](CLI::results_t res) { options_[key].priority = cli::OptionPriority::CommandLine; // get variable associated with the option - auto &var = options_[key].var->as<T>(); + auto& var = options_[key].var->as<T>(); // store parser result in var auto ret = CLI::detail::lexical_cast(res[0], var); // update YAML entry @@ -288,10 +284,11 @@ private: return options_[key].opt; } - template <typename T, - // options with vector values - CLI::enable_if_t<CLI::is_vector<T>::value, CLI::detail::enabler> = CLI::detail::dummy> - CLI::Option *addOption(const std::string &key, + template <typename T> + using EnableIfVector = CLI::enable_if_t<CLI::is_vector<T>::value, CLI::detail::enabler>; + + template <typename T, EnableIfVector<T> = CLI::detail::dummy> + CLI::Option* addOption(const std::string &key, const std::string &args, const std::string &help, T val, @@ -308,7 +305,7 @@ private: CLI::callback_t fun = [this, key](CLI::results_t res) { options_[key].priority = cli::OptionPriority::CommandLine; // get vector variable associated with the option - auto &vec = options_[key].var->as<T>(); + auto& vec = options_[key].var->as<T>(); vec.clear(); bool ret = true; // handle '[]' as an empty vector @@ -316,7 +313,7 @@ private: ret = true; } else { // populate the vector with parser results - for(const auto &a : res) { + for(const auto& a : res) { vec.emplace_back(); ret &= CLI::detail::lexical_cast(a, vec.back()); } @@ -345,10 +342,11 @@ private: return options_[key].opt; } - template <typename T, - // options with boolean values, called flags in CLI11 - CLI::enable_if_t<CLI::is_bool<T>::value, CLI::detail::enabler> = CLI::detail::dummy> - CLI::Option *addOption(const std::string &key, + template <typename T> + using EnableIfBoolean = CLI::enable_if_t<CLI::is_bool<T>::value, CLI::detail::enabler>; + + template <typename T, EnableIfBoolean<T> = CLI::detail::dummy> + CLI::Option* addOption(const std::string &key, const std::string &args, const std::string &help, T val, |