Change functions to commands

The module commands operations are now listed as `commands` instead of
`functions`. The output was also formatted and an optional filtering was
added to the `list commands` call.
This commit is contained in:
Markus Makela
2016-11-30 15:01:25 +02:00
parent 3ed4ef40ba
commit bc3d6f2ac7

View File

@ -290,8 +290,8 @@ bool listfuncs_cb(const MODULECMD *cmd, void *data)
{ {
DCB *dcb = (DCB*)data; DCB *dcb = (DCB*)data;
dcb_printf(dcb, "%s::%s(", cmd->domain, cmd->identifier); dcb_printf(dcb, "Command: %s %s\n", cmd->domain, cmd->identifier);
dcb_printf(dcb, "Parameters: ");
for (int i = 0; i < cmd->arg_count_max; i++) for (int i = 0; i < cmd->arg_count_max; i++)
{ {
@ -309,8 +309,7 @@ bool listfuncs_cb(const MODULECMD *cmd, void *data)
} }
} }
dcb_printf(dcb, ")\n"); dcb_printf(dcb, "\n\n");
for (int i = 0; i < cmd->arg_count_max; i++) for (int i = 0; i < cmd->arg_count_max; i++)
{ {
@ -334,9 +333,9 @@ bool listfuncs_cb(const MODULECMD *cmd, void *data)
return true; return true;
} }
void dListFunctions(DCB *dcb) void dListCommands(DCB *dcb, const char *domain, const char *ident)
{ {
modulecmd_foreach(NULL, NULL, listfuncs_cb, dcb); modulecmd_foreach(domain, ident, listfuncs_cb, dcb);
} }
/** /**
@ -405,10 +404,13 @@ struct subcommand listoptions[] =
{0, 0, 0} {0, 0, 0}
}, },
{ {
"functions", 0, 0, dListFunctions, "commands", 0, 2, dListCommands,
"List registered functions", "List registered commands",
"List all registered functions", "Usage list commands [DOMAIN] [COMMAND]\n"
{0} "Parameters:\n"
"DOMAIN Regular expressions for filtering module domains\n"
"COMMAND Regular expressions for filtering module commands\n",
{ARG_TYPE_STRING, ARG_TYPE_STRING}
}, },
{ EMPTY_OPTION} { EMPTY_OPTION}
}; };
@ -1385,7 +1387,7 @@ static inline bool requires_output_dcb(const MODULECMD *cmd)
return cmd->arg_count_max > 0 && MODULECMD_GET_TYPE(type) == MODULECMD_ARG_OUTPUT; return cmd->arg_count_max > 0 && MODULECMD_GET_TYPE(type) == MODULECMD_ARG_OUTPUT;
} }
static void callFunction(DCB *dcb, char *domain, char *id, char *v3, static void callModuleCommand(DCB *dcb, char *domain, char *id, char *v3,
char *v4, char *v5, char *v6, char *v7, char *v8, char *v9, char *v4, char *v5, char *v6, char *v7, char *v8, char *v9,
char *v10, char *v11, char *v12) char *v10, char *v11, char *v12)
{ {
@ -1404,7 +1406,7 @@ static void callFunction(DCB *dcb, char *domain, char *id, char *v3,
{ {
if (requires_output_dcb(cmd)) if (requires_output_dcb(cmd))
{ {
/** The function requires a DCB for output, add the client DCB /** The command requires a DCB for output, add the client DCB
* as the first argument */ * as the first argument */
for (int i = valuelen - 1; i > 0; i--) for (int i = valuelen - 1; i > 0; i--)
{ {
@ -1438,10 +1440,10 @@ static void callFunction(DCB *dcb, char *domain, char *id, char *v3,
struct subcommand calloptions[] = struct subcommand calloptions[] =
{ {
{ {
"function", 2, 12, callFunction, "command", 2, 12, callModuleCommand,
"Call module function", "Call module command",
"Usage: call function NAMESPACE FUNCTION ARGS...\n" "Usage: call command NAMESPACE COMMAND ARGS...\n"
"To list all registered functions, run 'list functions'.\n", "To list all registered commands, run 'list commands'.\n",
{ ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, { ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING,
ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING,
ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING} ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING, ARG_TYPE_STRING}