From nobody Wed Dec 17 04:03:12 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 1509455449168572.6831625678212; Tue, 31 Oct 2017 06:10:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4898C806A8; Tue, 31 Oct 2017 13:10:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 17A895C3FD; Tue, 31 Oct 2017 13:10:47 +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 CE5751804486; Tue, 31 Oct 2017 13:10:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9VDAY6s019485 for ; Tue, 31 Oct 2017 09:10:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 29D785D6A9; Tue, 31 Oct 2017 13:10:34 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E3305D6A3 for ; Tue, 31 Oct 2017 13:10:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4898C806A8 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 31 Oct 2017 14:10:26 +0100 Message-Id: <59189d774f501ad0f9da11ed14c166d6411f95c8.1509454497.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH RFC 1/2] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 31 Oct 2017 13:10:47 +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 | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 10a65c39f..0ae2892a3 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2672,7 +2672,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; @@ -2719,7 +2719,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; @@ -2785,7 +2785,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; @@ -2832,27 +2832,34 @@ 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); + return res; + } + res =3D NULL; + virStringListFree(completed_list); + completed_list =3D NULL; + completed_list_index =3D 0; } - res =3D NULL; - virStringListFree(completed_list); - completed_list_index =3D 0; } } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list