Re: [PATCH 2/3] virsh: Convert '<cmd> --help' to 'help <cmd>'

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

 



On 08/13/2012 08:28 AM, Cole Robinson wrote:
> Often times I find myself halfway through typing a long command when
> I want to see 'help' output. I instinctively append '--help' to the
> command I'm typing, only to get an error:
> 
>     $ virsh vol-create-as foo --help
>     error: command 'vol-create-as' doesn't support option --help
> 
> This patch makes --help work in a pretty hacky way. One missing piece
> here is that --help isn't listed as an option in the actual 'help <cmd>'
> output, but maybe this can be a starting point for someone.

Love this hack - I too have missed having it.

> ---
>  tools/virsh.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
>  
> +vshCmdOptDef helpopt = {"help", VSH_OT_BOOL, 0,
> +                        N_("print help for this function")};

Mark this static.

>  static const vshCmdOptDef *
>  vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name,
>                     uint32_t *opts_seen, int *opt_index)
>  {
>      int i;
>  
> +    if (STREQ(name, helpopt.name)) {
> +        return &helpopt;
> +    }
> +
>      for (i = 0; cmd->opts && cmd->opts[i].name; i++) {
>          const vshCmdOptDef *opt = &cmd->opts[i];
>  
> @@ -2053,6 +2059,25 @@ get_data:
>          /* command parsed -- allocate new struct for the command */
>          if (cmd) {
>              vshCmd *c = vshMalloc(ctl, sizeof(vshCmd));
> +            vshCmdOpt *tmpopt = first;
> +
> +            /* if we encountered --help, replace parsed command with
> +             * 'help <cmdname>' */
> +            for (tmpopt = first; tmpopt; tmpopt = tmpopt->next) {
> +                if (STRNEQ(tmpopt->def->name, "help"))
> +                    continue;

I tested corner cases like:
virsh echo --help # full help output
virsh echo -- --help # literal '--help'
virsh echo --string --help # literal '--help'

and it appears to match my expectations.

ACK.

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
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]