From nobody Thu May 15 09:55:15 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510589215477131.9318585628546; Mon, 13 Nov 2017 08:06:55 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C43DFDCA14; Mon, 13 Nov 2017 16:06:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A3AA27F5FD; Mon, 13 Nov 2017 16:06:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6FC9E14B29; Mon, 13 Nov 2017 16:06:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vADG6mF7016744 for ; Mon, 13 Nov 2017 11:06:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0B7678120C; Mon, 13 Nov 2017 16:06:48 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-194.brq.redhat.com [10.40.204.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71AB88120E for ; Mon, 13 Nov 2017 16:06:47 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 13 Nov 2017 17:06:26 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 06/12] vsh: Call vshCmdOptDef.completer properly X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 13 Nov 2017 16:06:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The idea is that .completer for vshCmdOptDef would be called if the last token on the input is a cmd opt. For instance: virsh # start --domain However, with current code that's not happening. Signed-off-by: Michal Privoznik --- tools/vsh.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index bad2c0bcf..3ed6bb916 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2691,7 +2691,7 @@ vshReadlineParse(const char *text, int state) uint64_t opts_seen; size_t opt_index; static bool cmd_exists, opts_filled, opt_exists; - static bool non_bool_opt_exists, data_complete; + static bool non_bool_opt_exists, complete_data, complete_opts; =20 if (!state) { parser.pos =3D rl_line_buffer; @@ -2738,7 +2738,7 @@ vshReadlineParse(const char *text, int state) cmd_exists =3D false; opts_filled =3D false; non_bool_opt_exists =3D false; - data_complete =3D false; + complete_data =3D false; =20 const_opts_need_arg =3D 0; const_opts_required =3D 0; @@ -2804,7 +2804,7 @@ vshReadlineParse(const char *text, int state) } if (STREQ(tkdata, sanitized_text)) { /* auto-complete non-bool option arg */ - data_complete =3D true; + complete_data =3D true; break; } non_bool_opt_exists =3D false; @@ -2851,27 +2851,36 @@ vshReadlineParse(const char *text, int state) virSkipSpaces((const char**)&tkdata); } VIR_FREE(const_tkdata); + complete_opts =3D opts_filled && !non_bool_opt_exists; } =20 if (!cmd_exists) { res =3D vshReadlineCommandGenerator(sanitized_text, state); - } else if (opts_filled && !non_bool_opt_exists) { - res =3D vshReadlineOptionsGenerator(sanitized_text, state, cmd); - } else if (non_bool_opt_exists && data_complete && opt && opt->complet= er) { - if (!completed_list) - completed_list =3D opt->completer(autoCompleteOpaque, - opt->completer_flags); - if (completed_list) { - while ((completed_name =3D completed_list[completed_list_index= ])) { - completed_list_index++; - if (!STRPREFIX(completed_name, sanitized_text)) - continue; - res =3D vshStrdup(NULL, completed_name); - return res; + } else { + if (complete_opts) { + res =3D vshReadlineOptionsGenerator(sanitized_text, state, cmd= ); + complete_opts =3D !!res; + } + + if (!complete_opts && complete_data) { + if (!completed_list && opt && opt->completer) + completed_list =3D opt->completer(autoCompleteOpaque, + opt->completer_flags); + if (completed_list) { + while ((completed_name =3D completed_list[completed_list_i= ndex])) { + completed_list_index++; + if (!STRPREFIX(completed_name, sanitized_text)) + continue; + res =3D vshStrdup(NULL, completed_name); + break; + } + + if (!res) { + virStringListFree(completed_list); + completed_list =3D NULL; + completed_list_index =3D 0; + } } - res =3D NULL; - virStringListFree(completed_list); - completed_list_index =3D 0; } } =20 @@ -2895,7 +2904,6 @@ vshReadlineParse(const char *text, int state) VIR_FREE(sanitized_text); VIR_FREE(ctext); return NULL; - } =20 static char ** --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list