mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
virsh: Convert '<cmd> --help' to 'help <cmd>'
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.
This commit is contained in:
parent
e7d1bdfbd2
commit
d2f971390e
@ -1189,12 +1189,18 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint32_t *opts_need_arg,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static vshCmdOptDef helpopt = {"help", VSH_OT_BOOL, 0,
|
||||
N_("print help for this function")};
|
||||
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;
|
||||
|
||||
vshCommandOptFree(first);
|
||||
first = vshMalloc(ctl, sizeof(vshCmdOpt));
|
||||
first->def = &(opts_help[0]);
|
||||
first->data = vshStrdup(ctl, cmd->name);
|
||||
first->next = NULL;
|
||||
|
||||
cmd = vshCmddefSearch("help");
|
||||
opts_required = 0;
|
||||
opts_seen = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
c->opts = first;
|
||||
c->def = cmd;
|
||||
|
Loading…
Reference in New Issue
Block a user