[PATCH 04/12] vsh: Accept NULL @list in vshCompleterFilter()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The aim of vshCompleterFilter() is to take a string list and a
prefix and remove all strings from the list that don't have the
desired prefix. The function is used to filter out those strings
returned by a completer callback that don't correspond with
user's (partial) input. For instance, domain name completer
virshDomainNameCompleter() returns all domain names and then
vshCompleterFilter() refines the list so that only domains with
correct prefix of their name are offered to user. This was a
design choice - it allows us to have shorter completers as they
do not have to copy the list filtering over and over.

Having said all of that, it may happen that a completer does not
return anything (e.g. there is no domain in requested state,
virsh is not connected and thus completer exited early, etc.). In
that case, the string list is NULL and vshCompleterFilter() can
simply return early.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tools/vsh.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 3cb657f582..13bf525acc 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2703,7 +2703,7 @@ vshCompleterFilter(char ***list,
     size_t i;
 
     if (!list || !*list)
-        return -1;
+        return 0;
 
     list_len = virStringListLength((const char **) *list);
     newList = g_new0(char *, list_len + 1);
@@ -2802,9 +2802,8 @@ vshReadlineParse(const char *text, int state)
                 /* For string list returned by completer we have to do
                  * filtering based on @text because completer returns all
                  * possible strings. */
-                if (completer_list &&
-                    (vshCompleterFilter(&completer_list, text) < 0 ||
-                     virStringListMerge(&list, &completer_list) < 0)) {
+                if (vshCompleterFilter(&completer_list, text) < 0 ||
+                    virStringListMerge(&list, &completer_list) < 0) {
                     goto cleanup;
                 }
             }
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux