aco: Use ast_cli_completion_add for 'config show help'.

In addition this removes:
* RAII_VAR usage
* Duplicate check of pos
* Unneeded arguments.

Change-Id: I2da8eac2670d1d8d6474c04037129804f55ebf39
certified/13.21
Corey Farrell 8 years ago
parent b50331626e
commit 18cbfcf4f0

@ -960,88 +960,79 @@ int aco_set_defaults(struct aco_type *type, const char *category, void *obj)
/*! \internal /*! \internal
* \brief Complete the name of the module the user is looking for * \brief Complete the name of the module the user is looking for
*/ */
static char *complete_config_module(const char *word, int pos, int state) static char *complete_config_module(const char *word)
{ {
char *c = NULL;
size_t wordlen = strlen(word); size_t wordlen = strlen(word);
int which = 0;
struct ao2_iterator i; struct ao2_iterator i;
struct ast_xml_doc_item *cur; struct ast_xml_doc_item *cur;
if (pos != 3) {
return NULL;
}
i = ao2_iterator_init(xmldocs, 0); i = ao2_iterator_init(xmldocs, 0);
while ((cur = ao2_iterator_next(&i))) { while ((cur = ao2_iterator_next(&i))) {
if (!strncasecmp(word, cur->name, wordlen) && ++which > state) { if (!strncasecmp(word, cur->name, wordlen)) {
c = ast_strdup(cur->name); if (ast_cli_completion_add(ast_strdup(cur->name))) {
ao2_ref(cur, -1); ao2_ref(cur, -1);
break; break;
} }
}
ao2_ref(cur, -1); ao2_ref(cur, -1);
} }
ao2_iterator_destroy(&i); ao2_iterator_destroy(&i);
return c; return NULL;
} }
/*! \internal /*! \internal
* \brief Complete the name of the configuration type the user is looking for * \brief Complete the name of the configuration type the user is looking for
*/ */
static char *complete_config_type(const char *module, const char *word, int pos, int state) static char *complete_config_type(const char *module, const char *word)
{ {
char *c = NULL;
size_t wordlen = strlen(word); size_t wordlen = strlen(word);
int which = 0; struct ast_xml_doc_item *info;
RAII_VAR(struct ast_xml_doc_item *, info, NULL, ao2_cleanup);
struct ast_xml_doc_item *cur; struct ast_xml_doc_item *cur;
if (pos != 4) { info = ao2_find(xmldocs, module, OBJ_KEY);
return NULL; if (!info) {
}
if (!(info = ao2_find(xmldocs, module, OBJ_KEY))) {
return NULL; return NULL;
} }
cur = info; cur = info;
while ((cur = AST_LIST_NEXT(cur, next))) { while ((cur = AST_LIST_NEXT(cur, next))) {
if (!strcasecmp(cur->type, "configObject") && !strncasecmp(word, cur->name, wordlen) && ++which > state) { if (!strcasecmp(cur->type, "configObject") && !strncasecmp(word, cur->name, wordlen)) {
c = ast_strdup(cur->name); if (ast_cli_completion_add(ast_strdup(cur->name))) {
break; break;
} }
} }
return c; }
ao2_ref(info, -1);
return NULL;
} }
/*! \internal /*! \internal
* \brief Complete the name of the configuration option the user is looking for * \brief Complete the name of the configuration option the user is looking for
*/ */
static char *complete_config_option(const char *module, const char *option, const char *word, int pos, int state) static char *complete_config_option(const char *module, const char *option, const char *word)
{ {
char *c = NULL;
size_t wordlen = strlen(word); size_t wordlen = strlen(word);
int which = 0; struct ast_xml_doc_item *info;
RAII_VAR(struct ast_xml_doc_item *, info, NULL, ao2_cleanup);
struct ast_xml_doc_item *cur; struct ast_xml_doc_item *cur;
if (pos != 5) { info = ao2_find(xmldocs, module, OBJ_KEY);
return NULL; if (!info) {
}
if (!(info = ao2_find(xmldocs, module, OBJ_KEY))) {
return NULL; return NULL;
} }
cur = info; cur = info;
while ((cur = AST_LIST_NEXT(cur, next))) { while ((cur = AST_LIST_NEXT(cur, next))) {
if (!strcasecmp(cur->type, "configOption") && !strcasecmp(cur->ref, option) && !strncasecmp(word, cur->name, wordlen) && ++which > state) { if (!strcasecmp(cur->type, "configOption") && !strcasecmp(cur->ref, option) && !strncasecmp(word, cur->name, wordlen)) {
c = ast_strdup(cur->name); if (ast_cli_completion_add(ast_strdup(cur->name))) {
break; break;
} }
} }
return c; }
ao2_ref(info, -1);
return NULL;
} }
/* Define as 0 if we want to allow configurations to be registered without /* Define as 0 if we want to allow configurations to be registered without
@ -1342,10 +1333,14 @@ static char *cli_show_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args
return NULL; return NULL;
case CLI_GENERATE: case CLI_GENERATE:
switch(a->pos) { switch(a->pos) {
case 3: return complete_config_module(a->word, a->pos, a->n); case 3:
case 4: return complete_config_type(a->argv[3], a->word, a->pos, a->n); return complete_config_module(a->word);
case 5: return complete_config_option(a->argv[3], a->argv[4], a->word, a->pos, a->n); case 4:
default: return NULL; return complete_config_type(a->argv[3], a->word);
case 5:
return complete_config_option(a->argv[3], a->argv[4], a->word);
default:
return NULL;
} }
} }

Loading…
Cancel
Save