Fix support for switches style option in user commands
This commit is contained in:
parent
c48bdbe4f1
commit
dc953197c3
|
@ -597,7 +597,7 @@ void define_command(const ParametersParser& parser, Context& context)
|
||||||
ParameterDesc desc;
|
ParameterDesc desc;
|
||||||
if (parser.has_option("env-params"))
|
if (parser.has_option("env-params"))
|
||||||
{
|
{
|
||||||
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None };
|
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::SwitchesAsPositional };
|
||||||
cmd = [=](const ParametersParser& parser, Context& context) {
|
cmd = [=](const ParametersParser& parser, Context& context) {
|
||||||
CommandManager::instance().execute(commands, context, {},
|
CommandManager::instance().execute(commands, context, {},
|
||||||
params_to_env_var_map(parser));
|
params_to_env_var_map(parser));
|
||||||
|
@ -605,14 +605,14 @@ void define_command(const ParametersParser& parser, Context& context)
|
||||||
}
|
}
|
||||||
if (parser.has_option("shell-params"))
|
if (parser.has_option("shell-params"))
|
||||||
{
|
{
|
||||||
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None };
|
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::SwitchesAsPositional };
|
||||||
cmd = [=](const ParametersParser& parser, Context& context) {
|
cmd = [=](const ParametersParser& parser, Context& context) {
|
||||||
CommandManager::instance().execute(commands, context, params_to_shell(parser));
|
CommandManager::instance().execute(commands, context, params_to_shell(parser));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None, 0, 0 };
|
desc = ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::SwitchesAsPositional, 0, 0 };
|
||||||
cmd = [=](const ParametersParser& parser, Context& context) {
|
cmd = [=](const ParametersParser& parser, Context& context) {
|
||||||
CommandManager::instance().execute(commands, context);
|
CommandManager::instance().execute(commands, context);
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,7 @@ ParametersParser::ParametersParser(ParameterList params,
|
||||||
: m_params(params),
|
: m_params(params),
|
||||||
m_desc(desc)
|
m_desc(desc)
|
||||||
{
|
{
|
||||||
bool only_pos = false;
|
bool only_pos = desc.flags & ParameterDesc::Flags::SwitchesAsPositional;
|
||||||
for (size_t i = 0; i < params.size(); ++i)
|
for (size_t i = 0; i < params.size(); ++i)
|
||||||
{
|
{
|
||||||
if (params[i] == "--")
|
if (params[i] == "--")
|
||||||
|
|
|
@ -50,6 +50,7 @@ struct ParameterDesc
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
SwitchesOnlyAtStart = 1,
|
SwitchesOnlyAtStart = 1,
|
||||||
|
SwitchesAsPositional = 2,
|
||||||
};
|
};
|
||||||
friend constexpr Flags operator|(Flags lhs, Flags rhs)
|
friend constexpr Flags operator|(Flags lhs, Flags rhs)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user