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

Re: [libvirt] PATCH: Bash auto-completion for virsh



On Mon, Jul 14, 2008 at 11:57:07AM +0100, Daniel P. Berrange wrote:
> Everyone[1] seems to be doing funky bash auto-completion for commands these
> days, so I thought I'd make a stab at doing something for virsh.

  heh, I'm a bash user, but never use completion except for filename in the
path ... But fine by me :-)

> First of all I needed the command line help in an easier format to deal
> with, so I've added
> 
>    virsh _complete-command commands|arguments|options
[...]
> diff -r f3413463b3ff src/libvirt.c
> --- a/src/libvirt.c	Sun Jul 13 13:14:50 2008 +0100
> +++ b/src/libvirt.c	Mon Jul 14 11:54:10 2008 +0100
> @@ -37,6 +37,7 @@
>  #include "uuid.h"
>  #include "util.h"
>  #include "test.h"
> +#include "memory.h"
>  #include "xen_unified.h"
>  #include "remote_internal.h"
>  #include "qemu_driver.h"
> @@ -701,7 +702,8 @@
>              int probes = 0;
>              for (i = 0; i < virDriverTabCount; i++) {
>                  if ((virDriverTab[i]->probe != NULL) &&
> -                    ((latest = virDriverTab[i]->probe()) != NULL)) {
> +                    ((latest = virDriverTab[i]->probe()) != NULL) &&
> +                    STRNEQ(latest, "test:///default")) {
>                      probes++;
>  
>                      DEBUG("Probed %s", latest);

  hum, interesting, i see how that could go in the way, okay :-)

[...]
> @@ -355,8 +758,9 @@
>  
>          vshPrint(ctl, "%s", _("Commands:\n\n"));
>          for (def = commands; def->name; def++)
> -            vshPrint(ctl, "    %-15s %s\n", def->name,
> -                     N_(vshCmddefGetInfo(def, "help")));
> +            if (def->name[0] != '_')
> +                vshPrint(ctl, "    %-15s %s\n", def->name,
> +                         N_(vshCmddefGetInfo(def, "help")));
>          return TRUE;
>      }
>      return vshCmddefHelp(ctl, cmdname, FALSE);

  Should we really hide it ?

> @@ -426,7 +830,7 @@
>  };
>  
>  static vshCmdOptDef opts_connect[] = {
> -    {"name",     VSH_OT_DATA, 0, gettext_noop("hypervisor connection URI")},
> +    {"uri",     VSH_OT_DATA, 0, gettext_noop("hypervisor connection URI")},
>      {"readonly", VSH_OT_BOOL, 0, gettext_noop("read-only connection")},
>      {NULL, 0, 0, NULL}
>  };
> @@ -446,7 +850,7 @@
>      }
>  
>      free(ctl->name);
> -    ctl->name = vshStrdup(ctl, vshCommandOptString(cmd, "name", NULL));
> +    ctl->name = vshStrdup(ctl, vshCommandOptString(cmd, "uri", NULL));
>  
>      if (!ro) {
>          ctl->conn = virConnectOpen(ctl->name);
> @@ -1004,7 +1408,7 @@
>  };
>  
>  static vshCmdOptDef opts_start[] = {
> -    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive domain")},
> +    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive domain")},
>      {NULL, 0, 0, NULL}
>  };
>  
> @@ -1017,7 +1421,7 @@
>      if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
>          return FALSE;
>  
> -    if (!(dom = vshCommandOptDomainBy(ctl, cmd, "name", NULL, VSH_BYNAME)))
> +    if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL, VSH_BYNAME)))
>          return FALSE;
>  
>      if (virDomainGetID(dom) != (unsigned int)-1) {
> @@ -2650,7 +3054,7 @@
>  };
>  
>  static vshCmdOptDef opts_network_start[] = {
> -    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive network")},
> +    {"network", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive network")},
>      {NULL, 0, 0, NULL}
>  };
>  
> @@ -2663,7 +3067,7 @@
>      if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
>          return FALSE;
>  
> -    if (!(network = vshCommandOptNetworkBy(ctl, cmd, "name", NULL, VSH_BYNAME)))
> +    if (!(network = vshCommandOptNetworkBy(ctl, cmd, "network", NULL, VSH_BYNAME)))
>           return FALSE;
>  
>      if (virNetworkCreate(network) == 0) {
> @@ -3554,7 +3958,7 @@
>  };
>  
>  static vshCmdOptDef opts_pool_start[] = {
> -    {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive pool")},
> +    {"pool", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive pool")},
>      {NULL, 0, 0, NULL}
>  };
>  
> @@ -3567,7 +3971,7 @@
>      if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
>          return FALSE;
>  
> -    if (!(pool = vshCommandOptPoolBy(ctl, cmd, "name", NULL, VSH_BYNAME)))
> +    if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL, VSH_BYNAME)))
>           return FALSE;
>  
>      if (virStoragePoolCreate(pool, 0) == 0) {

  Hum, this all looks like a bunch of generic bugs no ?


   Just wondering shouldn't the completion be made to work from within
 the virsh shell too ?

  looks fine to me

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/


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