-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can`t parse "--help" argument #4
Comments
Everything works without fault on my Linux machine, so this might be windows specific. |
I debugged the case to find the exact cause. Finally I found that this lambda expression can`t capture the variables correctly in windows. [&, this](auto&& attribute) -> decltype(attribute(x, *this, arg), void()) { attribute(x, *this, arg); } template<class T, class... Ts>
void parse(T&& x, Ts&&... xs)
{
argument arg;
arg.write_value = [&x](const std::string& s) { args::write_value_to(x, s); };
arg.type = args::get_argument_type(x);
arg.metavar = args::type_to_help(x);
args::each_arg(args::overload(
[&](const std::string& name) { arg.flags.push_back(name); },
[&, this](auto&& attribute) -> decltype(attribute(x, *this, arg), void()) { attribute(x, *this, arg); }
), std::forward<Ts>(xs)...);
this->add(std::move(arg));
} By the way, I can`t compile the "args.hpp" file directly at vs2019.
|
I think this is a problem with handling expression SFINAE in MSVC. I've never tested this on windows. If there is some workarounds to make this work on MSVC, please let me know. |
I'm newbie here of c++, so the root cause I can't figure out. In my test, this issue just happen in the "--help" parser. Cause of the project limit, I have to do some ugly modification, but work. template<class T, class... Ts> |template<class T, class... Ts>
void parse(T&& x, Ts&&... xs) |void parse(T&& x, Ts&&... xs)
{ |{
context* cxt = this; |-------------------------------------------------------------------------------------------------------------------------------------
argument arg; | argument arg;
arg.write_value = [&x](const std::string& s) { args::write_value_to(x, s); }; | arg.write_value = [&x](const std::string& s) {args::write_value_to(x, s); };
arg.type = args::get_argument_type(x); | arg.type = args::get_argument_type(x);
arg.metavar = args::type_to_help(x); | arg.metavar = args::type_to_help(x);
args::each_arg(args::overload( | args::each_arg(args::overload(
[&](const std::string& name) { arg.flags.push_back(name); }, | [&, this](const std::string& name) { arg.flags.push_back(name); },
[&, cxt](auto&& attribute) -> decltype(attribute(x, *cxt, arg), void()) { attribute(x, *cxt, arg); }| [&, this](auto&& attribute) -> decltype(attribute(x, *this, arg), void()) { attribute(x, *this, arg); }
), std::forward<Ts>(xs)...); | ), std::forward<Ts>(xs)...);
this->add(std::move(arg)); | this->add(std::move(arg));
} |}
Then, Using the 'ctx' variable captured by copy to support show "--help" information. template<class... Ts, class T> | template<class... Ts, class T>
context<T&, Ts...> build_context(T& cmd) | context<T&, Ts...> build_context(T& cmd)
{ | {
context<T&, Ts...> ctx; | context<T&, Ts...> ctx;
args::assign_subcommands(rank<1>{}, ctx, cmd); | args::assign_subcommands(rank<1>{}, ctx, cmd);
| ctx.parse(nullptr, "--help", "-h", args::help("Show help."),
----------------------------------------------------------------------------------| args::eager_callback([](std::nullptr_t, const auto& c, const argument&)
----------------------------------------------------------------------------------| {
----------------------------------------------------------------------------------| c.show_help(get_name<T>(), get_help<T>(), get_options_metavar<T>());
----------------------------------------------------------------------------------| }));
args::try_parse(rank<1>{}, cmd, [&](auto&&... xs) | args::try_parse(rank<1>{}, cmd, [&](auto&&... xs)
{ | {
ctx.parse(std::forward<decltype(xs)>(xs)...); | ctx.parse(std::forward<decltype(xs)>(xs)...);
}); | });
ctx.parse(nullptr, "--help", "-h", args::help("Show help."), | -------------------------------------------------------------------------------
args::eager_callback([ctx](std::nullptr_t, const auto& c, const argument&)| -------------------------------------------------------------------------------
{ | -------------------------------------------------------------------------------
ctx.show_help(get_name<T>(), get_help<T>(), get_options_metavar<T>()); | -------------------------------------------------------------------------------
})); | -------------------------------------------------------------------------------
return ctx; | return ctx;
} | }
Hope someone can solve this problem really. |
When I was trying to test the first use case under the Quickstart, all the argument parser works great except the "--help".
Could help to check this?
The text was updated successfully, but these errors were encountered: