From c3988c68593edfdc569d383a3b007eda45925ccc Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 18 Oct 2018 13:59:41 -0700 Subject: [PATCH] modules/console: Split console_command entry function for internal use. --- modules/console.cc | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/modules/console.cc b/modules/console.cc index c0f433db6..7a76bf459 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -174,6 +174,28 @@ find_cmd(const string_view &line) int console_command_derived(opt &, const string_view &line); +static int +_console_command(opt &out, + const string_view &line) +{ + const cmd *const cmd + { + find_cmd(line) + }; + + if(!cmd) + return console_command_derived(out, line); + + const auto args + { + lstrip(split(line, cmd->name).second, ' ') + }; + + const auto &ptr{cmd->ptr}; + using prototype = bool (struct opt &, const string_view &); + return ptr.operator()(out, args); +} + /// This function may be linked and called by those wishing to execute a /// command. Output from the command will be appended to the provided ostream. /// The input to the command is passed in `line`. Since `struct opt` is not @@ -191,22 +213,7 @@ try has(opts, "html") }; - const cmd *const cmd - { - find_cmd(line) - }; - - if(!cmd) - return console_command_derived(opt, line); - - const auto args - { - lstrip(split(line, cmd->name).second, ' ') - }; - - const auto &ptr{cmd->ptr}; - using prototype = bool (struct opt &, const string_view &); - return ptr.operator()(opt, args); + return _console_command(opt, line); } catch(const params::error &e) {