[Asterisk-code-review] aco: Use ast cli completion add for 'config show help'. (asterisk[master])
Joshua Colp
asteriskteam at digium.com
Tue Mar 20 08:31:49 CDT 2018
Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/8587 )
Change subject: aco: Use ast_cli_completion_add for 'config show help'.
......................................................................
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
---
M main/config_options.c
1 file changed, 37 insertions(+), 42 deletions(-)
Approvals:
George Joseph: Looks good to me, but someone else must approve
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Approved for Submit
diff --git a/main/config_options.c b/main/config_options.c
index 3aa00f9..41c8b22 100644
--- a/main/config_options.c
+++ b/main/config_options.c
@@ -958,88 +958,79 @@
/*! \internal
* \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);
- int which = 0;
struct ao2_iterator i;
struct ast_xml_doc_item *cur;
- if (pos != 3) {
- return NULL;
- }
-
i = ao2_iterator_init(xmldocs, 0);
while ((cur = ao2_iterator_next(&i))) {
- if (!strncasecmp(word, cur->name, wordlen) && ++which > state) {
- c = ast_strdup(cur->name);
- ao2_ref(cur, -1);
- break;
+ if (!strncasecmp(word, cur->name, wordlen)) {
+ if (ast_cli_completion_add(ast_strdup(cur->name))) {
+ ao2_ref(cur, -1);
+ break;
+ }
}
ao2_ref(cur, -1);
}
ao2_iterator_destroy(&i);
- return c;
+ return NULL;
}
/*! \internal
* \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);
- int which = 0;
- RAII_VAR(struct ast_xml_doc_item *, info, NULL, ao2_cleanup);
+ struct ast_xml_doc_item *info;
struct ast_xml_doc_item *cur;
- if (pos != 4) {
- return NULL;
- }
-
- if (!(info = ao2_find(xmldocs, module, OBJ_KEY))) {
+ info = ao2_find(xmldocs, module, OBJ_KEY);
+ if (!info) {
return NULL;
}
cur = info;
while ((cur = AST_LIST_NEXT(cur, next))) {
- if (!strcasecmp(cur->type, "configObject") && !strncasecmp(word, cur->name, wordlen) && ++which > state) {
- c = ast_strdup(cur->name);
- break;
+ if (!strcasecmp(cur->type, "configObject") && !strncasecmp(word, cur->name, wordlen)) {
+ if (ast_cli_completion_add(ast_strdup(cur->name))) {
+ break;
+ }
}
}
- return c;
+ ao2_ref(info, -1);
+
+ return NULL;
}
/*! \internal
* \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);
- int which = 0;
- RAII_VAR(struct ast_xml_doc_item *, info, NULL, ao2_cleanup);
+ struct ast_xml_doc_item *info;
struct ast_xml_doc_item *cur;
- if (pos != 5) {
- return NULL;
- }
-
- if (!(info = ao2_find(xmldocs, module, OBJ_KEY))) {
+ info = ao2_find(xmldocs, module, OBJ_KEY);
+ if (!info) {
return NULL;
}
cur = info;
while ((cur = AST_LIST_NEXT(cur, next))) {
- if (!strcasecmp(cur->type, "configOption") && !strcasecmp(cur->ref, option) && !strncasecmp(word, cur->name, wordlen) && ++which > state) {
- c = ast_strdup(cur->name);
- break;
+ if (!strcasecmp(cur->type, "configOption") && !strcasecmp(cur->ref, option) && !strncasecmp(word, cur->name, wordlen)) {
+ if (ast_cli_completion_add(ast_strdup(cur->name))) {
+ break;
+ }
}
}
- return c;
+ ao2_ref(info, -1);
+
+ return NULL;
}
/* Define as 0 if we want to allow configurations to be registered without
@@ -1340,10 +1331,14 @@
return NULL;
case CLI_GENERATE:
switch(a->pos) {
- case 3: return complete_config_module(a->word, a->pos, a->n);
- case 4: return complete_config_type(a->argv[3], a->word, a->pos, a->n);
- case 5: return complete_config_option(a->argv[3], a->argv[4], a->word, a->pos, a->n);
- default: return NULL;
+ case 3:
+ return complete_config_module(a->word);
+ case 4:
+ 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;
}
}
--
To view, visit https://gerrit.asterisk.org/8587
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I2da8eac2670d1d8d6474c04037129804f55ebf39
Gerrit-Change-Number: 8587
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180320/ba177a2d/attachment-0001.html>
More information about the asterisk-code-review
mailing list