diff options
| author | Justin Frank <justinpfrank@protonmail.com> | 2019-03-12 10:34:30 -0700 |
|---|---|---|
| committer | Justin Frank <justinpfrank@protonmail.com> | 2019-04-08 17:02:44 -0700 |
| commit | 6092852640096c777f700cf669666504b10e2a58 (patch) | |
| tree | 4d609cd77a8363c10e7286a6a46bf7a3aa251a26 /src/command_manager.cc | |
| parent | 670f8192c8d68c33e42b95847edd0678f87ca39b (diff) | |
Added 'provide-module' and 'require-module' commands
Diffstat (limited to 'src/command_manager.cc')
| -rw-r--r-- | src/command_manager.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc index 5e8c8196..91c41bd3 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -40,6 +40,33 @@ void CommandManager::register_command(String command_name, std::move(completer) }; } +bool CommandManager::module_defined(StringView module_name) const +{ + return m_modules.find(module_name) != m_modules.end(); +} + +void CommandManager::register_module(String module_name, String commands) +{ + auto module = m_modules.find(module_name); + if (module != m_modules.end() and module->value.loaded) + throw runtime_error{format("module already loaded: '{}'", module_name)}; + + m_modules[module_name] = { false, std::move(commands) }; +} + +void CommandManager::load_module(StringView module_name, Context& context) +{ + auto module = m_modules.find(module_name); + if (module == m_modules.end()) + throw runtime_error{format("no such module: '{}'", module_name)}; + if (module->value.loaded) + return; + + module->value.loaded = true; + execute(module->value.commands, context); + module->value.commands.clear(); +} + struct parse_error : runtime_error { parse_error(StringView error) |
