[PATCH 07/12] vsh: Rewrite opt->type check in vshReadlineParse()

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

 



The vshReadlineParse() function is called whenever user hits
<TAB><TAB>. If there is no command (or a partially written one),
then a list of possible commands is printed to the user. But, if
there is a command then its --options are generated. But
obviously, we can not generate --options if there already is an
--option that's expecting a value. For instance, consider:

  virsh # start --domain <TAB><TAB>

In this case we want to call completer for --domain option, but
that's a different story.

Anyway, the way that we currently check whether --options list
should be generated is checking the type of the last --option. If
it isn't DATA, STRING, INT, or ARGV (all these expect a value),
then we can generate --option list. Well, writing the condition
this way is needlessly verbose and also prone to errors (see
d9a320bf97 for example).

We know that boolean type does not require a value. This leaves
us with the only type that was not mentioned yet - VSH_OT_ALIAS.
This is a special type for backwards compatibility and it refers
to another --option which can be just any type.

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

diff --git a/tools/vsh.c b/tools/vsh.c
index 70b7e3e285..f83b2a95a9 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2765,10 +2765,7 @@ vshReadlineParse(const char *text, int state)
         if (!cmd) {
             list = vshReadlineCommandGenerator(text);
         } else {
-            if (!opt || (opt->type != VSH_OT_DATA &&
-                         opt->type != VSH_OT_STRING &&
-                         opt->type != VSH_OT_INT &&
-                         opt->type != VSH_OT_ARGV))
+            if (!opt || opt->type == VSH_OT_BOOL)
                 list = vshReadlineOptionsGenerator(text, cmd, partial);
 
             if (opt && opt->completer) {
-- 
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