Merge c91cd4a0dd into db9b70a935
This commit is contained in:
commit
d148723659
@ -46,7 +46,7 @@ namespace cxxopts
|
||||
(
|
||||
const std::string& s,
|
||||
const std::string& l,
|
||||
bool has_arg
|
||||
const bool has_arg
|
||||
)
|
||||
{
|
||||
std::string result = " ";
|
||||
@ -192,7 +192,7 @@ Options::checked_parse_arg
|
||||
void
|
||||
Options::add_to_option(const std::string& option, const std::string& arg)
|
||||
{
|
||||
auto iter = m_options.find(option);
|
||||
const auto iter = m_options.find(option);
|
||||
|
||||
if (iter == m_options.end())
|
||||
{
|
||||
@ -255,19 +255,19 @@ Options::parse(int& argc, char**& argv)
|
||||
//short or long option?
|
||||
if (result[4].length() != 0)
|
||||
{
|
||||
std::string s = result[4];
|
||||
const std::string s = result[4];
|
||||
|
||||
for (int i = 0; i != s.size(); ++i)
|
||||
{
|
||||
std::string name(1, s[i]);
|
||||
auto iter = m_options.find(name);
|
||||
const auto iter = m_options.find(name);
|
||||
|
||||
if (iter == m_options.end())
|
||||
{
|
||||
throw option_not_exists_exception(name);
|
||||
}
|
||||
|
||||
auto value = iter->second;
|
||||
const auto value = iter->second;
|
||||
|
||||
//if no argument then just add it
|
||||
if (!value->has_arg())
|
||||
@ -294,14 +294,14 @@ Options::parse(int& argc, char**& argv)
|
||||
{
|
||||
std::string name = result[1];
|
||||
|
||||
auto iter = m_options.find(name);
|
||||
const auto iter = m_options.find(name);
|
||||
|
||||
if (iter == m_options.end())
|
||||
{
|
||||
throw option_not_exists_exception(name);
|
||||
}
|
||||
|
||||
auto opt = iter->second;
|
||||
const auto opt = iter->second;
|
||||
|
||||
//equals provided for long option?
|
||||
if (result[3].length() != 0)
|
||||
@ -353,19 +353,19 @@ Options::add_option
|
||||
{
|
||||
auto option = std::make_shared<OptionDetails>(desc, value);
|
||||
|
||||
if (s.size() > 0)
|
||||
if (s.length() > 0)
|
||||
{
|
||||
add_one_option(s, option);
|
||||
}
|
||||
|
||||
if (l.size() > 0)
|
||||
if (l.length() > 0)
|
||||
{
|
||||
add_one_option(l, option);
|
||||
}
|
||||
|
||||
//add the help details
|
||||
auto& options = m_help[group];
|
||||
options.options.push_back(HelpOptionDetails{s, l, desc, value->has_arg()});
|
||||
options.options.emplace_back(HelpOptionDetails{s, l, desc, value->has_arg()});
|
||||
}
|
||||
|
||||
void
|
||||
@ -375,7 +375,7 @@ Options::add_one_option
|
||||
std::shared_ptr<OptionDetails> details
|
||||
)
|
||||
{
|
||||
auto in = m_options.insert(std::make_pair(option, details));
|
||||
auto in = m_options.emplace(option, details);
|
||||
|
||||
if (!in.second)
|
||||
{
|
||||
@ -386,9 +386,9 @@ Options::add_one_option
|
||||
std::string
|
||||
Options::help_one_group(const std::string& g) const
|
||||
{
|
||||
typedef std::vector<std::pair<std::string, std::string>> OptionHelp;
|
||||
using OptionHelp = std::vector<std::pair<std::string, std::string>>;
|
||||
|
||||
auto group = m_help.find(g);
|
||||
const auto group = m_help.find(g);
|
||||
if (group == m_help.end())
|
||||
{
|
||||
return "";
|
||||
@ -407,15 +407,15 @@ Options::help_one_group(const std::string& g) const
|
||||
|
||||
for (const auto& o : group->second.options)
|
||||
{
|
||||
auto s = format_option(o.s, o.l, o.has_arg);
|
||||
const auto s = format_option(o.s, o.l, o.has_arg);
|
||||
longest = std::max(longest, s.size());
|
||||
format.push_back(std::make_pair(s, std::string()));
|
||||
format.emplace_back(s, std::string());
|
||||
}
|
||||
|
||||
longest = std::min(longest, static_cast<size_t>(OPTION_LONGEST));
|
||||
|
||||
//widest allowed description
|
||||
int allowed = 76 - longest - OPTION_DESC_GAP;
|
||||
const int allowed = 76 - longest - OPTION_DESC_GAP;
|
||||
|
||||
auto fiter = format.begin();
|
||||
for (const auto& o : group->second.options)
|
||||
|
||||
@ -83,7 +83,7 @@ namespace cxxopts
|
||||
}
|
||||
};
|
||||
|
||||
class option_exists_error : public OptionSpecException
|
||||
class option_exists_error final : public OptionSpecException
|
||||
{
|
||||
public:
|
||||
option_exists_error(const std::string& option)
|
||||
@ -92,7 +92,7 @@ namespace cxxopts
|
||||
}
|
||||
};
|
||||
|
||||
class invalid_option_format_error : public OptionSpecException
|
||||
class invalid_option_format_error final : public OptionSpecException
|
||||
{
|
||||
public:
|
||||
invalid_option_format_error(const std::string& format)
|
||||
@ -101,7 +101,7 @@ namespace cxxopts
|
||||
}
|
||||
};
|
||||
|
||||
class option_not_exists_exception : public OptionParseException
|
||||
class option_not_exists_exception final : public OptionParseException
|
||||
{
|
||||
public:
|
||||
option_not_exists_exception(const std::string& option)
|
||||
@ -110,7 +110,7 @@ namespace cxxopts
|
||||
}
|
||||
};
|
||||
|
||||
class missing_argument_exception : public OptionParseException
|
||||
class missing_argument_exception final : public OptionParseException
|
||||
{
|
||||
public:
|
||||
missing_argument_exception(const std::string& option)
|
||||
@ -119,7 +119,7 @@ namespace cxxopts
|
||||
}
|
||||
};
|
||||
|
||||
class option_requires_argument_exception : public OptionParseException
|
||||
class option_requires_argument_exception final : public OptionParseException
|
||||
{
|
||||
public:
|
||||
option_requires_argument_exception(const std::string& option)
|
||||
@ -128,7 +128,7 @@ namespace cxxopts
|
||||
}
|
||||
};
|
||||
|
||||
class option_not_has_argument_exception : public OptionParseException
|
||||
class option_not_has_argument_exception final : public OptionParseException
|
||||
{
|
||||
public:
|
||||
option_not_has_argument_exception
|
||||
@ -143,7 +143,7 @@ namespace cxxopts
|
||||
}
|
||||
};
|
||||
|
||||
class option_not_present_exception : public OptionParseException
|
||||
class option_not_present_exception final : public OptionParseException
|
||||
{
|
||||
public:
|
||||
option_not_present_exception(const std::string& option)
|
||||
@ -152,7 +152,7 @@ namespace cxxopts
|
||||
}
|
||||
};
|
||||
|
||||
class argument_incorrect_type : public OptionParseException
|
||||
class argument_incorrect_type final : public OptionParseException
|
||||
{
|
||||
public:
|
||||
argument_incorrect_type
|
||||
@ -373,7 +373,7 @@ namespace cxxopts
|
||||
int
|
||||
count(const std::string& o) const
|
||||
{
|
||||
auto iter = m_options.find(o);
|
||||
const auto iter = m_options.find(o);
|
||||
if (iter == m_options.end())
|
||||
{
|
||||
return 0;
|
||||
@ -385,8 +385,7 @@ namespace cxxopts
|
||||
const OptionDetails&
|
||||
operator[](const std::string& option) const
|
||||
{
|
||||
auto iter = m_options.find(option);
|
||||
|
||||
const auto iter = m_options.find(option);
|
||||
if (iter == m_options.end())
|
||||
{
|
||||
throw option_not_present_exception(option);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user