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:
parent
abe9ebd6b4
commit
2ca68adeaf
@ -12,6 +12,8 @@ options. The project adheres to semantic versioning.
|
|||||||
when a positional argument could follow an option with an implicit value.
|
when a positional argument could follow an option with an implicit value.
|
||||||
For example, `--foo value`, where `foo` has an implicit value, will be
|
For example, `--foo value`, where `foo` has an implicit value, will be
|
||||||
parsed as `--foo=implicit` and a positional argument `value`.
|
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
|
## 2.0
|
||||||
|
|
||||||
|
|||||||
@ -1211,6 +1211,9 @@ namespace cxxopts
|
|||||||
void
|
void
|
||||||
parse_positional(std::vector<std::string> options);
|
parse_positional(std::vector<std::string> options);
|
||||||
|
|
||||||
|
void
|
||||||
|
parse_positional(std::initializer_list<std::string> options);
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
help(const std::vector<std::string>& groups = {""}) const;
|
help(const std::vector<std::string>& groups = {""}) const;
|
||||||
|
|
||||||
@ -1588,7 +1591,7 @@ inline
|
|||||||
void
|
void
|
||||||
Options::parse_positional(std::string option)
|
Options::parse_positional(std::string option)
|
||||||
{
|
{
|
||||||
parse_positional(std::vector<std::string>{option});
|
parse_positional(std::vector<std::string>{std::move(option)});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@ -1601,6 +1604,13 @@ Options::parse_positional(std::vector<std::string> options)
|
|||||||
m_positional_set.insert(m_positional.begin(), m_positional.end());
|
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
|
inline
|
||||||
ParseResult
|
ParseResult
|
||||||
Options::parse(int& argc, char**& argv)
|
Options::parse(int& argc, char**& argv)
|
||||||
|
|||||||
@ -145,7 +145,7 @@ TEST_CASE("All positional", "[positional]")
|
|||||||
auto argc = av.argc();
|
auto argc = av.argc();
|
||||||
auto argv = av.argv();
|
auto argv = av.argv();
|
||||||
|
|
||||||
options.parse_positional("positional");
|
options.parse_positional({"positional"});
|
||||||
|
|
||||||
auto result = options.parse(argc, argv);
|
auto result = options.parse(argc, argv);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user