summaryrefslogtreecommitdiff
path: root/main/cli.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2017-10-30 18:30:18 -0400
committerCorey Farrell <git@cfware.com>2017-11-02 08:29:47 -0400
commitaf2947c013b2ce15c2e65f10fd80df233ec58569 (patch)
tree1f6494f53b8daa57ad0ed3960f5eb25bae7c9fd3 /main/cli.c
parent21b922b565bdba9254445d1002a8a077d50ebe88 (diff)
Modules: Additional improvements to CLI completion.
Replace 'needsreload' argument with a 'type' argument to specify which type of modules you want completion. This provides more accurate CLI completion for load and unload commands. * 'module unload' now excludes modules that have active references or are not running. * 'module load' now excludes modules that are already running. * 'core set debug [atleast] <level> [module]' shows running modules only. ASTERISK-27378 Change-Id: Iea3e00054461484196c46f688f02635cc886bad1
Diffstat (limited to 'main/cli.c')
-rw-r--r--main/cli.c44
1 files changed, 12 insertions, 32 deletions
diff --git a/main/cli.c b/main/cli.c
index d9aab85cb..0896181b0 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -45,7 +45,6 @@
#include <regex.h>
#include <pwd.h>
#include <grp.h>
-#include <editline/readline.h>
#include "asterisk/cli.h"
#include "asterisk/linkedlists.h"
@@ -224,28 +223,6 @@ static int cli_has_permissions(int uid, int gid, const char *command)
static AST_RWLIST_HEAD_STATIC(helpers, ast_cli_entry);
-static char *complete_fn(const char *word, int state)
-{
- char *c, *d;
- char filename[PATH_MAX];
-
- if (word[0] == '/')
- ast_copy_string(filename, word, sizeof(filename));
- else
- snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word);
-
- c = d = filename_completion_function(filename, state);
-
- if (c && word[0] != '/')
- c += (strlen(ast_config_AST_MODULE_DIR) + 1);
- if (c)
- c = ast_strdup(c);
-
- ast_std_free(d);
-
- return c;
-}
-
static char *handle_load(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
/* "module load <mod>" */
@@ -258,12 +235,14 @@ static char *handle_load(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
return NULL;
case CLI_GENERATE:
- if (a->pos != e->args)
+ if (a->pos != e->args) {
return NULL;
- return complete_fn(a->word, a->n);
+ }
+ return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, AST_MODULE_HELPER_LOAD);
}
- if (a->argc != e->args + 1)
+ if (a->argc != e->args + 1) {
return CLI_SHOWUSAGE;
+ }
if (ast_load_resource(a->argv[e->args])) {
ast_cli(a->fd, "Unable to load module %s\n", a->argv[e->args]);
return CLI_FAILURE;
@@ -286,7 +265,7 @@ static char *handle_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args
return NULL;
case CLI_GENERATE:
- return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 1);
+ return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, AST_MODULE_HELPER_RELOAD);
}
if (a->argc == e->args) {
ast_module_reload(NULL);
@@ -482,7 +461,7 @@ static char *handle_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args
}
} else if ((a->pos == 4 && !atleast && strcasecmp(argv3, "off") && strcasecmp(argv3, "channel"))
|| (a->pos == 5 && atleast)) {
- return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 0);
+ return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, AST_MODULE_HELPER_RUNNING);
}
return NULL;
}
@@ -733,7 +712,7 @@ static char *handle_unload(struct ast_cli_entry *e, int cmd, struct ast_cli_args
return NULL;
case CLI_GENERATE:
- return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 0);
+ return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, AST_MODULE_HELPER_UNLOAD);
}
if (a->argc < e->args + 1)
return CLI_SHOWUSAGE;
@@ -889,10 +868,11 @@ static char *handle_modlist(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
return NULL;
case CLI_GENERATE:
- if (a->pos == e->args)
- return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 0);
- else
+ if (a->pos == e->args) {
+ return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, AST_MODULE_HELPER_LOADED);
+ } else {
return NULL;
+ }
}
/* all the above return, so we proceed with the handler.
* we are guaranteed to have argc >= e->args