From: Michal Privoznik Date: Tue, 2 Feb 2021 13:55:28 +0000 (+0100) Subject: vsh: Don't put VSH_OT_ALIAS onto list of completions X-Git-Tag: v7.1.0-rc1~215 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58aeebe0965e2653ecd64af2c809a48eef8fed21;p=thirdparty%2Flibvirt.git vsh: Don't put VSH_OT_ALIAS onto list of completions We've invented VSH_OT_ALIAS type for --option so that we can rewrite some --options (e.g. fix spelling). For instance blkdeviotune command uses this feature heavily: --options-with-dash are preferred over old --options_with_underscore. Both versions are supported but only the new ones (not aliased) are documented and reported in --help. Except for options completer, which happily put also aliased versions in front of user's eyes. Note, there is a second (gross) way we use aliases: to rewrite options from --oldoption to --newoption=value (for instance --shareable option of attach-disk is an alias of --mode=shareable). And just like with the previous group - don't generate them into the list of possible options. Signed-off-by: Michal Privoznik Reviewed-by: Jonathon Jongsma --- diff --git a/tools/vsh.c b/tools/vsh.c index 289ed82dbe..3771ad50e9 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2614,7 +2614,6 @@ vshReadlineOptionsGenerator(const char *text, { size_t list_index = 0; size_t len = strlen(text); - const char *name; size_t ret_size = 0; char **ret = NULL; @@ -2624,12 +2623,15 @@ vshReadlineOptionsGenerator(const char *text, if (!cmd->opts) return NULL; - while ((name = cmd->opts[list_index].name)) { + for (list_index = 0; cmd->opts[list_index].name; list_index++) { + const char *name = cmd->opts[list_index].name; bool exists = false; vshCmdOpt *opt = last->opts; size_t name_len; - list_index++; + /* Skip aliases, we do not report them in help output either. */ + if (cmd->opts[list_index].type == VSH_OT_ALIAS) + continue; if (len > 2) { /* provide auto-complete only when the text starts with -- */