[libvirt] [PATCH 2/3] virsh: Convert '<cmd> --help' to 'help <cmd>'
Eric Blake
eblake at redhat.com
Mon Aug 13 17:36:22 UTC 2012
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 at redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120813/3f9b28e2/attachment-0001.sig>
More information about the libvir-list
mailing list