diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-01-14 14:02:54 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-01-14 14:02:54 +0000 |
| commit | 95db828e170c48696fb67e869989a01e34516647 (patch) | |
| tree | 241aabe3fdd7591f07c95e1668d6fe0acf6865fc /src/command_manager.cc | |
| parent | 66d91b8828470c9ea89af11cbfe5060993155f83 (diff) | |
CommandManager: use directly first command parameter as the command name
Diffstat (limited to 'src/command_manager.cc')
| -rw-r--r-- | src/command_manager.cc | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc index 5d5e4e69..542466d4 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -65,33 +65,27 @@ void CommandManager::execute(const std::string& command_line, if (tokens.empty()) 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; - 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, it->second - it->first)); } - command_it->second.command(params, context); + execute(params, context); } -void CommandManager::execute(const std::string& command, - const CommandParameters& params, +void CommandManager::execute(const CommandParameters& params, const Context& context) { - auto command_it = m_commands.find(command); + if (params.empty()) + return; + + auto command_it = m_commands.find(params[0]); if (command_it == m_commands.end()) - throw command_not_found(command); + throw command_not_found(params[0]); - command_it->second.command(params, context); + command_it->second.command(CommandParameters(params.begin() + 1, params.end()), context); } Completions CommandManager::complete(const std::string& command_line, size_t cursor_pos) |
