CommandManager: use directly first command parameter as the command name
This commit is contained in:
parent
66d91b8828
commit
95db828e17
|
@ -65,33 +65,27 @@ void CommandManager::execute(const std::string& command_line,
|
||||||
if (tokens.empty())
|
if (tokens.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string command_name =
|
|
||||||
command_line.substr(tokens[0].first,
|
|
||||||
tokens[0].second - tokens[0].first);
|
|
||||||
|
|
||||||
auto command_it = m_commands.find(command_name);
|
|
||||||
if (command_it == m_commands.end())
|
|
||||||
throw command_not_found(command_name);
|
|
||||||
|
|
||||||
CommandParameters params;
|
CommandParameters params;
|
||||||
for (auto it = tokens.begin() + 1; it != tokens.end(); ++it)
|
for (auto it = tokens.begin(); it != tokens.end(); ++it)
|
||||||
{
|
{
|
||||||
params.push_back(command_line.substr(it->first,
|
params.push_back(command_line.substr(it->first,
|
||||||
it->second - it->first));
|
it->second - it->first));
|
||||||
}
|
}
|
||||||
|
|
||||||
command_it->second.command(params, context);
|
execute(params, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandManager::execute(const std::string& command,
|
void CommandManager::execute(const CommandParameters& params,
|
||||||
const CommandParameters& params,
|
|
||||||
const Context& context)
|
const Context& context)
|
||||||
{
|
{
|
||||||
auto command_it = m_commands.find(command);
|
if (params.empty())
|
||||||
if (command_it == m_commands.end())
|
return;
|
||||||
throw command_not_found(command);
|
|
||||||
|
|
||||||
command_it->second.command(params, context);
|
auto command_it = m_commands.find(params[0]);
|
||||||
|
if (command_it == m_commands.end())
|
||||||
|
throw command_not_found(params[0]);
|
||||||
|
|
||||||
|
command_it->second.command(CommandParameters(params.begin() + 1, params.end()), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Completions CommandManager::complete(const std::string& command_line, size_t cursor_pos)
|
Completions CommandManager::complete(const std::string& command_line, size_t cursor_pos)
|
||||||
|
|
|
@ -54,8 +54,7 @@ class CommandManager : public Singleton<CommandManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void execute(const std::string& command_line, const Context& context);
|
void execute(const std::string& command_line, const Context& context);
|
||||||
void execute(const std::string& command, const CommandParameters& params,
|
void execute(const CommandParameters& params, const Context& context);
|
||||||
const Context& context);
|
|
||||||
|
|
||||||
Completions complete(const std::string& command_line, size_t cursor_pos);
|
Completions complete(const std::string& command_line, size_t cursor_pos);
|
||||||
|
|
||||||
|
|
|
@ -531,15 +531,13 @@ void add_hook(const CommandParameters& params, const Context& context)
|
||||||
if (params.size() < 3)
|
if (params.size() < 3)
|
||||||
throw wrong_argument_count();
|
throw wrong_argument_count();
|
||||||
|
|
||||||
std::string command = params[2];
|
CommandParameters hook_params(params.begin()+2, params.end());
|
||||||
CommandParameters hook_params(params.begin()+3, params.end());
|
|
||||||
|
|
||||||
HooksManager::instance().add_hook(
|
HooksManager::instance().add_hook(
|
||||||
params[0],
|
params[0],
|
||||||
[=](const std::string& param, const Context& context) {
|
[=](const std::string& param, const Context& context) {
|
||||||
if (boost::regex_match(param, boost::regex(params[1])))
|
if (boost::regex_match(param, boost::regex(params[1])))
|
||||||
CommandManager::instance().execute(command, hook_params,
|
CommandManager::instance().execute(hook_params, context);
|
||||||
context);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user