Fix support for switches style option in user commands

This commit is contained in:
Maxime Coste 2014-03-20 19:50:42 +00:00
parent c48bdbe4f1
commit dc953197c3
3 changed files with 5 additions and 4 deletions

View File

@ -597,7 +597,7 @@ void define_command(const ParametersParser& parser, Context& context)
ParameterDesc desc;
if (parser.has_option("env-params"))
{
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None };
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::SwitchesAsPositional };
cmd = [=](const ParametersParser& parser, Context& context) {
CommandManager::instance().execute(commands, context, {},
params_to_env_var_map(parser));
@ -605,14 +605,14 @@ void define_command(const ParametersParser& parser, Context& context)
}
if (parser.has_option("shell-params"))
{
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None };
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::SwitchesAsPositional };
cmd = [=](const ParametersParser& parser, Context& context) {
CommandManager::instance().execute(commands, context, params_to_shell(parser));
};
}
else
{
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None, 0, 0 };
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::SwitchesAsPositional, 0, 0 };
cmd = [=](const ParametersParser& parser, Context& context) {
CommandManager::instance().execute(commands, context);
};

View File

@ -16,7 +16,7 @@ ParametersParser::ParametersParser(ParameterList params,
: m_params(params),
m_desc(desc)
{
bool only_pos = false;
bool only_pos = desc.flags & ParameterDesc::Flags::SwitchesAsPositional;
for (size_t i = 0; i < params.size(); ++i)
{
if (params[i] == "--")

View File

@ -50,6 +50,7 @@ struct ParameterDesc
{
None = 0,
SwitchesOnlyAtStart = 1,
SwitchesAsPositional = 2,
};
friend constexpr Flags operator|(Flags lhs, Flags rhs)
{