From e4048085a8742490e613fa960a4749bd5530fc88 Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Fri, 8 Feb 2013 14:27:40 +0100 Subject: cli: Handle arguments to the "help" command When arguments are supplied to the "help" command, only display help messages corresponding to the command these arguments refer to (e.g. "help pppoe" will only show help messages for commands starting with "pppoe"). Signed-off-by: Guillaume Nault --- accel-pppd/cli/cli.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'accel-pppd/cli') diff --git a/accel-pppd/cli/cli.c b/accel-pppd/cli/cli.c index e7e9e92a..a9d5a4cc 100644 --- a/accel-pppd/cli/cli.c +++ b/accel-pppd/cli/cli.c @@ -171,6 +171,7 @@ static int cli_process_help_cmd(struct cli_client_t *cln) struct cli_simple_cmd_t *sicmd = NULL; char *cmd = (char *)cln->cmdline; char *items[MAX_CMD_ITEMS] = { 0 }; + int cmd_found = 0; int nb_items; cmd = skip_space(cmd); @@ -182,19 +183,40 @@ static int cli_process_help_cmd(struct cli_client_t *cln) cmd = skip_space(cmd + helpcmd_len); + if (cmd[0] == '\0') + /* "help" with no argument always succeeds */ + cmd_found = 1; + list_for_each_entry(recmd, ®exp_cmd_list, entry) { if (cmd[0] == '\0' || pcre_exec(recmd->h_re, NULL, cmd, strlen(cmd), 0, 0, NULL, 0) >= 0) { + cmd_found = 1; if (recmd->help) recmd->help(cmd, cln); } } nb_items = split(cmd, items); - list_for_each_entry(sicmd, &simple_cmd_list, entry) - if (sicmd->help) - sicmd->help(items, nb_items, cln); + list_for_each_entry(sicmd, &simple_cmd_list, entry) { + int indx = 0; + int found = 1; + while (indx < sicmd->hdr_len && indx < nb_items) { + if (strcmp(sicmd->hdr[indx], items[indx]) != 0) { + found = 0; + break; + } + ++indx; + } + if (found) { + cmd_found = 1; + if (sicmd->help) + sicmd->help(items, nb_items, cln); + } + } + + if (!cmd_found) + cli_send(cln, MSG_INVAL_ERROR); return 1; } -- cgit v1.2.3