[v4 3/5] virsh: Add vshDomainCompleter

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

 



Function vshDomainCompler returns domains names which can be used
by various virsh commands, for example:

 virsh # start --domain <TAB>
  fedora      domain_foo    domain_bar

---
v2
* global variable __my_conn renamed to vshConn
* @name is now const char *
* label cleanup renamed to error

v3
* removed useless if
* used virStringFreeList() instead of iteration
* added vshControl *vshCtl instead of virConnectPtr *vshConn because
  vshCtl is needed in order to call vshReconnect()
* moved all .completer = vshDomainCompleter initializations from
  other patches into this

v4
* vshControl *vshCtl marked static
* changed vshMalloc to VIR_ALLOC_N
* fixed link error if building without USE_READLINE
* fixed @domains[] mem leak
* vshDomainCompleter .completer and .completer_flags initializers are
  now only in cmdOptDef
* reconnecting now takes place in the vshReadlineOptionsGenerator()
  and only just before auto-completion happens

 tools/virsh-domain-monitor.c |  52 ++++++--
 tools/virsh-domain.c         | 301 +++++++++++++++++++++++++++++++++----------
 tools/virsh-snapshot.c       |  50 +++++--
 tools/virsh.c                |  55 ++++++++
 tools/virsh.h                |   2 +
 5 files changed, 373 insertions(+), 87 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index b29b82a..f00cdfa 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -310,7 +310,9 @@ static const vshCmdOptDef opts_dommemstat[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "period",
      .type = VSH_OT_DATA,
@@ -434,7 +436,10 @@ static const vshCmdOptDef opts_domblkinfo[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "device",
      .type = VSH_OT_DATA,
@@ -489,7 +494,10 @@ static const vshCmdOptDef opts_domblklist[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "inactive",
      .type = VSH_OT_BOOL,
@@ -603,7 +611,10 @@ static const vshCmdOptDef opts_domiflist[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "inactive",
      .type = VSH_OT_BOOL,
@@ -708,7 +719,10 @@ static const vshCmdOptDef opts_domif_getlink[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "interface",
      .type = VSH_OT_DATA,
@@ -823,7 +837,9 @@ static const vshCmdOptDef opts_domcontrol[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -876,7 +892,10 @@ static const vshCmdOptDef opts_domblkstat[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_RUNNING
     },
     {.name = "device",
      .type = VSH_OT_DATA,
@@ -1059,7 +1078,10 @@ static const vshCmdOptDef opts_domifstat[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_RUNNING
     },
     {.name = "interface",
      .type = VSH_OT_DATA,
@@ -1136,7 +1158,9 @@ static const vshCmdOptDef opts_domblkerror[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id, or uuid")
+     .help = N_("domain name, id, or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -1201,7 +1225,10 @@ static const vshCmdOptDef opts_dominfo[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = NULL}
 };
@@ -1343,7 +1370,10 @@ static const vshCmdOptDef opts_domstate[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "reason",
      .type = VSH_OT_BOOL,
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 74feca1..7747446 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -165,7 +165,8 @@ static const vshCmdOptDef opts_attach_device[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "file",
      .type = VSH_OT_DATA,
@@ -267,7 +268,9 @@ static const vshCmdOptDef opts_attach_disk[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "source",
      .type = VSH_OT_DATA,
@@ -708,7 +711,9 @@ static const vshCmdOptDef opts_attach_interface[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "type",
      .type = VSH_OT_DATA,
@@ -962,7 +967,10 @@ static const vshCmdOptDef opts_autostart[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "disable",
      .type = VSH_OT_BOOL,
@@ -1018,7 +1026,10 @@ static const vshCmdOptDef opts_blkdeviotune[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "device",
      .type = VSH_OT_DATA,
@@ -1242,7 +1253,10 @@ static const vshCmdOptDef opts_blkiotune[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "weight",
      .type = VSH_OT_INT,
@@ -1505,7 +1519,10 @@ static const vshCmdOptDef opts_block_commit[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "path",
      .type = VSH_OT_DATA,
@@ -1680,7 +1697,10 @@ static const vshCmdOptDef opts_block_copy[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "path",
      .type = VSH_OT_DATA,
@@ -1886,7 +1906,9 @@ static const vshCmdOptDef opts_block_job[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "path",
      .type = VSH_OT_DATA,
@@ -1984,7 +2006,9 @@ static const vshCmdOptDef opts_block_pull[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "path",
      .type = VSH_OT_DATA,
@@ -2150,7 +2174,9 @@ static const vshCmdOptDef opts_block_resize[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "path",
      .type = VSH_OT_DATA,
@@ -2220,7 +2246,10 @@ static const vshCmdOptDef opts_console[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "devname",
      .type = VSH_OT_STRING,
@@ -2317,7 +2346,10 @@ static const vshCmdOptDef opts_domif_setlink[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "interface",
      .type = VSH_OT_DATA,
@@ -2511,7 +2543,10 @@ static const vshCmdOptDef opts_domiftune[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "interface",
      .type = VSH_OT_DATA,
@@ -2698,7 +2733,9 @@ static const vshCmdOptDef opts_suspend[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -2744,7 +2781,10 @@ static const vshCmdOptDef opts_dom_pm_suspend[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_RUNNING
     },
     {.name = "duration",
      .type = VSH_OT_INT,
@@ -2828,7 +2868,9 @@ static const vshCmdOptDef opts_dom_pm_wakeup[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -2877,7 +2919,10 @@ static const vshCmdOptDef opts_undefine[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name or uuid")
+     .help = N_("domain name or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "managed-save",
      .type = VSH_OT_BOOL,
@@ -3238,7 +3283,10 @@ static const vshCmdOptDef opts_start[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("name of the inactive domain")
+     .help = N_("name of the inactive domain"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_PERSISTENT
     },
 #ifndef WIN32
     {.name = "console",
@@ -3422,7 +3470,9 @@ static const vshCmdOptDef opts_save[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "file",
      .type = VSH_OT_DATA,
@@ -3886,7 +3936,11 @@ static const vshCmdOptDef opts_managedsave[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_RUNNING |
+                        VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE
     },
     {.name = "running",
      .type = VSH_OT_BOOL,
@@ -4006,7 +4060,10 @@ static const vshCmdOptDef opts_managedsaveremove[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE
     },
     {.name = NULL}
 };
@@ -4065,7 +4122,10 @@ static const vshCmdOptDef opts_schedinfo[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "weight",
      .type = VSH_OT_INT,
@@ -4408,7 +4468,9 @@ static const vshCmdOptDef opts_dump[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "file",
      .type = VSH_OT_DATA,
@@ -4538,7 +4600,8 @@ static const vshCmdOptDef opts_screenshot[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "file",
      .type = VSH_OT_DATA,
@@ -4685,7 +4748,10 @@ static const vshCmdOptDef opts_resume[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_PAUSED
     },
     {.name = NULL}
 };
@@ -4728,7 +4794,9 @@ static const vshCmdOptDef opts_shutdown[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "mode",
      .type = VSH_OT_STRING,
@@ -4814,7 +4882,9 @@ static const vshCmdOptDef opts_reboot[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "mode",
      .type = VSH_OT_STRING,
@@ -4895,7 +4965,9 @@ static const vshCmdOptDef opts_reset[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -4938,7 +5010,9 @@ static const vshCmdOptDef opts_domjobinfo[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -5150,7 +5224,9 @@ static const vshCmdOptDef opts_domjobabort[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -5226,7 +5302,10 @@ static const vshCmdOptDef opts_vcpucount[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "maximum",
      .type = VSH_OT_BOOL,
@@ -5436,7 +5515,10 @@ static const vshCmdOptDef opts_vcpuinfo[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = NULL}
 };
@@ -5545,7 +5627,10 @@ static const vshCmdOptDef opts_vcpupin[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "vcpu",
      .type = VSH_OT_INT,
@@ -5832,7 +5917,10 @@ static const vshCmdOptDef opts_emulatorpin[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "cpulist",
      .type = VSH_OT_DATA,
@@ -5951,7 +6039,9 @@ static const vshCmdOptDef opts_setvcpus[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "count",
      .type = VSH_OT_INT,
@@ -6289,7 +6379,9 @@ static const vshCmdOptDef opts_cpu_stats[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "total",
      .type = VSH_OT_BOOL,
@@ -6620,7 +6712,9 @@ static const vshCmdOptDef opts_destroy[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "graceful",
      .type = VSH_OT_BOOL,
@@ -6677,7 +6771,10 @@ static const vshCmdOptDef opts_desc[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "live",
      .type = VSH_OT_BOOL,
@@ -6851,7 +6948,9 @@ static const vshCmdOptDef opts_inject_nmi[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -6889,7 +6988,9 @@ static const vshCmdOptDef opts_send_key[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "codeset",
      .type = VSH_OT_STRING,
@@ -6991,7 +7092,9 @@ static const vshCmdOptDef opts_send_process_signal[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "pid",
      .type = VSH_OT_DATA,
@@ -7106,7 +7209,9 @@ static const vshCmdOptDef opts_setmem[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "kilobytes",
      .type = VSH_OT_ALIAS,
@@ -7203,7 +7308,9 @@ static const vshCmdOptDef opts_setmaxmem[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "kilobytes",
      .type = VSH_OT_ALIAS,
@@ -7305,7 +7412,10 @@ static const vshCmdOptDef opts_memtune[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "hard-limit",
      .type = VSH_OT_INT,
@@ -7504,7 +7614,10 @@ static const vshCmdOptDef opts_numatune[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "mode",
      .type = VSH_OT_DATA,
@@ -7651,7 +7764,10 @@ static const vshCmdOptDef opts_qemu_monitor_command[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "hmp",
      .type = VSH_OT_BOOL,
@@ -7801,7 +7917,10 @@ static const vshCmdOptDef opts_qemu_agent_command[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "timeout",
      .type = VSH_OT_INT,
@@ -7930,7 +8049,10 @@ static const vshCmdOptDef opts_lxc_enter_namespace[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "noseclabel",
      .type = VSH_OT_BOOL,
@@ -8068,7 +8190,10 @@ static const vshCmdOptDef opts_dumpxml[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "inactive",
      .type = VSH_OT_BOOL,
@@ -8290,7 +8415,10 @@ static const vshCmdOptDef opts_domid[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name or uuid")
+     .help = N_("domain name or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = NULL}
 };
@@ -8331,7 +8459,10 @@ static const vshCmdOptDef opts_domuuid[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain id or name")
+     .help = N_("domain id or name"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = NULL}
 };
@@ -8703,7 +8834,10 @@ static const vshCmdOptDef opts_migrate_setmaxdowntime[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "downtime",
      .type = VSH_OT_INT,
@@ -8757,7 +8891,9 @@ static const vshCmdOptDef opts_migrate_compcache[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "size",
      .type = VSH_OT_INT,
@@ -8819,7 +8955,10 @@ static const vshCmdOptDef opts_migrate_setspeed[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "bandwidth",
      .type = VSH_OT_INT,
@@ -8871,7 +9010,10 @@ static const vshCmdOptDef opts_migrate_getspeed[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = NULL}
 };
@@ -8915,7 +9057,10 @@ static const vshCmdOptDef opts_domdisplay[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "include-password",
      .type = VSH_OT_BOOL,
@@ -9093,7 +9238,9 @@ static const vshCmdOptDef opts_vncdisplay[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -9166,7 +9313,9 @@ static const vshCmdOptDef opts_ttyconsole[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = NULL}
 };
@@ -9226,7 +9375,10 @@ static const vshCmdOptDef opts_domhostname[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = NULL}
 };
@@ -9389,7 +9541,9 @@ static const vshCmdOptDef opts_detach_device[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE
     },
     {.name = "file",
      .type = VSH_OT_DATA,
@@ -9490,7 +9644,10 @@ static const vshCmdOptDef opts_update_device[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "file",
      .type = VSH_OT_DATA,
@@ -9592,7 +9749,10 @@ static const vshCmdOptDef opts_detach_interface[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "type",
      .type = VSH_OT_DATA,
@@ -9993,7 +10153,10 @@ static const vshCmdOptDef opts_detach_disk[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "target",
      .type = VSH_OT_DATA,
@@ -10103,7 +10266,10 @@ static const vshCmdOptDef opts_edit[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = NULL}
 };
@@ -10163,7 +10329,10 @@ static const vshCmdOptDef opts_change_media[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "path",
      .type = VSH_OT_DATA,
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index e37a5b3..3f13c7b 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -125,7 +125,10 @@ static const vshCmdOptDef opts_snapshot_create[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "xmlfile",
      .type = VSH_OT_DATA,
@@ -328,7 +331,10 @@ static const vshCmdOptDef opts_snapshot_create_as[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "name",
      .type = VSH_OT_DATA,
@@ -520,7 +526,10 @@ static const vshCmdOptDef opts_snapshot_edit[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "snapshotname",
      .type = VSH_OT_DATA,
@@ -642,7 +651,10 @@ static const vshCmdOptDef opts_snapshot_current[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "name",
      .type = VSH_OT_BOOL,
@@ -878,7 +890,10 @@ static const vshCmdOptDef opts_snapshot_info[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "snapshotname",
      .type = VSH_OT_DATA,
@@ -1435,7 +1450,10 @@ static const vshCmdOptDef opts_snapshot_list[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "parent",
      .type = VSH_OT_BOOL,
@@ -1699,7 +1717,10 @@ static const vshCmdOptDef opts_snapshot_dumpxml[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "snapshotname",
      .type = VSH_OT_DATA,
@@ -1767,7 +1788,10 @@ static const vshCmdOptDef opts_snapshot_parent[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "snapshotname",
      .type = VSH_OT_DATA,
@@ -1835,7 +1859,10 @@ static const vshCmdOptDef opts_snapshot_revert[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "snapshotname",
      .type = VSH_OT_DATA,
@@ -1928,7 +1955,10 @@ static const vshCmdOptDef opts_snapshot_delete[] = {
     {.name = "domain",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
-     .help = N_("domain name, id or uuid")
+     .help = N_("domain name, id or uuid"),
+     .completer = vshDomainCompleter,
+     .completer_flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                        VIR_CONNECT_LIST_DOMAINS_INACTIVE
     },
     {.name = "snapshotname",
      .type = VSH_OT_DATA,
diff --git a/tools/virsh.c b/tools/virsh.c
index 321ed5d..271c841 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -89,6 +89,8 @@ static char *progname;
 
 static const vshCmdGrp cmdGroups[];
 
+static vshControl *vshCtl;
+
 /* Bypass header poison */
 #undef strdup
 
@@ -2580,6 +2582,54 @@ vshCloseLogFile(vshControl *ctl)
     }
 }
 
+/* -------------
+ * Completers
+ * -------------
+ */
+
+char **
+vshDomainCompleter(unsigned int completer_flags ATTRIBUTE_UNUSED)
+{
+#ifdef USE_READLINE
+    virDomainPtr *domains;
+    size_t i;
+    char **names = NULL;
+    int ndomains;
+
+    if (!vshCtl->conn)
+        return NULL;
+
+    ndomains = virConnectListAllDomains(vshCtl->conn, &domains, completer_flags);
+
+    if (ndomains < 0)
+        return NULL;
+
+    if (VIR_ALLOC_N(names, ndomains + 1) < 0)
+        return NULL;
+
+    for (i = 0; i < ndomains; i++) {
+        const char *name = virDomainGetName(domains[i]);
+        if (VIR_STRDUP(names[i], name) < 0) {
+            virDomainFree(domains[i]);
+            goto error;
+        }
+        virDomainFree(domains[i]);
+    }
+    names[i] = NULL;
+    VIR_FREE(domains);
+    return names;
+
+error:
+    virStringFreeList(names);
+    for (i = i+1; i < ndomains; i++)
+        virDomainFree(domains[i]);
+    VIR_FREE(domains);
+    return NULL;
+#else
+    return NULL;
+#endif
+}
+
 #ifdef USE_READLINE
 
 /* -----------------
@@ -2769,6 +2819,10 @@ vshReadlineOptionsGenerator(const char *text, int state)
     if (!cmd)
         return NULL;
 
+    if ((vshCtl->conn == NULL || disconnected) &&
+        !(cmd->flags & VSH_CMD_FLAG_NOCONNECT))
+        vshReconnect(vshCtl);
+
     if (!cmd->opts)
         return NULL;
 
@@ -3460,6 +3514,7 @@ main(int argc, char **argv)
     ctl->debug = VSH_DEBUG_DEFAULT;
     ctl->escapeChar = "^]";     /* Same default as telnet */
 
+    vshCtl = ctl;
 
     if (!setlocale(LC_ALL, "")) {
         perror("setlocale");
diff --git a/tools/virsh.h b/tools/virsh.h
index f978d94..845fc17 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -258,6 +258,8 @@ struct _vshCmdGrp {
     const vshCmdDef *commands;
 };
 
+char **vshDomainCompleter(unsigned int flags);
+
 void vshError(vshControl *ctl, const char *format, ...)
     ATTRIBUTE_FMT_PRINTF(2, 3);
 void vshOpenLogFile(vshControl *ctl);
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]