diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-02-08 19:04:20 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-02-08 19:04:20 +0000 |
| commit | a94c554a7bd9c290b6ba19f65e95c3dd62f65ce0 (patch) | |
| tree | 1cc1dc1354129b9658489bd2bb2a10b873803758 /src/command_manager.cc | |
| parent | 0a2f2c2247a5226978b997b9c160e0f8716a4883 (diff) | |
Add optional helper for commands, to get parameter dependent help
Use for the set command to document options.
Diffstat (limited to 'src/command_manager.cc')
| -rw-r--r-- | src/command_manager.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc index 0b9e65a2..918db6f8 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -22,12 +22,14 @@ void CommandManager::register_command(String command_name, String docstring, ParameterDesc param_desc, CommandFlags flags, + CommandHelper helper, CommandCompleter completer) { m_commands[command_name] = { std::move(command), std::move(docstring), std::move(param_desc), flags, + std::move(helper), std::move(completer) }; } @@ -458,6 +460,25 @@ CommandInfo CommandManager::command_info(const Context& context, StringView comm if (not cmd->second.docstring.empty()) res.second += cmd->second.docstring + "\n"; + if (cmd->second.helper) + { + Vector<String> params; + for (auto it = tokens.begin() + cmd_idx + 1; + it != tokens.end() and it->type() != Token::Type::CommandSeparator; + ++it) + { + if (it->type() == Token::Type::Raw or it->type() == Token::Type::RawEval) + params.push_back(it->content()); + } + String helpstr = cmd->second.helper(context, params); + if (not helpstr.empty()) + { + if (helpstr.back() != '\n') + helpstr += '\n'; + res.second += helpstr; + } + } + String aliases; for (auto& alias : context.aliases().aliases_for(cmd->first)) aliases += " " + alias; |
