vsh: Simplify condition for calling completer callback
The way we currently call completer callbacks is that if we've found --option that user wants to complete value for and it has callback set then the callback is called. And just before that, if no --option to have the value completed is found or is found and is of boolean type then a list of --option is generated (for given command). But these two conditions can never be true at the same time because boolean type of --options do not accept values. Therefore the calling of completer callback can be promoted onto the same level as the --option list generation. This means that merging of two lists can be dropped to and completer callback can store its retval directly into @list (but as shown earlier one of the string lists to merge is always empty). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
parent
b1eab47c2d
commit
9b005b1967
44
tools/vsh.c
44
tools/vsh.c
@ -2750,34 +2750,28 @@ vshReadlineParse(const char *text, int state)
|
|||||||
|
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
list = vshReadlineCommandGenerator(text);
|
list = vshReadlineCommandGenerator(text);
|
||||||
} else {
|
} else if (!opt || opt->type == VSH_OT_BOOL) {
|
||||||
if (!opt || opt->type == VSH_OT_BOOL)
|
list = vshReadlineOptionsGenerator(text, cmd, partial);
|
||||||
list = vshReadlineOptionsGenerator(text, cmd, partial);
|
} else if (opt && opt->completer) {
|
||||||
|
list = opt->completer(autoCompleteOpaque,
|
||||||
|
partial,
|
||||||
|
opt->completer_flags);
|
||||||
|
}
|
||||||
|
|
||||||
if (opt && opt->completer) {
|
/* Escape completions, if needed (i.e. argument
|
||||||
g_auto(GStrv) completer_list = opt->completer(autoCompleteOpaque,
|
* we are completing wasn't started with a quote
|
||||||
partial,
|
* character). This also enables filtering done
|
||||||
opt->completer_flags);
|
* below to work properly. */
|
||||||
|
if (list &&
|
||||||
|
!rl_completion_quote_character) {
|
||||||
|
size_t i;
|
||||||
|
|
||||||
/* Escape completions, if needed (i.e. argument
|
for (i = 0; list[i]; i++) {
|
||||||
* we are completing wasn't started with a quote
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||||
* character). This also enables filtering done
|
|
||||||
* below to work properly. */
|
|
||||||
if (completer_list &&
|
|
||||||
!rl_completion_quote_character) {
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i = 0; completer_list[i]; i++) {
|
virBufferEscape(&buf, '\\', " ", "%s", list[i]);
|
||||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
VIR_FREE(list[i]);
|
||||||
|
list[i] = virBufferContentAndReset(&buf);
|
||||||
virBufferEscape(&buf, '\\', " ", "%s", completer_list[i]);
|
|
||||||
VIR_FREE(completer_list[i]);
|
|
||||||
completer_list[i] = virBufferContentAndReset(&buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virStringListMerge(&list, &completer_list) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user