Add help console command

This commit is contained in:
yvt 2019-07-14 23:34:40 +09:00
parent 008c687e83
commit bb4675ca00
No known key found for this signature in database
GPG Key ID: 48F2768FA8D07C92
2 changed files with 31 additions and 1 deletions

View File

@ -21,6 +21,7 @@
#include <ScriptBindings/ScriptFunction.h> #include <ScriptBindings/ScriptFunction.h>
#include "ConfigConsoleResponder.h" #include "ConfigConsoleResponder.h"
#include "ConsoleCommand.h"
#include "ConsoleHelper.h" #include "ConsoleHelper.h"
#include "ConsoleScreen.h" #include "ConsoleScreen.h"
@ -214,15 +215,41 @@ namespace spades {
return subview->WantsToBeClosed(); return subview->WantsToBeClosed();
} }
void ConsoleScreen::DumpAllCommands() {
SPADES_MARK_FUNCTION();
auto it = AutocompleteCommandName("");
while (it->MoveNext()) {
const auto &cmd = it->GetCurrent();
SPLog("%s %s", cmd.name.c_str(), cmd.description.c_str());
}
}
namespace {
constexpr const char *CMD_HELP = "help";
std::map<std::string, std::string> const g_commands{
{CMD_HELP, ": Display all available commands"},
};
} // namespace
bool ConsoleScreen::ExecCommand(const Handle<ConsoleCommand> &command) { bool ConsoleScreen::ExecCommand(const Handle<ConsoleCommand> &command) {
SPADES_MARK_FUNCTION(); SPADES_MARK_FUNCTION();
if (command->GetName() == CMD_HELP) {
if (command->GetNumArguments() != 0) {
SPLog("Usage: help (no arguments)");
return true;
}
DumpAllCommands();
return true;
}
return ConfigConsoleResponder::ExecCommand(command) || subview->ExecCommand(command); return ConfigConsoleResponder::ExecCommand(command) || subview->ExecCommand(command);
} }
Handle<ConsoleCommandCandidateIterator> Handle<ConsoleCommandCandidateIterator>
ConsoleScreen::AutocompleteCommandName(const std::string &name) { ConsoleScreen::AutocompleteCommandName(const std::string &name) {
SPADES_MARK_FUNCTION(); SPADES_MARK_FUNCTION();
return ConfigConsoleResponder::AutocompleteCommandName(name) + return MakeCandidates(g_commands, name) +
ConfigConsoleResponder::AutocompleteCommandName(name) +
subview->AutocompleteCommandName(name); subview->AutocompleteCommandName(name);
} }

View File

@ -68,6 +68,9 @@ namespace spades {
bool ShouldInterceptInput(); bool ShouldInterceptInput();
void ToggleConsole(); void ToggleConsole();
void AddLine(const std::string &); void AddLine(const std::string &);
/** Dump all available commands to `SPLog`. */
void DumpAllCommands();
}; };
} // namespace gui } // namespace gui
} // namespace spades } // namespace spades