Commit 668787e0 authored by aligungr's avatar aligungr

Options parser improvement

parent 7e3fccd5
...@@ -349,10 +349,16 @@ std::string opt::OptionsResult::getPositional(int index) const ...@@ -349,10 +349,16 @@ std::string opt::OptionsResult::getPositional(int index) const
std::string opt::OptionsResult::getOption(const OptionItem &item) const std::string opt::OptionsResult::getOption(const OptionItem &item) const
{ {
if (item.shortName.has_value() && m_options.count(std::string(1, *item.shortName)) > 0) return getOption(item.shortName, item.longName);
return m_options.at(std::string(1, *item.shortName)); }
if (item.longName.has_value() && m_options.count(*item.longName))
return m_options.at(*item.longName); std::string opt::OptionsResult::getOption(const std::optional<char> &shortName,
const std::optional<std::string> &longName) const
{
if (shortName.has_value() && m_options.count(std::string(1, *shortName)) > 0)
return m_options.at(std::string(1, *shortName));
if (longName.has_value() && m_options.count(*longName))
return m_options.at(*longName);
return {}; return {};
} }
......
...@@ -112,6 +112,7 @@ class OptionsResult ...@@ -112,6 +112,7 @@ class OptionsResult
int count() const; int count() const;
std::string getPositional(int index) const; std::string getPositional(int index) const;
std::string getOption(const OptionItem &item) const; std::string getOption(const OptionItem &item) const;
std::string getOption(const std::optional<char> &shortName, const std::optional<std::string>& longName) const;
public: public:
void showHelp() const; void showHelp() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment