From ea8a610776ca80ddb2302543e32b487896ad2f5c Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Sat, 11 Feb 2017 10:57:03 -0500 Subject: cli: Fix various CLI documentation and completion issues * app_minivm: Use built-in completion facilities to complete optional arguments. * app_voicemail: Use built-in completion facilities to complete optional arguments. * app_confbridge: Add missing colons after 'Usage' text. * chan_alsa: Use built-in completion facilities to complete optional arguments. * chan_sip: Use built-in completion facilities to complete optional arguments. Add completions for 'load' for 'sip show user', 'sip show peer', and 'sip qualify peer.' * chan_skinny: Correct and extend completions for 'skinny reset' and 'skinny show line.' * func_odbc: Correct completions for 'odbc read' and 'odbc write' * main/asterisk: Correct and extend completions for 'core show file version.' * main/astmm: Use built-in completion facilities to complete arguments for 'memory' commands. * main/bridge: Correct completions for 'bridge kick.' * main/ccss: Use built-in completion facilities to complete arguments for 'cc cancel' command. * main/cli: Add 'all' completion for 'channel request hangup.' Correct completions for 'core set debug channel.' Correct completions for 'core show calls.' * main/pbx_app: Remove redundant completions for 'core show applications.' * main/pbx_hangup_handler: Remove unused completions for 'core show hanguphandlers all.' * res_sorcery_memory_cache: Add completion for 'reload' argument of 'sorcery memory cache stale' and properly implement. Change-Id: Iee58c7392f6fec34ad9d596109117af87697bbca --- channels/chan_alsa.c | 20 ++------------------ channels/chan_sip.c | 27 +++++++++++++++++++++------ channels/chan_skinny.c | 40 ++++++++++++++++++++++++++++------------ 3 files changed, 51 insertions(+), 36 deletions(-) (limited to 'channels') diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c index 6508a1e07..61ea2e719 100644 --- a/channels/chan_alsa.c +++ b/channels/chan_alsa.c @@ -639,29 +639,13 @@ static struct ast_channel *alsa_request(const char *type, struct ast_format_cap return tmp; } -static char *autoanswer_complete(const char *line, const char *word, int pos, int state) -{ - switch (state) { - case 0: - if (!ast_strlen_zero(word) && !strncasecmp(word, "on", MIN(strlen(word), 2))) - return ast_strdup("on"); - case 1: - if (!ast_strlen_zero(word) && !strncasecmp(word, "off", MIN(strlen(word), 3))) - return ast_strdup("off"); - default: - return NULL; - } - - return NULL; -} - static char *console_autoanswer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { char *res = CLI_SUCCESS; switch (cmd) { case CLI_INIT: - e->command = "console autoanswer"; + e->command = "console autoanswer [on|off]"; e->usage = "Usage: console autoanswer [on|off]\n" " Enables or disables autoanswer feature. If used without\n" @@ -669,7 +653,7 @@ static char *console_autoanswer(struct ast_cli_entry *e, int cmd, struct ast_cli " The default value of autoanswer is in 'alsa.conf'.\n"; return NULL; case CLI_GENERATE: - return autoanswer_complete(a->line, a->word, a->pos, a->n); + return NULL; } if ((a->argc != 2) && (a->argc != 3)) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 83f72b9ad..f31302e8b 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -19527,7 +19527,7 @@ static char *sip_show_inuse(struct ast_cli_entry *e, int cmd, struct ast_cli_arg switch (cmd) { case CLI_INIT: - e->command = "sip show inuse"; + e->command = "sip show inuse [all]"; e->usage = "Usage: sip show inuse [all]\n" " List all SIP devices usage counters and limits.\n" @@ -19717,7 +19717,7 @@ static char *sip_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_arg switch (cmd) { case CLI_INIT: - e->command = "sip show users"; + e->command = "sip show users [like]"; e->usage = "Usage: sip show users [like ]\n" " Lists all known SIP users.\n" @@ -19856,7 +19856,7 @@ static char *sip_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_arg { switch (cmd) { case CLI_INIT: - e->command = "sip show peers"; + e->command = "sip show peers [like]"; e->usage = "Usage: sip show peers [like ]\n" " Lists all known SIP peers.\n" @@ -20570,7 +20570,12 @@ static char *sip_show_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args " Option \"load\" forces lookup of peer in realtime storage.\n"; return NULL; case CLI_GENERATE: - return complete_sip_show_peer(a->line, a->word, a->pos, a->n); + if (a->pos == 4) { + static const char * const completions[] = { "load", NULL }; + return ast_cli_complete(a->word, completions, a->n); + } else { + return complete_sip_show_peer(a->line, a->word, a->pos, a->n); + } } return _sip_show_peer(0, a->fd, NULL, NULL, a->argc, (const char **) a->argv); } @@ -20740,7 +20745,12 @@ static char *sip_qualify_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_a " Option \"load\" forces lookup of peer in realtime storage.\n"; return NULL; case CLI_GENERATE: - return complete_sip_show_peer(a->line, a->word, a->pos, a->n); + if (a->pos == 4) { + static const char * const completions[] = { "load", NULL }; + return ast_cli_complete(a->word, completions, a->n); + } else { + return complete_sip_show_peer(a->line, a->word, a->pos, a->n); + } } return _sip_qualify_peer(0, a->fd, NULL, NULL, a->argc, (const char **) a->argv); } @@ -21111,7 +21121,12 @@ static char *sip_show_user(struct ast_cli_entry *e, int cmd, struct ast_cli_args " Option \"load\" forces lookup of peer in realtime storage.\n"; return NULL; case CLI_GENERATE: - return complete_sip_show_user(a->line, a->word, a->pos, a->n); + if (a->pos == 4) { + static const char * const completions[] = { "load", NULL }; + return ast_cli_complete(a->word, completions, a->n); + } else { + return complete_sip_show_user(a->line, a->word, a->pos, a->n); + } } if (a->argc < 4) diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index 5cdfe1b78..9cde77540 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -3924,24 +3924,40 @@ static char *complete_skinny_show_device(const char *line, const char *word, int static char *complete_skinny_reset(const char *line, const char *word, int pos, int state) { - return (pos == 2 ? complete_skinny_devices(word, state) : NULL); + if (pos == 2) { + static const char * const completions[] = { "all", NULL }; + char *ret = ast_cli_complete(word, completions, state); + if (!ret) { + ret = complete_skinny_devices(word, state - 1); + } + return ret; + } else if (pos == 3) { + static const char * const completions[] = { "restart", NULL }; + return ast_cli_complete(word, completions, state); + } + + return NULL; } static char *complete_skinny_show_line(const char *line, const char *word, int pos, int state) { - struct skinny_device *d; - struct skinny_line *l; - int wordlen = strlen(word), which = 0; + if (pos == 3) { + struct skinny_device *d; + struct skinny_line *l; + int wordlen = strlen(word), which = 0; - if (pos != 3) - return NULL; - - AST_LIST_TRAVERSE(&devices, d, list) { - AST_LIST_TRAVERSE(&d->lines, l, list) { - if (!strncasecmp(word, l->name, wordlen) && ++which > state) { - return ast_strdup(l->name); + AST_LIST_TRAVERSE(&devices, d, list) { + AST_LIST_TRAVERSE(&d->lines, l, list) { + if (!strncasecmp(word, l->name, wordlen) && ++which > state) { + return ast_strdup(l->name); + } } } + } else if (pos == 4) { + static const char * const completions[] = { "on", NULL }; + return ast_cli_complete(word, completions, state); + } else if (pos == 5) { + return complete_skinny_devices(word, state); } return NULL; @@ -4583,7 +4599,7 @@ static char *handle_skinny_show_line(struct ast_cli_entry *e, int cmd, struct as case CLI_INIT: e->command = "skinny show line"; e->usage = - "Usage: skinny show line [ on ]\n" + "Usage: skinny show line [on ]\n" " List all lineinformation of a specific line known to the Skinny subsystem.\n"; return NULL; case CLI_GENERATE: -- cgit v1.2.3