From nobody Sun Apr 28 14:26:58 2024 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 1510057392053140.92761683998833; Tue, 7 Nov 2017 04:23:12 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 673B33DE31; Tue, 7 Nov 2017 12:23:08 +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 3FE7D6A023; Tue, 7 Nov 2017 12:23:08 +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 951474BB79; Tue, 7 Nov 2017 12:23:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CN5nY031600 for ; Tue, 7 Nov 2017 07:23:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id D99FA5C545; Tue, 7 Nov 2017 12:23:05 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 609EC1821D for ; Tue, 7 Nov 2017 12:23:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 673B33DE31 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.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, 7 Nov 2017 13:22:49 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/11] vshCommandStringParse: Allow retrieving partial result 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 07 Nov 2017 12:23:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In the future, this function is going to be called from vshReadlineParse() to provide parsed input for completer callbacks. The idea is to allow the callbacks to provide more specific data. For instance, for the following input: virsh # domifaddr --domain fedora --interface the --interface completer callback is going to be called. Now, it is more user friendly if the completer offers only those interfaces found in 'fedora' domain. But in order to do that it needs to be able to retrieve partially parsed result. Signed-off-by: Michal Privoznik --- tools/virsh.c | 4 ++-- tools/virt-admin.c | 4 ++-- tools/vsh.c | 67 ++++++++++++++++++++++++++++++++++----------------= ---- tools/vsh.h | 2 +- 4 files changed, 47 insertions(+), 30 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index d1789f03a..d0c135016 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -815,7 +815,7 @@ virshParseArgv(vshControl *ctl, int argc, char **argv) ctl->imode =3D false; if (argc - optind =3D=3D 1) { vshDebug(ctl, VSH_ERR_INFO, "commands: \"%s\"\n", argv[optind]= ); - return vshCommandStringParse(ctl, argv[optind]); + return vshCommandStringParse(ctl, argv[optind], NULL); } else { return vshCommandArgvParse(ctl, argc - optind, argv + optind); } @@ -952,7 +952,7 @@ main(int argc, char **argv) #if WITH_READLINE add_history(ctl->cmdstr); #endif - if (vshCommandStringParse(ctl, ctl->cmdstr)) + if (vshCommandStringParse(ctl, ctl->cmdstr, NULL)) vshCommandRun(ctl, ctl->cmd); } VIR_FREE(ctl->cmdstr); diff --git a/tools/virt-admin.c b/tools/virt-admin.c index e529a2891..b8b33af19 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1335,7 +1335,7 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **arg= v) ctl->imode =3D false; if (argc - optind =3D=3D 1) { vshDebug(ctl, VSH_ERR_INFO, "commands: \"%s\"\n", argv[optind]= ); - return vshCommandStringParse(ctl, argv[optind]); + return vshCommandStringParse(ctl, argv[optind], NULL); } else { return vshCommandArgvParse(ctl, argc - optind, argv + optind); } @@ -1555,7 +1555,7 @@ main(int argc, char **argv) #if WITH_READLINE add_history(ctl->cmdstr); #endif - if (vshCommandStringParse(ctl, ctl->cmdstr)) + if (vshCommandStringParse(ctl, ctl->cmdstr, NULL)) vshCommandRun(ctl, ctl->cmd); } VIR_FREE(ctl->cmdstr); diff --git a/tools/vsh.c b/tools/vsh.c index 10a65c39f..eca312b4b 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1387,26 +1387,27 @@ struct _vshCommandParser { }; =20 static bool -vshCommandParse(vshControl *ctl, vshCommandParser *parser) +vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partia= l) { char *tkdata =3D NULL; vshCmd *clast =3D NULL; vshCmdOpt *first =3D NULL; + const vshCmdDef *cmd =3D NULL; =20 - if (ctl->cmd) { + if (!partial && ctl->cmd) { vshCommandFree(ctl->cmd); ctl->cmd =3D NULL; } =20 while (1) { vshCmdOpt *last =3D NULL; - const vshCmdDef *cmd =3D NULL; vshCommandToken tk; bool data_only =3D false; uint64_t opts_need_arg =3D 0; uint64_t opts_required =3D 0; uint64_t opts_seen =3D 0; =20 + cmd =3D NULL; first =3D NULL; =20 while (1) { @@ -1425,7 +1426,8 @@ vshCommandParse(vshControl *ctl, vshCommandParser *pa= rser) if (cmd =3D=3D NULL) { /* first token must be command name */ if (!(cmd =3D vshCmddefSearch(tkdata))) { - vshError(ctl, _("unknown command: '%s'"), tkdata); + if (!partial) + vshError(ctl, _("unknown command: '%s'"), tkdata); goto syntaxError; /* ... or ignore this command only= ? */ } =20 @@ -1437,9 +1439,10 @@ vshCommandParse(vshControl *ctl, vshCommandParser *p= arser) } if (vshCmddefOptParse(cmd, &opts_need_arg, &opts_required) < 0) { - vshError(ctl, - _("internal error: bad options in command: '%= s'"), - tkdata); + if (!partial) + vshError(ctl, + _("internal error: bad options in command= : '%s'"), + tkdata); goto syntaxError; } VIR_FREE(tkdata); @@ -1474,11 +1477,12 @@ vshCommandParse(vshControl *ctl, vshCommandParser *= parser) if (tk =3D=3D VSH_TK_ERROR) goto syntaxError; if (tk !=3D VSH_TK_ARG) { - vshError(ctl, - _("expected syntax: --%s <%s>"), - opt->name, - opt->type =3D=3D - VSH_OT_INT ? _("number") : _("string")); + if (!partial) + vshError(ctl, + _("expected syntax: --%s <%s>"), + opt->name, + opt->type =3D=3D + VSH_OT_INT ? _("number") : _("string"= )); goto syntaxError; } if (opt->type !=3D VSH_OT_ARGV) @@ -1486,8 +1490,9 @@ vshCommandParse(vshControl *ctl, vshCommandParser *pa= rser) } else { tkdata =3D NULL; if (optstr) { - vshError(ctl, _("invalid '=3D' after option --%s"), - opt->name); + if (!partial) + vshError(ctl, _("invalid '=3D' after option --= %s"), + opt->name); VIR_FREE(optstr); goto syntaxError; } @@ -1502,7 +1507,8 @@ vshCommandParse(vshControl *ctl, vshCommandParser *pa= rser) if (!(opt =3D vshCmddefGetData(cmd, &opts_need_arg, &opts_seen)) && STRNEQ(cmd->name, "help")) { - vshError(ctl, _("unexpected data '%s'"), tkdata); + if (!partial) + vshError(ctl, _("unexpected data '%s'"), tkdata); goto syntaxError; } } @@ -1558,12 +1564,15 @@ vshCommandParse(vshControl *ctl, vshCommandParser *= parser) c->def =3D cmd; c->next =3D NULL; =20 - if (vshCommandCheckOpts(ctl, c, opts_required, opts_seen) < 0)= { + if (!partial && + vshCommandCheckOpts(ctl, c, opts_required, opts_seen) < 0)= { VIR_FREE(c); goto syntaxError; } =20 - if (!ctl->cmd) + if (partial) + *partial =3D c; + else if (!ctl->cmd) ctl->cmd =3D c; if (clast) clast->next =3D c; @@ -1577,12 +1586,20 @@ vshCommandParse(vshControl *ctl, vshCommandParser *= parser) return true; =20 syntaxError: - if (ctl->cmd) { - vshCommandFree(ctl->cmd); - ctl->cmd =3D NULL; + if (partial) { + if (!*partial) + *partial =3D vshMalloc(ctl, sizeof(vshCmd)); + + (*partial)->opts =3D first; + (*partial)->def =3D cmd; + } else { + if (ctl->cmd) { + vshCommandFree(ctl->cmd); + ctl->cmd =3D NULL; + } + if (first) + vshCommandOptFree(first); } - if (first) - vshCommandOptFree(first); VIR_FREE(tkdata); return false; } @@ -1617,7 +1634,7 @@ vshCommandArgvParse(vshControl *ctl, int nargs, char = **argv) parser.arg_pos =3D argv; parser.arg_end =3D argv + nargs; parser.getNextArg =3D vshCommandArgvGetArg; - return vshCommandParse(ctl, &parser); + return vshCommandParse(ctl, &parser, NULL); } =20 /* ---------------------- @@ -1689,7 +1706,7 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandPar= ser *parser, char **res, } =20 bool -vshCommandStringParse(vshControl *ctl, char *cmdstr) +vshCommandStringParse(vshControl *ctl, char *cmdstr, vshCmd **partial) { vshCommandParser parser; =20 @@ -1698,7 +1715,7 @@ vshCommandStringParse(vshControl *ctl, char *cmdstr) =20 parser.pos =3D cmdstr; parser.getNextArg =3D vshCommandStringGetArg; - return vshCommandParse(ctl, &parser); + return vshCommandParse(ctl, &parser, partial); } =20 /** diff --git a/tools/vsh.h b/tools/vsh.h index ab755bccf..8f7df9ff8 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -299,7 +299,7 @@ int vshBlockJobOptionBandwidth(vshControl *ctl, unsigned long *bandwidth); bool vshCommandOptBool(const vshCmd *cmd, const char *name); bool vshCommandRun(vshControl *ctl, const vshCmd *cmd); -bool vshCommandStringParse(vshControl *ctl, char *cmdstr); +bool vshCommandStringParse(vshControl *ctl, char *cmdstr, vshCmd **partial= ); =20 const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd, const vshCmdOpt *opt); --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 14:26:58 2024 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 1510057393952550.4965806431726; Tue, 7 Nov 2017 04:23:13 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F7D52C977E; Tue, 7 Nov 2017 12:23:12 +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 6639B6A04B; Tue, 7 Nov 2017 12:23:12 +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 27D1F3FCF9; Tue, 7 Nov 2017 12:23:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CN6pY031610 for ; Tue, 7 Nov 2017 07:23:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id AD06117161; Tue, 7 Nov 2017 12:23:06 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32AB45C545 for ; Tue, 7 Nov 2017 12:23:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8F7D52C977E Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.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, 7 Nov 2017 13:22:50 +0100 Message-Id: <9b9d2014b3ab57056532e46d8d1f0357956b8498.1510055948.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/11] vshCommandOpt: Relax check for valid options 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 07 Nov 2017 12:23:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When trying to get an opt for command typed on the command line we first check if command has such option. Because if it doesn't it is a programming error. For instance: vshCommandOptBool(cmd, "config") called from say cmdStart() doesn't make sense since there's no --config for the start command. However, we will want to have generic completers which are going to check if various options are set. And so it can happen that we will check for non-existent option for given command. Therefore, we need to relax the check otherwise we will hit the assert() and don't get anywhere. Signed-off-by: Michal Privoznik --- tools/vsh.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index eca312b4b..24ea45aa4 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -815,8 +815,7 @@ vshCommandFree(vshCmd *cmd) * Look up an option passed to CMD by NAME. Returns 1 with *OPT set * to the option if found, 0 with *OPT set to NULL if the name is * valid and the option is not required, -1 with *OPT set to NULL if - * the option is required but not present, and assert if NAME is not - * valid (which indicates a programming error). No error messages are + * the option is required but not present. No error messages are * issued if a value is returned. */ static int @@ -829,8 +828,7 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vshC= mdOpt **opt, =20 /* See if option is valid and/or required. */ *opt =3D NULL; - while (valid) { - assert(valid->name); + while (valid && valid->name) { if (STREQ(name, valid->name)) break; valid++; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 14:26:58 2024 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 1510057392143220.0609739724531; Tue, 7 Nov 2017 04:23:12 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89EBD883DC; Tue, 7 Nov 2017 12:23:10 +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 6500F5D6A9; Tue, 7 Nov 2017 12:23:10 +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 0A8FE4A469; Tue, 7 Nov 2017 12:23:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CN7tE031625 for ; Tue, 7 Nov 2017 07:23:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id D89435C545; Tue, 7 Nov 2017 12:23:07 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F90F5C8A1 for ; Tue, 7 Nov 2017 12:23:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 89EBD883DC 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, 7 Nov 2017 13:22:51 +0100 Message-Id: <762ee1b32f7be5a3d44919e4b6aa41ad16e80471.1510055948.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/11] vsh: Add @silent to vshConnectionHook 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 07 Nov 2017 12:23:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In near future we will want to not report error when connecting fails. In order to achieve that we have to pass a boolean that suppresses error messages. Signed-off-by: Michal Privoznik --- tools/virsh-domain.c | 2 +- tools/virsh.c | 67 ++++++++++++++++++++++++++++++++----------------= ---- tools/virsh.h | 5 +++- tools/virt-admin.c | 49 +++++++++++++++++++++----------------- tools/vsh.c | 2 +- tools/vsh.h | 3 ++- 6 files changed, 76 insertions(+), 52 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 42d552637..cf612f73e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -10931,7 +10931,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "desturi", &desturi) < 0) goto cleanup; =20 - dconn =3D virshConnect(ctl, desturi, false); + dconn =3D virshConnect(ctl, desturi, false, false); if (!dconn) goto cleanup; =20 diff --git a/tools/virsh.c b/tools/virsh.c index d0c135016..7d6dc2620 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -137,7 +137,7 @@ virshCatchDisconnect(virConnectPtr conn, /* Main Function which should be used for connecting. * This function properly handles keepalive settings. */ virConnectPtr -virshConnect(vshControl *ctl, const char *uri, bool readonly) +virshConnect(vshControl *ctl, const char *uri, bool readonly, bool silent) { virConnectPtr c =3D NULL; int interval =3D 5; /* Default */ @@ -191,15 +191,19 @@ virshConnect(vshControl *ctl, const char *uri, bool r= eadonly) if (interval > 0 && virConnectSetKeepAlive(c, interval, count) !=3D 0) { if (keepalive_forced) { - vshError(ctl, "%s", - _("Cannot setup keepalive on connection " - "as requested, disconnecting")); + if (!silent) { + vshError(ctl, "%s", + _("Cannot setup keepalive on connection " + "as requested, disconnecting")); + } virConnectClose(c); c =3D NULL; goto cleanup; } - vshDebug(ctl, VSH_ERR_INFO, "%s", - _("Failed to setup keepalive on connection\n")); + if (!silent) { + vshDebug(ctl, VSH_ERR_INFO, "%s", + _("Failed to setup keepalive on connection\n")); + } } =20 cleanup: @@ -214,7 +218,11 @@ virshConnect(vshControl *ctl, const char *uri, bool re= adonly) * */ static int -virshReconnect(vshControl *ctl, const char *name, bool readonly, bool forc= e) +virshReconnect(vshControl *ctl, + const char *name, + bool readonly, + bool force, + bool silent) { bool connected =3D false; virshControlPtr priv =3D ctl->privData; @@ -232,20 +240,25 @@ virshReconnect(vshControl *ctl, const char *name, boo= l readonly, bool force) =20 virConnectUnregisterCloseCallback(priv->conn, virshCatchDisconnect= ); ret =3D virConnectClose(priv->conn); - if (ret < 0) - vshError(ctl, "%s", _("Failed to disconnect from the hyperviso= r")); - else if (ret > 0) - vshError(ctl, "%s", _("One or more references were leaked afte= r " - "disconnect from the hypervisor")); + if (!silent) { + if (ret < 0) + vshError(ctl, "%s", _("Failed to disconnect from the hyper= visor")); + else if (ret > 0) + vshError(ctl, "%s", _("One or more references were leaked = after " + "disconnect from the hypervisor")); + } } =20 - priv->conn =3D virshConnect(ctl, name ? name : ctl->connname, readonly= ); + priv->conn =3D virshConnect(ctl, name ? name : ctl->connname, + readonly, silent); =20 if (!priv->conn) { - if (disconnected) - vshError(ctl, "%s", _("Failed to reconnect to the hypervisor")= ); - else - vshError(ctl, "%s", _("failed to connect to the hypervisor")); + if (!silent) { + if (disconnected) + vshError(ctl, "%s", _("Failed to reconnect to the hypervis= or")); + else + vshError(ctl, "%s", _("Failed to connect to the hypervisor= ")); + } return -1; } else { if (name) { @@ -255,8 +268,9 @@ virshReconnect(vshControl *ctl, const char *name, bool = readonly, bool force) } if (virConnectRegisterCloseCallback(priv->conn, virshCatchDisconne= ct, ctl, NULL) < 0) - vshError(ctl, "%s", _("Unable to register disconnect callback"= )); - if (connected && !force) + if (!silent) + vshError(ctl, "%s", _("Unable to register disconnect callb= ack")); + if (connected && !force && !silent) vshError(ctl, "%s", _("Reconnected to the hypervisor")); } disconnected =3D 0; @@ -304,7 +318,7 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0) return false; =20 - if (virshReconnect(ctl, name, ro, true) < 0) + if (virshReconnect(ctl, name, ro, true, false) < 0) return false; =20 return true; @@ -316,11 +330,12 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd) */ =20 static bool -virshConnectionUsability(vshControl *ctl, virConnectPtr conn) +virshConnectionUsability(vshControl *ctl, virConnectPtr conn, bool silent) { if (!conn || virConnectIsAlive(conn) =3D=3D 0) { - vshError(ctl, "%s", _("no valid connection")); + if (!silent) + vshError(ctl, "%s", _("no valid connection")); return false; } =20 @@ -333,15 +348,15 @@ virshConnectionUsability(vshControl *ctl, virConnectP= tr conn) } =20 static void * -virshConnectionHandler(vshControl *ctl) +virshConnectionHandler(vshControl *ctl, bool silent) { virshControlPtr priv =3D ctl->privData; =20 if ((!priv->conn || disconnected) && - virshReconnect(ctl, NULL, false, false) < 0) + virshReconnect(ctl, NULL, false, false, silent) < 0) return NULL; =20 - if (virshConnectionUsability(ctl, priv->conn)) + if (virshConnectionUsability(ctl, priv->conn, silent)) return priv->conn; =20 return NULL; @@ -391,7 +406,7 @@ virshInit(vshControl *ctl) * non-default connection, or might be 'help' which needs no * connection). */ - if (virshReconnect(ctl, NULL, false, false) < 0) { + if (virshReconnect(ctl, NULL, false, false, false) < 0) { vshReportError(ctl); return false; } diff --git a/tools/virsh.h b/tools/virsh.h index b353b645a..e03b597ef 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -144,6 +144,9 @@ typedef enum { VIRSH_BYMAC =3D (1 << 4), } virshLookupByFlags; =20 -virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly= ); +virConnectPtr virshConnect(vshControl *ctl, + const char *uri, + bool readonly, + bool silent); =20 #endif /* VIRSH_H */ diff --git a/tools/virt-admin.c b/tools/virt-admin.c index b8b33af19..5d7ef7988 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -154,24 +154,26 @@ vshAdmCatchDisconnect(virAdmConnectPtr conn ATTRIBUTE= _UNUSED, } =20 static int -vshAdmConnect(vshControl *ctl, unsigned int flags) +vshAdmConnect(vshControl *ctl, unsigned int flags, bool silent) { vshAdmControlPtr priv =3D ctl->privData; =20 priv->conn =3D virAdmConnectOpen(ctl->connname, flags); =20 if (!priv->conn) { - if (priv->wantReconnect) - vshError(ctl, "%s", _("Failed to reconnect to the admin server= ")); - else - vshError(ctl, "%s", _("Failed to connect to the admin server")= ); + if (!silent) { + if (priv->wantReconnect) + vshError(ctl, "%s", _("Failed to reconnect to the admin se= rver")); + else + vshError(ctl, "%s", _("Failed to connect to the admin serv= er")); + } return -1; } else { if (virAdmConnectRegisterCloseCallback(priv->conn, vshAdmCatchDisc= onnect, - NULL, NULL) < 0) + NULL, NULL) < 0 && !silent) vshError(ctl, "%s", _("Unable to register disconnect callback"= )); =20 - if (priv->wantReconnect) + if (priv->wantReconnect && !silent) vshPrint(ctl, "%s\n", _("Reconnected to the admin server")); } =20 @@ -179,7 +181,7 @@ vshAdmConnect(vshControl *ctl, unsigned int flags) } =20 static int -vshAdmDisconnect(vshControl *ctl) +vshAdmDisconnect(vshControl *ctl, bool silent) { int ret =3D 0; vshAdmControlPtr priv =3D ctl->privData; @@ -189,11 +191,13 @@ vshAdmDisconnect(vshControl *ctl) =20 virAdmConnectUnregisterCloseCallback(priv->conn, vshAdmCatchDisconnect= ); ret =3D virAdmConnectClose(priv->conn); - if (ret < 0) - vshError(ctl, "%s", _("Failed to disconnect from the admin server"= )); - else if (ret > 0) - vshError(ctl, "%s", _("One or more references were leaked after " - "disconnect from the hypervisor")); + if (!silent) { + if (ret < 0) + vshError(ctl, "%s", _("Failed to disconnect from the admin ser= ver")); + else if (ret > 0) + vshError(ctl, "%s", _("One or more references were leaked afte= r " + "disconnect from the hypervisor")); + } priv->conn =3D NULL; return ret; } @@ -205,14 +209,14 @@ vshAdmDisconnect(vshControl *ctl) * */ static void -vshAdmReconnect(vshControl *ctl) +vshAdmReconnect(vshControl *ctl, bool silent) { vshAdmControlPtr priv =3D ctl->privData; if (priv->conn) priv->wantReconnect =3D true; =20 - vshAdmDisconnect(ctl); - vshAdmConnect(ctl, 0); + vshAdmDisconnect(ctl, silent); + vshAdmConnect(ctl, 0, silent); =20 priv->wantReconnect =3D false; } @@ -350,7 +354,7 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd) ctl->connname =3D vshStrdup(ctl, name); } =20 - vshAdmReconnect(ctl); + vshAdmReconnect(ctl, false); if (!connected && priv->conn) vshPrint(ctl, "%s\n", _("Connected to the admin server")); =20 @@ -1080,15 +1084,16 @@ cmdDaemonLogOutputs(vshControl *ctl, const vshCmd *= cmd) } =20 static void * -vshAdmConnectionHandler(vshControl *ctl) +vshAdmConnectionHandler(vshControl *ctl, bool silent) { vshAdmControlPtr priv =3D ctl->privData; =20 if (!virAdmConnectIsAlive(priv->conn)) - vshAdmReconnect(ctl); + vshAdmReconnect(ctl, silent); =20 if (!virAdmConnectIsAlive(priv->conn)) { - vshError(ctl, "%s", _("no valid connection")); + if (!silent) + vshError(ctl, "%s", _("no valid connection")); return NULL; } =20 @@ -1122,7 +1127,7 @@ vshAdmInit(vshControl *ctl) ctl->eventLoopStarted =3D true; =20 if (ctl->connname) { - vshAdmReconnect(ctl); + vshAdmReconnect(ctl, false); /* Connecting to a named connection must succeed, but we delay * connecting to the default connection until we need it * (since the first command might be 'connect' which allows a @@ -1156,7 +1161,7 @@ vshAdmDeinit(vshControl *ctl) VIR_FREE(ctl->connname); =20 if (priv->conn) - vshAdmDisconnect(ctl); + vshAdmDisconnect(ctl, false); =20 virResetLastError(); =20 diff --git a/tools/vsh.c b/tools/vsh.c index 24ea45aa4..83c96e1a8 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1321,7 +1321,7 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) GETTIMEOFDAY(&before); =20 if ((cmd->def->flags & VSH_CMD_FLAG_NOCONNECT) || - (hooks && hooks->connHandler && hooks->connHandler(ctl))) { + (hooks && hooks->connHandler && hooks->connHandler(ctl, false)= )) { ret =3D cmd->def->handler(ctl, cmd); } else { /* connection is not usable, return error */ diff --git a/tools/vsh.h b/tools/vsh.h index 8f7df9ff8..c411c2ca4 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -232,7 +232,8 @@ struct _vshControl { }; =20 typedef void * -(*vshConnectionHook)(vshControl *ctl); +(*vshConnectionHook)(vshControl *ctl, + bool silent); =20 struct _vshClientHooks { vshConnectionHook connHandler; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 14:26:58 2024 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 1510057395080321.9575129402027; Tue, 7 Nov 2017 04:23:15 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4887F267E0; Tue, 7 Nov 2017 12:23:13 +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 28A1A5EDE4; Tue, 7 Nov 2017 12:23:13 +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 E1A3A1800BDC; Tue, 7 Nov 2017 12:23:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CN8XT031630 for ; Tue, 7 Nov 2017 07:23:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id AAE1F5C545; Tue, 7 Nov 2017 12:23:08 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 320B05C8A1 for ; Tue, 7 Nov 2017 12:23:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4887F267E0 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.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, 7 Nov 2017 13:22:52 +0100 Message-Id: <4a2c98374087a428fe03f8c95a59dc827af82c47.1510055948.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/11] vsh: Fix vshCompleter signature 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 07 Nov 2017 12:23:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The first argument passed to this function is vshControl *. There's no need to use void pointer. Signed-off-by: Michal Privoznik --- tools/vsh.c | 2 +- tools/vsh.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 83c96e1a8..cbab6f7d0 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -66,7 +66,7 @@ =20 #ifdef WITH_READLINE /* For autocompletion */ -void *autoCompleteOpaque; +vshControl *autoCompleteOpaque; #endif =20 /* NOTE: It would be much nicer to have these two as part of vshControl diff --git a/tools/vsh.h b/tools/vsh.h index c411c2ca4..1ebd5c11a 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -123,7 +123,8 @@ typedef struct _vshCmdOpt vshCmdOpt; typedef struct _vshCmdOptDef vshCmdOptDef; typedef struct _vshControl vshControl; =20 -typedef char **(*vshCompleter)(void *opaque, unsigned int flags); +typedef char **(*vshCompleter)(vshControl *ctl, + unsigned int flags); =20 /* * vshCmdInfo -- name/value pair for information about command --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 14:26:58 2024 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 1510057397074671.6777797521214; Tue, 7 Nov 2017 04:23:17 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B6B75FD63; Tue, 7 Nov 2017 12:23:15 +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 267B05EDE0; Tue, 7 Nov 2017 12:23:15 +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 E430A1800BDD; Tue, 7 Nov 2017 12:23:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CN9n9031635 for ; Tue, 7 Nov 2017 07:23:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7E00C17161; Tue, 7 Nov 2017 12:23:09 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04D405C8A1 for ; Tue, 7 Nov 2017 12:23:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4B6B75FD63 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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, 7 Nov 2017 13:22:53 +0100 Message-Id: <3135425e2e2b5f360c748ee64b736cb8a63ffb93.1510055948.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/11] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Nov 2017 12:23:16 +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 cbab6f7d0..dd2f06ada 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2687,7 +2687,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; @@ -2734,7 +2734,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; @@ -2800,7 +2800,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; @@ -2847,27 +2847,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 From nobody Sun Apr 28 14:26:58 2024 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 1510057410034413.0003042465694; Tue, 7 Nov 2017 04:23:30 -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 7104A80C1E; Tue, 7 Nov 2017 12:23:28 +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 47B6460C97; Tue, 7 Nov 2017 12:23:28 +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 106CB1802123; Tue, 7 Nov 2017 12:23:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CNAJp031648 for ; Tue, 7 Nov 2017 07:23:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4FCFD5C545; Tue, 7 Nov 2017 12:23:10 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB30E5C8A1 for ; Tue, 7 Nov 2017 12:23:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7104A80C1E 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, 7 Nov 2017 13:22:54 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/11] vshCompleter: Pass partially parsed command 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.26]); Tue, 07 Nov 2017 12:23:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The callback we're calling might need to make decisions on already passed arguments. For instance, a completer that is supposed to bring up list of domain's interfaces might want to see what domain user wants to work with. Signed-off-by: Michal Privoznik --- tools/vsh.c | 7 ++++++- tools/vsh.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/vsh.c b/tools/vsh.c index dd2f06ada..121669574 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2859,9 +2859,14 @@ vshReadlineParse(const char *text, int state) } =20 if (!complete_opts && complete_data) { - if (!completed_list && opt && opt->completer) + if (!completed_list && opt && opt->completer) { + vshCmd *partial =3D NULL; + vshCommandStringParse(autoCompleteOpaque, rl_line_buffer, = &partial); completed_list =3D opt->completer(autoCompleteOpaque, + partial, opt->completer_flags); + vshCommandFree(partial); + } if (completed_list) { while ((completed_name =3D completed_list[completed_list_i= ndex])) { completed_list_index++; diff --git a/tools/vsh.h b/tools/vsh.h index 1ebd5c11a..c5a62e593 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -124,6 +124,7 @@ typedef struct _vshCmdOptDef vshCmdOptDef; typedef struct _vshControl vshControl; =20 typedef char **(*vshCompleter)(vshControl *ctl, + const vshCmd *cmd, unsigned int flags); =20 /* --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 14:26:58 2024 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 1510057400484884.5263834160899; Tue, 7 Nov 2017 04:23:20 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83263BAED; Tue, 7 Nov 2017 12:23:18 +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 39CE25D965; Tue, 7 Nov 2017 12:23:18 +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 8B9E3180474D; Tue, 7 Nov 2017 12:23:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CNBCm031655 for ; Tue, 7 Nov 2017 07:23:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2153C17161; Tue, 7 Nov 2017 12:23:11 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CC245C545 for ; Tue, 7 Nov 2017 12:23:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83263BAED Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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, 7 Nov 2017 13:22:55 +0100 Message-Id: <3b5adb82eeaaf2d87c7f59fe5cef4184902a7e24.1510055948.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/11] vsh: Introduce complete command 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Nov 2017 12:23:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This command is going to be called from bash completion script in the following form: virsh complete "start --domain" Its only purpose is to return list of possible strings for completion. Note that this is a 'hidden', unlisted command and therefore there's no documentation to it. Signed-off-by: Michal Privoznik --- tools/virsh.c | 1 + tools/virt-admin.c | 1 + tools/vsh.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ tools/vsh.h | 14 +++++++++++ 4 files changed, 84 insertions(+) diff --git a/tools/virsh.c b/tools/virsh.c index 7d6dc2620..f830331f6 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -846,6 +846,7 @@ static const vshCmdDef virshCmds[] =3D { VSH_CMD_PWD, VSH_CMD_QUIT, VSH_CMD_SELF_TEST, + VSH_CMD_COMPLETE, {.name =3D "connect", .handler =3D cmdConnect, .opts =3D opts_connect, diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 5d7ef7988..c24ed95c0 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1356,6 +1356,7 @@ static const vshCmdDef vshAdmCmds[] =3D { VSH_CMD_PWD, VSH_CMD_QUIT, VSH_CMD_SELF_TEST, + VSH_CMD_COMPLETE, {.name =3D "uri", .handler =3D cmdURI, .opts =3D NULL, diff --git a/tools/vsh.c b/tools/vsh.c index 121669574..136acb0ab 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3419,3 +3419,71 @@ cmdSelfTest(vshControl *ctl ATTRIBUTE_UNUSED, =20 return true; } + +/* ---------------------- + * Autocompletion command + * ---------------------- */ + +const vshCmdOptDef opts_complete[] =3D { + {.name =3D "string", + .type =3D VSH_OT_ARGV, + .flags =3D VSH_OFLAG_EMPTY_OK, + .help =3D N_("partial string to autocomplete") + }, + {.name =3D NULL} +}; + +const vshCmdInfo info_complete[] =3D { + {.name =3D "help", + .data =3D N_("internal command for autocompletion") + }, + {.name =3D "desc", + .data =3D N_("internal use only") + }, + {.name =3D NULL} +}; + +bool +cmdComplete(vshControl *ctl, const vshCmd *cmd) +{ + bool ret =3D false; +#ifdef WITH_READLINE + const vshClientHooks *hooks =3D ctl->hooks; + int stdin_fileno =3D STDIN_FILENO; + const char *arg =3D NULL; + char **matches =3D NULL, *tmp =3D NULL, **iter; + + if (vshCommandOptStringQuiet(ctl, cmd, "string", &arg) <=3D 0) + goto cleanup; + + /* This command is flagged VSH_CMD_FLAG_NOCONNECT because we + * need to prevent auth hooks reading any input. Therefore we + * have to close stdin and then connect ourselves. */ + VIR_FORCE_CLOSE(stdin_fileno); + + if (!(hooks && hooks->connHandler && hooks->connHandler(ctl, true))) + goto cleanup; + + autoCompleteOpaque =3D ctl; + + rl_basic_word_break_characters =3D " \t\n\\`@$><=3D;|&{("; + if (VIR_STRDUP(rl_line_buffer, arg) < 0) + goto cleanup; + + while ((tmp =3D strpbrk(arg, rl_basic_word_break_characters))) + arg =3D tmp + 1; + + if (!(matches =3D vshReadlineCompletion(arg, 0, 0))) + goto cleanup; + + for (iter =3D matches; *iter; iter++) + printf("%s\n", *iter); + + ret =3D true; + cleanup: + for (iter =3D matches; iter && *iter; iter++) + VIR_FREE(*iter); + VIR_FREE(matches); +#endif /* WITH_READLINE */ + return ret; +} diff --git a/tools/vsh.h b/tools/vsh.h index c5a62e593..f55ba86f0 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -382,6 +382,8 @@ extern const vshCmdInfo info_echo[]; extern const vshCmdInfo info_pwd[]; extern const vshCmdInfo info_quit[]; extern const vshCmdInfo info_selftest[]; +extern const vshCmdOptDef opts_complete[]; +extern const vshCmdInfo info_complete[]; =20 bool cmdHelp(vshControl *ctl, const vshCmd *cmd); bool cmdCd(vshControl *ctl, const vshCmd *cmd); @@ -389,6 +391,7 @@ bool cmdEcho(vshControl *ctl, const vshCmd *cmd); bool cmdPwd(vshControl *ctl, const vshCmd *cmd); bool cmdQuit(vshControl *ctl, const vshCmd *cmd); bool cmdSelfTest(vshControl *ctl, const vshCmd *cmd); +bool cmdComplete(vshControl *ctl, const vshCmd *cmd); =20 # define VSH_CMD_CD \ { \ @@ -454,6 +457,17 @@ bool cmdSelfTest(vshControl *ctl, const vshCmd *cmd); .alias =3D "self-test" \ } =20 +# define VSH_CMD_COMPLETE \ + { \ + .name =3D "complete", \ + .handler =3D cmdComplete, \ + .opts =3D opts_complete, \ + .info =3D info_complete, \ + .flags =3D VSH_CMD_FLAG_NOCONNECT | VSH_CMD_FLAG_ALIAS, \ + .alias =3D "complete" \ + } + + =20 /* readline */ char * vshReadline(vshControl *ctl, const char *prompt); --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 14:26:58 2024 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 1510057403388759.8927508831341; Tue, 7 Nov 2017 04:23:23 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0376881222; Tue, 7 Nov 2017 12:23:22 +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 D7FEB5EDF0; Tue, 7 Nov 2017 12:23:21 +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 A20A13FADE; Tue, 7 Nov 2017 12:23:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CNBPC031670 for ; Tue, 7 Nov 2017 07:23:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id E82354DA61; Tue, 7 Nov 2017 12:23:11 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EAB117161 for ; Tue, 7 Nov 2017 12:23:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0376881222 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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, 7 Nov 2017 13:22:56 +0100 Message-Id: <9017e1efdf4861adef1b835b994265248aca270b.1510055948.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/11] tools: Provide bash autompletion file 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Nov 2017 12:23:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- configure.ac | 3 ++ libvirt.spec.in | 2 ++ m4/virt-bash-completion.m4 | 74 ++++++++++++++++++++++++++++++++++++++++++= ++++ tools/Makefile.am | 22 ++++++++++++-- tools/bash-completion/vsh | 73 ++++++++++++++++++++++++++++++++++++++++++= +++ 5 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 m4/virt-bash-completion.m4 create mode 100644 tools/bash-completion/vsh diff --git a/configure.ac b/configure.ac index b2d991c3b..9103612bb 100644 --- a/configure.ac +++ b/configure.ac @@ -242,6 +242,7 @@ LIBVIRT_ARG_APPARMOR LIBVIRT_ARG_ATTR LIBVIRT_ARG_AUDIT LIBVIRT_ARG_AVAHI +LIBVIRT_ARG_BASH_COMPLETION LIBVIRT_ARG_BLKID LIBVIRT_ARG_CAPNG LIBVIRT_ARG_CURL @@ -278,6 +279,7 @@ LIBVIRT_CHECK_ATOMIC LIBVIRT_CHECK_ATTR LIBVIRT_CHECK_AUDIT LIBVIRT_CHECK_AVAHI +LIBVIRT_CHECK_BASH_COMPLETION LIBVIRT_CHECK_BLKID LIBVIRT_CHECK_CAPNG LIBVIRT_CHECK_CURL @@ -976,6 +978,7 @@ LIBVIRT_RESULT_APPARMOR LIBVIRT_RESULT_ATTR LIBVIRT_RESULT_AUDIT LIBVIRT_RESULT_AVAHI +LIBVIRT_RESULT_BASH_COMPLETION LIBVIRT_RESULT_BLKID LIBVIRT_RESULT_CAPNG LIBVIRT_RESULT_CURL diff --git a/libvirt.spec.in b/libvirt.spec.in index b00689cab..67bbd128c 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -2043,6 +2043,8 @@ exit 0 %{_datadir}/systemtap/tapset/libvirt_qemu_probes*.stp %{_datadir}/systemtap/tapset/libvirt_functions.stp =20 +%{_datadir}/bash-completion/completions/vsh + =20 %if %{with_systemd} %{_unitdir}/libvirt-guests.service diff --git a/m4/virt-bash-completion.m4 b/m4/virt-bash-completion.m4 new file mode 100644 index 000000000..e1ef58740 --- /dev/null +++ b/m4/virt-bash-completion.m4 @@ -0,0 +1,74 @@ +dnl Bash completion support +dnl +dnl Copyright (C) 2017 Red Hat, Inc. +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License, or (at your option) any later version. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library. If not, see +dnl . +dnl +dnl Inspired by libguestfs code. +dnl + +AC_DEFUN([LIBVIRT_ARG_BASH_COMPLETION],[ + LIBVIRT_ARG_WITH_FEATURE([BASH_COMPLETION], [bash-completion], [check], = [2.0]) + LIBVIRT_ARG_WITH([BASH_COMPLETIONS_DIR], + [directory containing bash completions scripts], + [check]) +]) + +AC_DEFUN([LIBVIRT_CHECK_BASH_COMPLETION], [ + AC_REQUIRE([LIBVIRT_CHECK_READLINE]) + + if test "x$with_readline" !=3D "xyes" ; then + if test "x$with_bash_completion" !=3D "xyes" ; then + with_bash_completion=3Dno + else + AC_MSG_ERROR([readline is required for bash completion support]) + fi + else + if test "x$with_bash_completion" =3D "xcheck" ; then + with_bash_completion=3Dyes + fi + fi + + LIBVIRT_CHECK_PKG([BASH_COMPLETION], [bash-completion], [2.0]) + + if test "x$with_bash_completion" =3D "xyes" ; then + if test "x$with_bash_completions_dir" =3D "xcheck"; then + AC_MSG_CHECKING([for bash-completions directory]) + BASH_COMPLETIONS_DIR=3D"$($PKG_CONFIG --variable=3Dcompletionsdir ba= sh-completion)" + AC_MSG_RESULT([$BASH_COMPLETIONS_DIR]) + + dnl Replace bash completions's exec_prefix with our own. + dnl Note that ${exec_prefix} is kept verbatim at this point in time, + dnl and will only be expanded later, when make is called: this makes + dnl it possible to override such prefix at compilation or installati= on + dnl time + bash_completions_prefix=3D"$($PKG_CONFIG --variable=3Dprefix bash-co= mpletion)" + if test "x$bash_completions_prefix" =3D "x" ; then + bash_completions_prefix=3D"/usr" + fi + + BASH_COMPLETIONS_DIR=3D'${exec_prefix}'"${BASH_COMPLETIONS_DIR#$bash= _completions_prefix}" + elif test "x$with_bash_completions_dir" =3D "xno" || test "x$with_bash= _completions_dir" =3D "xyes"; then + AC_MSG_ERROR([bash-completions-dir must be used only with valid path= ]) + else + BASH_COMPLETIONS_DIR=3D$with_bash_completions_dir + fi + AC_SUBST([BASH_COMPLETIONS_DIR]) + fi +]) + +AC_DEFUN([LIBVIRT_RESULT_BASH_COMPLETION],[ + LIBVIRT_RESULT_LIB([BASH_COMPLETION]) +]) diff --git a/tools/Makefile.am b/tools/Makefile.am index 7513a73ac..34a81e69c 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -66,6 +66,7 @@ EXTRA_DIST =3D \ libvirt-guests.sysconf \ virt-login-shell.conf \ virsh-edit.c \ + bash-completion/vsh \ $(PODFILES) \ $(MANINFILES) \ $(NULL) @@ -332,9 +333,11 @@ POD2MAN =3D pod2man -c "Virtualization Support" -r "$(= PACKAGE)-$(VERSION)" < $< > $@-t && \ mv $@-t $@ =20 -install-data-local: install-init install-systemd install-nss +install-data-local: install-init install-systemd install-nss \ + install-bash-completion =20 -uninstall-local: uninstall-init uninstall-systemd uninstall-nss +uninstall-local: uninstall-init uninstall-systemd uninstall-nss \ + uninstall-bash-completion =20 install-sysconfig: $(MKDIR_P) $(DESTDIR)$(sysconfdir)/sysconfig @@ -420,6 +423,21 @@ libvirt-guests.service: libvirt-guests.service.in $(to= p_builddir)/config.status mv $@-t $@ =20 =20 +if WITH_BASH_COMPLETION +install-bash-completion: + $(MKDIR_P) "$(DESTDIR)$(BASH_COMPLETIONS_DIR)" + $(INSTALL_SCRIPT) $(srcdir)/bash-completion/vsh \ + "$(DESTDIR)$(BASH_COMPLETIONS_DIR)/vsh" + +uninstall-bash-completion: + rm -f $(DESTDIR)$(BASH_COMPLETIONS_DIR)/vsh + rmdir $(DESTDIR)$(BASH_COMPLETIONS_DIR) ||: +else ! WITH_BASH_COMPLETION +install-bash-completion: +uninstall-bash-completion: +endif ! WITH_BASH_COMPLETION + + EXTRA_DIST +=3D \ wireshark/util/genxdrstub.pl \ wireshark/util/make-dissector-reg diff --git a/tools/bash-completion/vsh b/tools/bash-completion/vsh new file mode 100644 index 000000000..0c923c8b5 --- /dev/null +++ b/tools/bash-completion/vsh @@ -0,0 +1,73 @@ +# +# virsh & virt-admin completion command +# + +_vsh_complete() +{ + local words cword c=3D0 i=3D0 cur RO URI CMDLINE INPUT A + + # Here, $COMP_WORDS is an array of words on the bash + # command line that user wants to complete. However, when + # parsing command line, the default set of word breaks is + # applied. This doesn't work for us as it mangles libvirt + # arguments, e.g. connection URI (with the default set it's + # split into multiple items within the array). Fortunately, + # there's a fixup function for the array. + _get_comp_words_by_ref -n "\"'><=3D;|&(:" -w words -i cword + COMP_WORDS=3D( "${words[@]}" ) + COMP_CWORD=3D${cword} + cur=3D${COMP_WORDS[$COMP_CWORD]} + + # See what URI is user trying to connect to and if they are + # connecting RO. Honour that. + while [ $c -le $COMP_CWORD ]; do + word=3D"${COMP_WORDS[c]}" + case "$word" in + -r|--readonly) RO=3D1 ;; + -c|--connect) c=3D$((++c)); URI=3D${COMP_WORDS[c]} ;; + *) if [ $c -ne 0 ] && [ $i -eq 0 ]; then i=3D$c; break; fi ;; + esac + c=3D$((++c)) + done + + CMDLINE=3D + if [ -n "${RO}" ]; then + CMDLINE=3D"${CMDLINE} -r" + fi + if [ -n "${URI}" ]; then + CMDLINE=3D"${CMDLINE} -c ${URI}" + fi + + INPUT=3D"${COMP_WORDS[@]:$i}" + + # Uncomment these lines for easy debug. +# echo; +# echo "RO=3D${flag_ro}"; +# echo "URI=3D${URI}"; +# echo "CMDLINE=3D${CMDLINE}"; +# echo "INPUT[${#INPUT[@]}]=3D**${INPUT}**"; +# echo "cur=3D${cur}"; +# echo; +# return 0; + + # Small shortcut here. According to manpage: + # When the function is executed, the first argument ($1) is + # the name of the command whose arguments are being + # completed. + # Therefore, we might just run $1. + A=3D($($1 ${CMDLINE} complete "${INPUT}" 2>/dev/null)) + + # If our 'complete' command hasn't offered anything offer + # filedir completion. + if [ ${#A[@]} -gt 0 ]; then + COMPREPLY=3D($(compgen -W "${A[*]%--}" -- ${cur})) + else + _filedir + fi + __ltrim_colon_completions "$cur" + return 0 +} && +complete -F _vsh_complete virsh && +complete -F _vsh_complete virt-admin + +# vim: ft=3Dsh:et:ts=3D4:sw=3D4:tw=3D80 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 14:26:58 2024 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 1510057398055249.50351450940116; Tue, 7 Nov 2017 04:23:18 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 639187E437; Tue, 7 Nov 2017 12:23:16 +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 3542717DE6; Tue, 7 Nov 2017 12:23:16 +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 C9DA41800C87; Tue, 7 Nov 2017 12:23:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CNCTH031679 for ; Tue, 7 Nov 2017 07:23:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id E3C1D5C542; Tue, 7 Nov 2017 12:23:12 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 425635C545 for ; Tue, 7 Nov 2017 12:23:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 639187E437 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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, 7 Nov 2017 13:22:57 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/11] virsh: Introduce virshDomainNameCompleter 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 07 Nov 2017 12:23:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- tools/Makefile.am | 9 +++ tools/virsh-completer.c | 90 +++++++++++++++++++++ tools/virsh-completer.h | 33 ++++++++ tools/virsh-domain-monitor.c | 30 +++---- tools/virsh-domain.c | 182 ++++++++++++++++++++++-----------------= ---- tools/virsh-snapshot.c | 24 +++--- tools/virsh.h | 7 +- 7 files changed, 256 insertions(+), 119 deletions(-) create mode 100644 tools/virsh-completer.c create mode 100644 tools/virsh-completer.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 34a81e69c..8eddc7bbe 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -231,6 +231,15 @@ virsh_SOURCES =3D \ virsh-volume.c virsh-volume.h \ $(NULL) =20 +VIRSH_COMPLETER =3D \ + virsh-completer.c virsh-completer.h + +if WITH_READLINE +virsh_SOURCES +=3D $(VIRSH_COMPLETER) +else ! WITH_READLINE +EXTRA_DIST +=3D $(VIRSH_COMPLETER) +endif ! WITH_READLINE + virsh_LDFLAGS =3D \ $(AM_LDFLAGS) \ $(PIE_LDFLAGS) \ diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c new file mode 100644 index 000000000..4e32b882b --- /dev/null +++ b/tools/virsh-completer.c @@ -0,0 +1,90 @@ +/* + * virsh-completer.c: virsh completer callbacks + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Michal Privoznik + * + */ + +#include + +#include "virsh-completer.h" +#include "virsh.h" +#include "virsh-util.h" +#include "internal.h" +#include "viralloc.h" +#include "virstring.h" + + +char ** +virshDomainNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virDomainPtr *domains =3D NULL; + int ndomains =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE | + VIR_CONNECT_LIST_DOMAINS_PERSISTENT | + VIR_CONNECT_LIST_DOMAINS_TRANSIENT | + VIR_CONNECT_LIST_DOMAINS_RUNNING | + VIR_CONNECT_LIST_DOMAINS_PAUSED | + VIR_CONNECT_LIST_DOMAINS_SHUTOFF | + VIR_CONNECT_LIST_DOMAINS_OTHER | + VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE | + VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE | + VIR_CONNECT_LIST_DOMAINS_AUTOSTART | + VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART | + VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT | + VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, + NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((ndomains =3D virConnectListAllDomains(priv->conn, &domains, flags= )) < 0) + return NULL; + + if (VIR_ALLOC_N(ret, ndomains + 1) < 0) + goto error; + + for (i =3D 0; i < ndomains; i++) { + const char *name =3D virDomainGetName(domains[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virshDomainFree(domains[i]); + } + VIR_FREE(domains); + + return ret; + error: + + for (; i < ndomains; i++) + virshDomainFree(domains[i]); + VIR_FREE(domains); + for (i =3D 0; i < ndomains; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h new file mode 100644 index 000000000..288e17909 --- /dev/null +++ b/tools/virsh-completer.h @@ -0,0 +1,33 @@ +/* + * virsh-completer.h: virsh completer callbacks + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Michal Privoznik + * + */ + +#ifndef VIRSH_COMPLETER +# define VIRSH_COMPLETER + +# include "vsh.h" + +char ** virshDomainNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +#endif diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index b3bfc33c8..d0edb177d 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -40,8 +40,8 @@ #include "virxml.h" #include "virstring.h" =20 -#define VIRSH_COMMON_OPT_DOMAIN_FULL \ - VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid")) +#define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \ + VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid"), cflags) =20 VIR_ENUM_DECL(virshDomainIOError) VIR_ENUM_IMPL(virshDomainIOError, @@ -278,7 +278,7 @@ static const vshCmdInfo info_dommemstat[] =3D { }; =20 static const vshCmdOptDef opts_dommemstat[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "period", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ_OPT, @@ -390,7 +390,7 @@ static const vshCmdInfo info_domblkinfo[] =3D { }; =20 static const vshCmdOptDef opts_domblkinfo[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "device", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -460,7 +460,7 @@ static const vshCmdInfo info_domblklist[] =3D { }; =20 static const vshCmdOptDef opts_domblklist[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "inactive", .type =3D VSH_OT_BOOL, .help =3D N_("get inactive rather than running configuration") @@ -566,7 +566,7 @@ static const vshCmdInfo info_domiflist[] =3D { }; =20 static const vshCmdOptDef opts_domiflist[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "inactive", .type =3D VSH_OT_BOOL, .help =3D N_("get inactive rather than running configuration") @@ -655,7 +655,7 @@ static const vshCmdInfo info_domif_getlink[] =3D { }; =20 static const vshCmdOptDef opts_domif_getlink[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "interface", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -752,7 +752,7 @@ static const vshCmdInfo info_domcontrol[] =3D { }; =20 static const vshCmdOptDef opts_domcontrol[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 @@ -805,7 +805,7 @@ static const vshCmdInfo info_domblkstat[] =3D { }; =20 static const vshCmdOptDef opts_domblkstat[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "device", .type =3D VSH_OT_STRING, .flags =3D VSH_OFLAG_EMPTY_OK, @@ -991,7 +991,7 @@ static const vshCmdInfo info_domifstat[] =3D { }; =20 static const vshCmdOptDef opts_domifstat[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "interface", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -1064,7 +1064,7 @@ static const vshCmdInfo info_domblkerror[] =3D { }; =20 static const vshCmdOptDef opts_domblkerror[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 @@ -1125,7 +1125,7 @@ static const vshCmdInfo info_dominfo[] =3D { }; =20 static const vshCmdOptDef opts_dominfo[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D NULL} }; =20 @@ -1264,7 +1264,7 @@ static const vshCmdInfo info_domstate[] =3D { }; =20 static const vshCmdOptDef opts_domstate[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "reason", .type =3D VSH_OT_BOOL, .help =3D N_("also print reason for the state") @@ -1316,7 +1316,7 @@ static const vshCmdInfo info_domtime[] =3D { }; =20 static const vshCmdOptDef opts_domtime[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "now", .type =3D VSH_OT_BOOL, .help =3D N_("set to the time of the host running virsh") @@ -2145,7 +2145,7 @@ static const vshCmdInfo info_domifaddr[] =3D { }; =20 static const vshCmdOptDef opts_domifaddr[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "interface", .type =3D VSH_OT_STRING, .flags =3D VSH_OFLAG_NONE, diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index cf612f73e..101a5f647 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -65,8 +65,8 @@ # define SA_SIGINFO 0 #endif =20 -#define VIRSH_COMMON_OPT_DOMAIN_FULL \ - VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid")) +#define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \ + VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid"), cflags) =20 #define VIRSH_COMMON_OPT_DOMAIN_PERSISTENT \ {.name =3D "persistent", \ @@ -154,7 +154,7 @@ static const vshCmdInfo info_attach_device[] =3D { }; =20 static const vshCmdOptDef opts_attach_device[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_FILE(N_("XML file")), VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, VIRSH_COMMON_OPT_DOMAIN_CONFIG, @@ -236,7 +236,7 @@ static const vshCmdInfo info_attach_disk[] =3D { }; =20 static const vshCmdOptDef opts_attach_disk[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "source", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK, @@ -727,7 +727,7 @@ static const vshCmdInfo info_attach_interface[] =3D { }; =20 static const vshCmdOptDef opts_attach_interface[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "type", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -1037,7 +1037,7 @@ static const vshCmdInfo info_autostart[] =3D { }; =20 static const vshCmdOptDef opts_autostart[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "disable", .type =3D VSH_OT_BOOL, .help =3D N_("disable autostarting") @@ -1089,7 +1089,7 @@ static const vshCmdInfo info_blkdeviotune[] =3D { }; =20 static const vshCmdOptDef opts_blkdeviotune[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "device", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -1416,7 +1416,7 @@ static const vshCmdInfo info_blkiotune[] =3D { }; =20 static const vshCmdOptDef opts_blkiotune[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "weight", .type =3D VSH_OT_INT, .help =3D N_("IO Weight") @@ -1885,7 +1885,7 @@ static const vshCmdInfo info_block_commit[] =3D { }; =20 static const vshCmdOptDef opts_block_commit[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "path", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -2110,7 +2110,7 @@ static const vshCmdInfo info_block_copy[] =3D { }; =20 static const vshCmdOptDef opts_block_copy[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "path", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -2426,7 +2426,7 @@ static const vshCmdInfo info_block_job[] =3D { }; =20 static const vshCmdOptDef opts_block_job[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "path", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -2669,7 +2669,7 @@ static const vshCmdInfo info_block_pull[] =3D { }; =20 static const vshCmdOptDef opts_block_pull[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "path", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -2815,7 +2815,7 @@ static const vshCmdInfo info_block_resize[] =3D { }; =20 static const vshCmdOptDef opts_block_resize[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "path", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -2879,7 +2879,7 @@ static const vshCmdInfo info_console[] =3D { }; =20 static const vshCmdOptDef opts_console[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "devname", /* sc_prohibit_devname */ .type =3D VSH_OT_STRING, .help =3D N_("character device name") @@ -2973,7 +2973,7 @@ static const vshCmdInfo info_domif_setlink[] =3D { }; =20 static const vshCmdOptDef opts_domif_setlink[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "interface", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -3143,7 +3143,7 @@ static const vshCmdInfo info_domiftune[] =3D { }; =20 static const vshCmdOptDef opts_domiftune[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "interface", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -3340,7 +3340,7 @@ static const vshCmdInfo info_suspend[] =3D { }; =20 static const vshCmdOptDef opts_suspend[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_RUNNING), {.name =3D NULL} }; =20 @@ -3382,7 +3382,7 @@ static const vshCmdInfo info_dom_pm_suspend[] =3D { }; =20 static const vshCmdOptDef opts_dom_pm_suspend[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_RUNNING), {.name =3D "target", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -3460,7 +3460,7 @@ static const vshCmdInfo info_dom_pm_wakeup[] =3D { }; =20 static const vshCmdOptDef opts_dom_pm_wakeup[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_OTHER), {.name =3D NULL} }; =20 @@ -3505,7 +3505,7 @@ static const vshCmdInfo info_undefine[] =3D { }; =20 static const vshCmdOptDef opts_undefine[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_PERSISTENT), {.name =3D "managed-save", .type =3D VSH_OT_BOOL, .help =3D N_("remove domain managed state file") @@ -3923,7 +3923,8 @@ static const vshCmdInfo info_start[] =3D { }; =20 static const vshCmdOptDef opts_start[] =3D { - VIRSH_COMMON_OPT_DOMAIN(N_("name of the inactive domain")), + VIRSH_COMMON_OPT_DOMAIN(N_("name of the inactive domain"), + VIR_CONNECT_LIST_DOMAINS_SHUTOFF), #ifndef WIN32 {.name =3D "console", .type =3D VSH_OT_BOOL, @@ -4098,7 +4099,7 @@ static const vshCmdInfo info_save[] =3D { }; =20 static const vshCmdOptDef opts_save[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), VIRSH_COMMON_OPT_FILE(N_("where to save the data")), {.name =3D "bypass-cache", .type =3D VSH_OT_BOOL, @@ -4544,7 +4545,7 @@ static const vshCmdInfo info_managedsave[] =3D { }; =20 static const vshCmdOptDef opts_managedsave[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "bypass-cache", .type =3D VSH_OT_BOOL, .help =3D N_("avoid file system cache when saving") @@ -4663,7 +4664,7 @@ static const vshCmdInfo info_managedsaveremove[] =3D { }; =20 static const vshCmdOptDef opts_managedsaveremove[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D NULL} }; =20 @@ -4718,7 +4719,7 @@ static const vshCmdInfo info_managed_save_edit[] =3D { }; =20 static const vshCmdOptDef opts_managed_save_edit[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "running", .type =3D VSH_OT_BOOL, .help =3D N_("set domain to be running on start") @@ -4784,7 +4785,7 @@ static const vshCmdInfo info_managed_save_dumpxml[] = =3D { }; =20 static const vshCmdOptDef opts_managed_save_dumpxml[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "security-info", .type =3D VSH_OT_BOOL, .help =3D N_("include security sensitive information in XML dump") @@ -4832,7 +4833,7 @@ static const vshCmdInfo info_managed_save_define[] = =3D { }; =20 static const vshCmdOptDef opts_managed_save_define[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "xml", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -4904,7 +4905,7 @@ static const vshCmdInfo info_schedinfo[] =3D { }; =20 static const vshCmdOptDef opts_schedinfo[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "weight", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ_OPT, @@ -5215,7 +5216,7 @@ static const vshCmdInfo info_dump[] =3D { }; =20 static const vshCmdOptDef opts_dump[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), VIRSH_COMMON_OPT_FILE(N_("where to dump the core")), VIRSH_COMMON_OPT_LIVE(N_("perform a live core dump if supported")), {.name =3D "crash", @@ -5387,7 +5388,7 @@ static const vshCmdInfo info_screenshot[] =3D { }; =20 static const vshCmdOptDef opts_screenshot[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "file", .type =3D VSH_OT_STRING, .help =3D N_("where to store the screenshot") @@ -5530,7 +5531,7 @@ static const vshCmdInfo info_setLifecycleAction[] =3D= { }; =20 static const vshCmdOptDef opts_setLifecycleAction[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "type", .type =3D VSH_OT_STRING, .flags =3D VSH_OFLAG_REQ, @@ -5626,7 +5627,7 @@ static const vshCmdInfo info_set_user_password[] =3D { }; =20 static const vshCmdOptDef opts_set_user_password[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "user", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -5690,7 +5691,7 @@ static const vshCmdInfo info_resume[] =3D { }; =20 static const vshCmdOptDef opts_resume[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_PAUSED), {.name =3D NULL} }; =20 @@ -5729,7 +5730,7 @@ static const vshCmdInfo info_shutdown[] =3D { }; =20 static const vshCmdOptDef opts_shutdown[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "mode", .type =3D VSH_OT_STRING, .help =3D N_("shutdown mode: acpi|agent|initctl|signal|paravirt") @@ -5813,7 +5814,7 @@ static const vshCmdInfo info_reboot[] =3D { }; =20 static const vshCmdOptDef opts_reboot[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "mode", .type =3D VSH_OT_STRING, .help =3D N_("shutdown mode: acpi|agent|initctl|signal|paravirt") @@ -5892,7 +5893,7 @@ static const vshCmdInfo info_reset[] =3D { }; =20 static const vshCmdOptDef opts_reset[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D NULL} }; =20 @@ -5931,7 +5932,7 @@ static const vshCmdInfo info_domjobinfo[] =3D { }; =20 static const vshCmdOptDef opts_domjobinfo[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "completed", .type =3D VSH_OT_BOOL, .help =3D N_("return statistics of a recently completed job") @@ -6275,7 +6276,7 @@ static const vshCmdInfo info_domjobabort[] =3D { }; =20 static const vshCmdOptDef opts_domjobabort[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 @@ -6309,7 +6310,7 @@ static const vshCmdInfo info_vcpucount[] =3D { }; =20 static const vshCmdOptDef opts_vcpucount[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "maximum", .type =3D VSH_OT_BOOL, .help =3D N_("get maximum count of vcpus") @@ -6506,7 +6507,7 @@ static const vshCmdInfo info_vcpuinfo[] =3D { }; =20 static const vshCmdOptDef opts_vcpuinfo[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "pretty", .type =3D VSH_OT_BOOL, .help =3D N_("return human readable output") @@ -6755,7 +6756,7 @@ static const vshCmdInfo info_vcpupin[] =3D { }; =20 static const vshCmdOptDef opts_vcpupin[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "vcpu", .type =3D VSH_OT_INT, .help =3D N_("vcpu number") @@ -6972,7 +6973,7 @@ static const vshCmdInfo info_emulatorpin[] =3D { }; =20 static const vshCmdOptDef opts_emulatorpin[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "cpulist", .type =3D VSH_OT_STRING, .flags =3D VSH_OFLAG_EMPTY_OK, @@ -7076,7 +7077,7 @@ static const vshCmdInfo info_setvcpus[] =3D { }; =20 static const vshCmdOptDef opts_setvcpus[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "count", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ, @@ -7174,7 +7175,7 @@ static const vshCmdInfo info_guestvcpus[] =3D { }; =20 static const vshCmdOptDef opts_guestvcpus[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "cpulist", .type =3D VSH_OT_STRING, .help =3D N_("list of cpus to enable or disable") @@ -7259,7 +7260,7 @@ static const vshCmdInfo info_setvcpu[] =3D { }; =20 static const vshCmdOptDef opts_setvcpu[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "vcpulist", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -7342,7 +7343,7 @@ static const vshCmdInfo info_domblkthreshold[] =3D { }; =20 static const vshCmdOptDef opts_domblkthreshold[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "dev", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -7398,7 +7399,7 @@ static const vshCmdInfo info_iothreadinfo[] =3D { {.name =3D NULL} }; static const vshCmdOptDef opts_iothreadinfo[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_DOMAIN_CONFIG, VIRSH_COMMON_OPT_DOMAIN_LIVE, VIRSH_COMMON_OPT_DOMAIN_CURRENT, @@ -7474,7 +7475,7 @@ static const vshCmdInfo info_iothreadpin[] =3D { }; =20 static const vshCmdOptDef opts_iothreadpin[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "iothread", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ, @@ -7556,7 +7557,7 @@ static const vshCmdInfo info_iothreadadd[] =3D { }; =20 static const vshCmdOptDef opts_iothreadadd[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "id", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ, @@ -7621,7 +7622,7 @@ static const vshCmdInfo info_iothreaddel[] =3D { }; =20 static const vshCmdOptDef opts_iothreaddel[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "id", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ, @@ -7897,7 +7898,7 @@ static const vshCmdInfo info_cpu_stats[] =3D { }; =20 static const vshCmdOptDef opts_cpu_stats[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "total", .type =3D VSH_OT_BOOL, .help =3D N_("Show total statistics only") @@ -8236,7 +8237,7 @@ static const vshCmdInfo info_destroy[] =3D { }; =20 static const vshCmdOptDef opts_destroy[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "graceful", .type =3D VSH_OT_BOOL, .help =3D N_("terminate gracefully") @@ -8289,7 +8290,7 @@ static const vshCmdInfo info_desc[] =3D { }; =20 static const vshCmdOptDef opts_desc[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_LIVE(N_("modify/get running state")), VIRSH_COMMON_OPT_CONFIG(N_("modify/get persistent configuration")), VIRSH_COMMON_OPT_CURRENT(N_("modify/get current state configuration")), @@ -8454,7 +8455,7 @@ static const vshCmdInfo info_metadata[] =3D { }; =20 static const vshCmdOptDef opts_metadata[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "uri", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -8600,7 +8601,7 @@ static const vshCmdInfo info_inject_nmi[] =3D { }; =20 static const vshCmdOptDef opts_inject_nmi[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 @@ -8634,7 +8635,7 @@ static const vshCmdInfo info_send_key[] =3D { }; =20 static const vshCmdOptDef opts_send_key[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "codeset", .type =3D VSH_OT_STRING, .flags =3D VSH_OFLAG_REQ_OPT, @@ -8730,7 +8731,7 @@ static const vshCmdInfo info_send_process_signal[] = =3D { }; =20 static const vshCmdOptDef opts_send_process_signal[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "pid", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -8835,7 +8836,7 @@ static const vshCmdInfo info_setmem[] =3D { }; =20 static const vshCmdOptDef opts_setmem[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "kilobytes", .type =3D VSH_OT_ALIAS, .help =3D "size" @@ -8916,7 +8917,7 @@ static const vshCmdInfo info_setmaxmem[] =3D { }; =20 static const vshCmdOptDef opts_setmaxmem[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "kilobytes", .type =3D VSH_OT_ALIAS, .help =3D "size" @@ -9004,7 +9005,7 @@ static const vshCmdInfo info_memtune[] =3D { }; =20 static const vshCmdOptDef opts_memtune[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "hard-limit", .type =3D VSH_OT_INT, .help =3D N_("Max memory, as scaled integer (default KiB)") @@ -9181,7 +9182,7 @@ static const vshCmdInfo info_perf[] =3D { }; =20 static const vshCmdOptDef opts_perf[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "enable", .type =3D VSH_OT_STRING, .help =3D N_("perf events which will be enabled") @@ -9315,7 +9316,7 @@ static const vshCmdInfo info_numatune[] =3D { }; =20 static const vshCmdOptDef opts_numatune[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "mode", .type =3D VSH_OT_STRING, .help =3D N_("NUMA mode, one of strict, preferred and interleave \n" @@ -9450,7 +9451,7 @@ static const vshCmdInfo info_qemu_monitor_command[] = =3D { }; =20 static const vshCmdOptDef opts_qemu_monitor_command[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "hmp", .type =3D VSH_OT_BOOL, .help =3D N_("command is in human monitor protocol") @@ -9751,7 +9752,7 @@ static const vshCmdInfo info_qemu_agent_command[] =3D= { }; =20 static const vshCmdOptDef opts_qemu_agent_command[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "timeout", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ_OPT, @@ -9873,7 +9874,7 @@ static const vshCmdInfo info_lxc_enter_namespace[] = =3D { }; =20 static const vshCmdOptDef opts_lxc_enter_namespace[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "noseclabel", .type =3D VSH_OT_BOOL, .help =3D N_("Do not change process security label") @@ -10014,7 +10015,7 @@ static const vshCmdInfo info_dumpxml[] =3D { }; =20 static const vshCmdOptDef opts_dumpxml[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "inactive", .type =3D VSH_OT_BOOL, .help =3D N_("show inactive defined XML") @@ -10223,7 +10224,7 @@ static const vshCmdInfo info_domname[] =3D { }; =20 static const vshCmdOptDef opts_domname[] =3D { - VIRSH_COMMON_OPT_DOMAIN(N_("domain id or uuid")), + VIRSH_COMMON_OPT_DOMAIN(N_("domain id or uuid"), 0), {.name =3D NULL} }; =20 @@ -10255,7 +10256,7 @@ static const vshCmdInfo info_domrename[] =3D { }; =20 static const vshCmdOptDef opts_domrename[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_INACTIVE), {.name =3D "new-name", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -10302,7 +10303,8 @@ static const vshCmdInfo info_domid[] =3D { }; =20 static const vshCmdOptDef opts_domid[] =3D { - VIRSH_COMMON_OPT_DOMAIN(N_("domain name or uuid")), + VIRSH_COMMON_OPT_DOMAIN(N_("domain name or uuid"), + VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 @@ -10339,7 +10341,7 @@ static const vshCmdInfo info_domuuid[] =3D { }; =20 static const vshCmdOptDef opts_domuuid[] =3D { - VIRSH_COMMON_OPT_DOMAIN(N_("domain id or name")), + VIRSH_COMMON_OPT_DOMAIN(N_("domain id or name"), 0), {.name =3D NULL} }; =20 @@ -10376,7 +10378,7 @@ static const vshCmdInfo info_migrate[] =3D { }; =20 static const vshCmdOptDef opts_migrate[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "desturi", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -10974,7 +10976,7 @@ static const vshCmdInfo info_migrate_setmaxdowntime= [] =3D { }; =20 static const vshCmdOptDef opts_migrate_setmaxdowntime[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "downtime", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ, @@ -11025,7 +11027,7 @@ static const vshCmdInfo info_migrate_getmaxdowntime= [] =3D { }; =20 static const vshCmdOptDef opts_migrate_getmaxdowntime[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 @@ -11066,7 +11068,7 @@ static const vshCmdInfo info_migrate_compcache[] = =3D { }; =20 static const vshCmdOptDef opts_migrate_compcache[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "size", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ_OPT, @@ -11123,7 +11125,7 @@ static const vshCmdInfo info_migrate_setspeed[] =3D= { }; =20 static const vshCmdOptDef opts_migrate_setspeed[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "bandwidth", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ, @@ -11169,7 +11171,7 @@ static const vshCmdInfo info_migrate_getspeed[] =3D= { }; =20 static const vshCmdOptDef opts_migrate_getspeed[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 @@ -11252,7 +11254,7 @@ static const vshCmdInfo info_domdisplay[] =3D { }; =20 static const vshCmdOptDef opts_domdisplay[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "include-password", .type =3D VSH_OT_BOOL, .help =3D N_("includes the password into the connection URI if availa= ble") @@ -11533,7 +11535,7 @@ static const vshCmdInfo info_vncdisplay[] =3D { }; =20 static const vshCmdOptDef opts_vncdisplay[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 @@ -11609,7 +11611,7 @@ static const vshCmdInfo info_ttyconsole[] =3D { }; =20 static const vshCmdOptDef opts_ttyconsole[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 @@ -11651,7 +11653,7 @@ static const vshCmdInfo info_domhostname[] =3D { }; =20 static const vshCmdOptDef opts_domhostname[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D NULL} }; =20 @@ -11810,7 +11812,7 @@ static const vshCmdInfo info_detach_device[] =3D { }; =20 static const vshCmdOptDef opts_detach_device[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_FILE(N_("XML file")), VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, VIRSH_COMMON_OPT_DOMAIN_CONFIG, @@ -11891,7 +11893,7 @@ static const vshCmdInfo info_update_device[] =3D { }; =20 static const vshCmdOptDef opts_update_device[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), VIRSH_COMMON_OPT_FILE(N_("XML file")), VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, VIRSH_COMMON_OPT_DOMAIN_CONFIG, @@ -11973,7 +11975,7 @@ static const vshCmdInfo info_detach_interface[] =3D= { }; =20 static const vshCmdOptDef opts_detach_interface[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "type", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -12416,7 +12418,7 @@ static const vshCmdInfo info_detach_disk[] =3D { }; =20 static const vshCmdOptDef opts_detach_disk[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "target", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -12516,7 +12518,7 @@ static const vshCmdInfo info_edit[] =3D { }; =20 static const vshCmdOptDef opts_edit[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "skip-validate", .type =3D VSH_OT_BOOL, .help =3D N_("skip validation of the XML against the schema") @@ -13475,7 +13477,7 @@ static const vshCmdInfo info_change_media[] =3D { }; =20 static const vshCmdOptDef opts_change_media[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "path", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -13636,7 +13638,7 @@ static const vshCmdInfo info_domfstrim[] =3D { }; =20 static const vshCmdOptDef opts_domfstrim[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "minimum", .type =3D VSH_OT_INT, .help =3D N_("Just a hint to ignore contiguous " @@ -13689,7 +13691,7 @@ static const vshCmdInfo info_domfsfreeze[] =3D { }; =20 static const vshCmdOptDef opts_domfsfreeze[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "mountpoint", .type =3D VSH_OT_ARGV, .help =3D N_("mountpoint path to be frozen") @@ -13742,7 +13744,7 @@ static const vshCmdInfo info_domfsthaw[] =3D { }; =20 static const vshCmdOptDef opts_domfsthaw[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D "mountpoint", .type =3D VSH_OT_ARGV, .help =3D N_("mountpoint path to be thawed") @@ -13795,7 +13797,7 @@ static const vshCmdInfo info_domfsinfo[] =3D { }; =20 static const vshCmdOptDef opts_domfsinfo[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), {.name =3D NULL} }; =20 diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index cd89a414a..c44a36f98 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -42,8 +42,8 @@ #include "virxml.h" #include "conf/snapshot_conf.h" =20 -#define VIRSH_COMMON_OPT_DOMAIN_FULL \ - VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid")) +#define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \ + VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid"), cflags) =20 /* Helper for snapshot-create and snapshot-create-as */ static bool @@ -125,7 +125,7 @@ static const vshCmdInfo info_snapshot_create[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_create[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "xmlfile", .type =3D VSH_OT_STRING, .help =3D N_("domain snapshot XML") @@ -319,7 +319,7 @@ static const vshCmdInfo info_snapshot_create_as[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_create_as[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "name", .type =3D VSH_OT_STRING, .help =3D N_("name of snapshot") @@ -508,7 +508,7 @@ static const vshCmdInfo info_snapshot_edit[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_edit[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, .help =3D N_("snapshot name") @@ -620,7 +620,7 @@ static const vshCmdInfo info_snapshot_current[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_current[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "name", .type =3D VSH_OT_BOOL, .help =3D N_("list the name, rather than the full xml") @@ -851,7 +851,7 @@ static const vshCmdInfo info_snapshot_info[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_info[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, .help =3D N_("snapshot name") @@ -1401,7 +1401,7 @@ static const vshCmdInfo info_snapshot_list[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_list[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "parent", .type =3D VSH_OT_BOOL, .help =3D N_("add a column showing parent snapshot") @@ -1657,7 +1657,7 @@ static const vshCmdInfo info_snapshot_dumpxml[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_dumpxml[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, @@ -1720,7 +1720,7 @@ static const vshCmdInfo info_snapshot_parent[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_parent[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, .help =3D N_("find parent of snapshot name") @@ -1779,7 +1779,7 @@ static const vshCmdInfo info_snapshot_revert[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_revert[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, .help =3D N_("snapshot name") @@ -1863,7 +1863,7 @@ static const vshCmdInfo info_snapshot_delete[] =3D { }; =20 static const vshCmdOptDef opts_snapshot_delete[] =3D { - VIRSH_COMMON_OPT_DOMAIN_FULL, + VIRSH_COMMON_OPT_DOMAIN_FULL(0), {.name =3D "snapshotname", .type =3D VSH_OT_STRING, .help =3D N_("snapshot name") diff --git a/tools/virsh.h b/tools/virsh.h index e03b597ef..856513a48 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -38,6 +38,7 @@ # include "virthread.h" # include "virpolkit.h" # include "vsh.h" +# include "virsh-completer.h" =20 # define VIRSH_PROMPT_RW "virsh # " # define VIRSH_PROMPT_RO "virsh > " @@ -70,11 +71,13 @@ .help =3D _helpstr \ } =20 -# define VIRSH_COMMON_OPT_DOMAIN(_helpstr) \ +# define VIRSH_COMMON_OPT_DOMAIN(_helpstr, cflags) \ {.name =3D "domain", \ .type =3D VSH_OT_DATA, \ .flags =3D VSH_OFLAG_REQ, \ - .help =3D _helpstr \ + .help =3D _helpstr, \ + .completer =3D virshDomainNameCompleter, \ + .completer_flags =3D cflags, \ } =20 # define VIRSH_COMMON_OPT_CONFIG(_helpstr) \ --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 14:26:58 2024 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 1510057407665108.49900535330517; Tue, 7 Nov 2017 04:23:27 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DD9FC047B75; Tue, 7 Nov 2017 12:23:26 +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 1154A5EDEE; Tue, 7 Nov 2017 12:23:26 +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 D39CE3D381; Tue, 7 Nov 2017 12:23:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CNG32031705 for ; Tue, 7 Nov 2017 07:23:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1550A1821D; Tue, 7 Nov 2017 12:23:16 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90D6F5C8BA for ; Tue, 7 Nov 2017 12:23:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2DD9FC047B75 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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, 7 Nov 2017 13:22:58 +0100 Message-Id: <66f6ac316fe5e4f379cfce3f729d17bf026d72eb.1510055948.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/11] virsh: Introduce virshDomainInterfaceCompleter 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 07 Nov 2017 12:23:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- tools/virsh-completer.c | 60 ++++++++++++++++++++++++++++++++++++++++= ++++ tools/virsh-completer.h | 8 ++++++ tools/virsh-domain-monitor.c | 3 +++ tools/virsh-domain.c | 4 +++ 4 files changed, 75 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 4e32b882b..25c3aaa0d 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -29,6 +29,7 @@ #include "internal.h" #include "viralloc.h" #include "virstring.h" +#include "virxml.h" =20 =20 char ** @@ -88,3 +89,62 @@ virshDomainNameCompleter(vshControl *ctl, VIR_FREE(ret); return NULL; } + + +char ** +virshDomainInterfaceCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + xmlDocPtr xmldoc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + int ninterfaces; + xmlNodePtr *interfaces =3D NULL; + size_t i; + unsigned int domainXMLFlags =3D 0; + char **ret =3D NULL; + + virCheckFlags(VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (vshCommandOptBool(cmd, "config")) + domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; + + if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) + goto error; + + ninterfaces =3D virXPathNodeSet("./devices/interface", ctxt, &interfac= es); + if (ninterfaces < 0) + goto error; + + if (VIR_ALLOC_N(ret, ninterfaces + 1) < 0) + goto error; + + for (i =3D 0; i < ninterfaces; i++) { + ctxt->node =3D interfaces[i]; + + if (!(flags & VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC) && + (ret[i] =3D virXPathString("string(./target/@dev)", ctxt))) + continue; + + /* In case we are dealing with inactive domain XML there's no + * . Offer MAC addresses then. */ + if (!(ret[i] =3D virXPathString("string(./mac/@address)", ctxt))) + goto error; + } + + VIR_FREE(interfaces); + xmlFreeDoc(xmldoc); + xmlXPathFreeContext(ctxt); + return ret; + + error: + VIR_FREE(interfaces); + xmlFreeDoc(xmldoc); + xmlXPathFreeContext(ctxt); + virStringListFree(ret); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 288e17909..680cd12ff 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -30,4 +30,12 @@ char ** virshDomainNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +enum { + VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC =3D 1 << 1, /* Return just MACs */ +}; + +char ** virshDomainInterfaceCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index d0edb177d..dd89f0758 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -659,6 +659,7 @@ static const vshCmdOptDef opts_domif_getlink[] =3D { {.name =3D "interface", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D virshDomainInterfaceCompleter, .help =3D N_("interface device (MAC Address)") }, {.name =3D "persistent", @@ -995,6 +996,7 @@ static const vshCmdOptDef opts_domifstat[] =3D { {.name =3D "interface", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D virshDomainInterfaceCompleter, .help =3D N_("interface device") }, {.name =3D NULL} @@ -2149,6 +2151,7 @@ static const vshCmdOptDef opts_domifaddr[] =3D { {.name =3D "interface", .type =3D VSH_OT_STRING, .flags =3D VSH_OFLAG_NONE, + .completer =3D virshDomainInterfaceCompleter, .help =3D N_("network interface name")}, {.name =3D "full", .type =3D VSH_OT_BOOL, diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 101a5f647..f977832aa 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2977,6 +2977,7 @@ static const vshCmdOptDef opts_domif_setlink[] =3D { {.name =3D "interface", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D virshDomainInterfaceCompleter, .help =3D N_("interface device (MAC Address)") }, {.name =3D "state", @@ -3147,6 +3148,7 @@ static const vshCmdOptDef opts_domiftune[] =3D { {.name =3D "interface", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D virshDomainInterfaceCompleter, .help =3D N_("interface device (MAC Address)") }, {.name =3D "inbound", @@ -11983,6 +11985,8 @@ static const vshCmdOptDef opts_detach_interface[] = =3D { }, {.name =3D "mac", .type =3D VSH_OT_STRING, + .completer =3D virshDomainInterfaceCompleter, + .completer_flags =3D VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC, .help =3D N_("MAC address") }, VIRSH_COMMON_OPT_DOMAIN_PERSISTENT, --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 14:26:58 2024 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 1510057413063168.0318209985146; Tue, 7 Nov 2017 04:23:33 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFCE75D9E2; Tue, 7 Nov 2017 12:23:31 +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 8E80560561; Tue, 7 Nov 2017 12:23:31 +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 58E5C3D383; Tue, 7 Nov 2017 12:23:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7CNGvr031715 for ; Tue, 7 Nov 2017 07:23:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id E5CFD5C542; Tue, 7 Nov 2017 12:23:16 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D2705C545 for ; Tue, 7 Nov 2017 12:23:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AFCE75D9E2 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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, 7 Nov 2017 13:22:59 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/11] virt-admin: Introduce vshAdmServerCompleter 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Nov 2017 12:23:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik --- tools/Makefile.am | 9 ++++++ tools/virt-admin-completer.c | 76 ++++++++++++++++++++++++++++++++++++++++= ++++ tools/virt-admin-completer.h | 33 +++++++++++++++++++ tools/virt-admin.c | 8 +++++ 4 files changed, 126 insertions(+) create mode 100644 tools/virt-admin-completer.c create mode 100644 tools/virt-admin-completer.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 8eddc7bbe..a1652d459 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -261,6 +261,15 @@ virt_admin_SOURCES =3D \ virt-admin.c virt-admin.h \ $(NULL) =20 +VIRT_ADMIN_COMPLETER =3D \ + virt-admin-completer.c virt-admin-completer.h + +if WITH_READLINE +virt_admin_SOURCES +=3D $(VIRT_ADMIN_COMPLETER) +else ! WITH_READLINE +EXTRA_DIST +=3D $(VIRT_ADMIN_COMPLETER) +endif ! WITH_READLINE + virt_admin_LDFLAGS =3D \ $(AM_LDFLAGS) \ $(COVERAGE_LDFLAGS) \ diff --git a/tools/virt-admin-completer.c b/tools/virt-admin-completer.c new file mode 100644 index 000000000..2cd471f32 --- /dev/null +++ b/tools/virt-admin-completer.c @@ -0,0 +1,76 @@ +/* + * virt-admin-completer.c: virt-admin completer callbacks + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Michal Privoznik + * + */ + +#include + +#include "virt-admin-completer.h" +#include "internal.h" +#include "virt-admin.h" +#include "viralloc.h" +#include "virstring.h" + + +char ** +vshAdmServerCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + vshAdmControlPtr priv =3D ctl->privData; + virAdmServerPtr *srvs =3D NULL; + int nsrvs =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virAdmConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + /* Obtain a list of available servers on the daemon */ + if ((nsrvs =3D virAdmConnectListServers(priv->conn, &srvs, 0)) < 0) + return NULL; + + if (VIR_ALLOC_N(ret, nsrvs + 1) < 0) + goto error; + + for (i =3D 0; i < nsrvs; i++) { + const char *name =3D virAdmServerGetName(srvs[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virAdmServerFree(srvs[i]); + } + VIR_FREE(srvs); + + return ret; + + error: + for (; i < nsrvs; i++) + virAdmServerFree(srvs[i]); + VIR_FREE(srvs); + for (i =3D 0; i < nsrvs; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + return ret; +} diff --git a/tools/virt-admin-completer.h b/tools/virt-admin-completer.h new file mode 100644 index 000000000..7507b95c1 --- /dev/null +++ b/tools/virt-admin-completer.h @@ -0,0 +1,33 @@ +/* + * virt-admin-completer.h: virt-admin completer callbacks + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Michal Privoznik + * + */ + +#ifndef VIRT_ADMIN_COMPLETER +# define VIRT_ADMIN_COMPLETER + +# include "vsh.h" + +char ** +vshAdmServerCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); +#endif diff --git a/tools/virt-admin.c b/tools/virt-admin.c index c24ed95c0..41b945e49 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -39,6 +39,7 @@ #include "virthread.h" #include "virgettext.h" #include "virtime.h" +#include "virt-admin-completer.h" =20 /* Gnulib doesn't guarantee SA_SIGINFO support. */ #ifndef SA_SIGINFO @@ -432,6 +433,7 @@ static const vshCmdOptDef opts_srv_threadpool_info[] = =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("Server to retrieve threadpool attributes from."), }, {.name =3D NULL} @@ -493,6 +495,7 @@ static const vshCmdOptDef opts_srv_threadpool_set[] =3D= { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("Server to alter threadpool attributes on."), }, {.name =3D "min-workers", @@ -599,6 +602,7 @@ static const vshCmdOptDef opts_srv_clients_list[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("server which to list connected clients from"), }, {.name =3D NULL} @@ -680,6 +684,7 @@ static const vshCmdOptDef opts_client_info[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("server to which is connected to"), }, {.name =3D "client", @@ -767,6 +772,7 @@ static const vshCmdOptDef opts_client_disconnect[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("server which the client is currently connected to"), }, {.name =3D "client", @@ -832,6 +838,7 @@ static const vshCmdOptDef opts_srv_clients_info[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("Server to retrieve the client limits from."), }, {.name =3D NULL} @@ -891,6 +898,7 @@ static const vshCmdOptDef opts_srv_clients_set[] =3D { {.name =3D "server", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D vshAdmServerCompleter, .help =3D N_("Server to alter the client-related configuration limits= on."), }, {.name =3D "max-clients", --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list