Fix positional arguments overload

Fixes #83.

Adds an overload for positional arguments taking a
`std::initializer_list`. When using an `initializer_list` with one
argument, the function call is ambiguous matching both `std::string`
and `std::vector<std::string>`.
This commit is contained in:
Jarryd Beck 2017-11-28 17:56:03 +11:00
parent abe9ebd6b4
commit 2ca68adeaf
3 changed files with 14 additions and 2 deletions

View File

@ -12,6 +12,8 @@ options. The project adheres to semantic versioning.
when a positional argument could follow an option with an implicit value.
For example, `--foo value`, where `foo` has an implicit value, will be
parsed as `--foo=implicit` and a positional argument `value`.
* Fixed an ambiguous overload in the `parse_positional` function when an
`initializer_list` was directly passed.
## 2.0

View File

@ -1211,6 +1211,9 @@ namespace cxxopts
void
parse_positional(std::vector<std::string> options);
void
parse_positional(std::initializer_list<std::string> options);
std::string
help(const std::vector<std::string>& groups = {""}) const;
@ -1588,7 +1591,7 @@ inline
void
Options::parse_positional(std::string option)
{
parse_positional(std::vector<std::string>{option});
parse_positional(std::vector<std::string>{std::move(option)});
}
inline
@ -1601,6 +1604,13 @@ Options::parse_positional(std::vector<std::string> options)
m_positional_set.insert(m_positional.begin(), m_positional.end());
}
inline
void
Options::parse_positional(std::initializer_list<std::string> options)
{
parse_positional(std::vector<std::string>(std::move(options)));
}
inline
ParseResult
Options::parse(int& argc, char**& argv)

View File

@ -145,7 +145,7 @@ TEST_CASE("All positional", "[positional]")
auto argc = av.argc();
auto argv = av.argv();
options.parse_positional("positional");
options.parse_positional({"positional"});
auto result = options.parse(argc, argv);