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:
parent
0787246e23
commit
c3988c6859
1 changed files with 23 additions and 16 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue