[PATCH 8/9] vsh: Allow double quotes imbalance for auto completion in vshCommandStringGetArg()

Ján Tomko jtomko at redhat.com
Tue Jan 26 15:33:10 UTC 2021


On a Tuesday in 2021, Michal Privoznik wrote:
>If user is trying to auto complete a value that contains a space,
>they have two options: use backslash to escape space or use
>qotes, like this:
>
>  virsh # start --domain "domain with space<TAB>
>
>However, in this case our tokenizer sees imbalance in (double)
>quotes: there is a starting one that's missing it's companion.

*its

>Well, that's obvious - user is still in process of writing the
>command. What we need to do in this case is to ignore the
>imbalance and return success (from the tokenizer) - readline will
>handle closing the quote properly.
>
>Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>---
> tools/vsh.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
>diff --git a/tools/vsh.c b/tools/vsh.c
>index e5c6cebebb..53a84b9d95 100644
>--- a/tools/vsh.c
>+++ b/tools/vsh.c
>@@ -1418,7 +1418,7 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
>                     if (optstr)
>                         tkdata = optstr;
>                     else
>-                        tk = parser->getNextArg(ctl, parser, &tkdata, true);
>+                        tk = parser->getNextArg(ctl, parser, &tkdata, partial == NULL);
>                     if (tk == VSH_TK_ERROR)
>                         goto syntaxError;
>                     if (tk != VSH_TK_ARG) {
>@@ -1673,10 +1673,16 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res,
>
>         *q++ = *p++;
>     }
>+
>     if (double_quote) {
>-        if (report)
>+        /* We have seen a double quote, but not it's companion

*its

Jano

>+         * ending. It's valid though, in case when we're called
>+         * from completer (report = false), but it's not valid
>+         * when parsing real command (report= true).  */
>+        if (report) {
>             vshError(ctl, "%s", _("missing \""));
>-        return VSH_TK_ERROR;
>+            return VSH_TK_ERROR;
>+        }
>     }
>
>     *q = '\0';
>-- 
>2.26.2
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210126/037353f3/attachment-0001.sig>


More information about the libvir-list mailing list