0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 02:02:38 +01:00

modules/console: Split console_command entry function for internal use.

This commit is contained in:
Jason Volk 2018-10-18 13:59:41 -07:00
parent 0787246e23
commit c3988c6859

View file

@ -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()<prototype>(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()<prototype>(opt, args);
return _console_command(opt, line);
}
catch(const params::error &e)
{