mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
virsh.c: generate each "virsh help COMMAND"s synopsis
* src/virsh.c: Also, diagnose extra arguments after --help (-h).
This commit is contained in:
parent
62db1b13f7
commit
6f61232852
@ -1,3 +1,8 @@
|
||||
Mon 8 Dec 2008 13:22:06 +0100 Jim Meyering <meyering@redhat.com>
|
||||
|
||||
virsh.c: generate each "virsh help COMMAND"s synopsis
|
||||
* src/virsh.c: Also, diagnose extra arguments after --help (-h).
|
||||
|
||||
Mon Dec 8 12:00:53 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||
|
||||
* qemud/Makefile.am: Fix mixup between _LDFLAGS & _LDADD
|
||||
|
58
src/virsh.c
58
src/virsh.c
@ -224,7 +224,7 @@ static void vshError(vshControl *ctl, int doexit, const char *format, ...)
|
||||
ATTRIBUTE_FORMAT(printf, 3, 4);
|
||||
static int vshInit(vshControl *ctl);
|
||||
static int vshDeinit(vshControl *ctl);
|
||||
static void vshUsage(vshControl *ctl, const char *cmdname);
|
||||
static void vshUsage(void);
|
||||
static void vshOpenLogFile(vshControl *ctl);
|
||||
static void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, va_list ap);
|
||||
static void vshCloseLogFile(vshControl *ctl);
|
||||
@ -233,7 +233,7 @@ static int vshParseArgv(vshControl *ctl, int argc, char **argv);
|
||||
|
||||
static const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info);
|
||||
static const vshCmdDef *vshCmddefSearch(const char *cmdname);
|
||||
static int vshCmddefHelp(vshControl *ctl, const char *name, int withprog);
|
||||
static int vshCmddefHelp(vshControl *ctl, const char *name);
|
||||
|
||||
static vshCmdOpt *vshCommandOpt(const vshCmd *cmd, const char *name);
|
||||
static int vshCommandOptInt(const vshCmd *cmd, const char *name, int *found);
|
||||
@ -361,7 +361,7 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd)
|
||||
N_(vshCmddefGetInfo(def, "help")));
|
||||
return TRUE;
|
||||
}
|
||||
return vshCmddefHelp(ctl, cmdname, FALSE);
|
||||
return vshCmddefHelp(ctl, cmdname);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -5803,7 +5803,7 @@ vshCmddefSearch(const char *cmdname)
|
||||
}
|
||||
|
||||
static int
|
||||
vshCmddefHelp(vshControl *ctl, const char *cmdname, int withprog)
|
||||
vshCmddefHelp(vshControl *ctl, const char *cmdname)
|
||||
{
|
||||
const vshCmdDef *def = vshCmddefSearch(cmdname);
|
||||
|
||||
@ -5811,30 +5811,46 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname, int withprog)
|
||||
vshError(ctl, FALSE, _("command '%s' doesn't exist"), cmdname);
|
||||
return FALSE;
|
||||
} else {
|
||||
const vshCmdOptDef *opt;
|
||||
const char *desc = N_(vshCmddefGetInfo(def, "desc"));
|
||||
const char *help = N_(vshCmddefGetInfo(def, "help"));
|
||||
const char *syntax = vshCmddefGetInfo(def, "syntax");
|
||||
char buf[256];
|
||||
|
||||
fputs(_(" NAME\n"), stdout);
|
||||
fprintf(stdout, " %s - %s\n", def->name, help);
|
||||
|
||||
if (syntax) {
|
||||
fputs(_("\n SYNOPSIS\n"), stdout);
|
||||
if (!withprog)
|
||||
fprintf(stdout, " %s\n", syntax);
|
||||
fprintf(stdout, " %s", def->name);
|
||||
if (def->opts) {
|
||||
const vshCmdOptDef *opt;
|
||||
for (opt = def->opts; opt->name; opt++) {
|
||||
const char *fmt;
|
||||
if (opt->type == VSH_OT_BOOL)
|
||||
fmt = "[--%s]";
|
||||
else if (opt->type == VSH_OT_INT)
|
||||
fmt = N_("[--%s <number>]");
|
||||
else if (opt->type == VSH_OT_STRING)
|
||||
fmt = N_("[--%s <string>]");
|
||||
else if (opt->type == VSH_OT_DATA)
|
||||
fmt = ((opt->flag & VSH_OFLAG_REQ) ? "<%s>" : "[<%s>]");
|
||||
else
|
||||
fprintf(stdout, " %s %s\n", progname, syntax);
|
||||
assert(0);
|
||||
fputc(' ', stdout);
|
||||
fprintf(stdout, _(fmt), opt->name);
|
||||
}
|
||||
if (desc) {
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
|
||||
if (desc[0]) {
|
||||
/* FIXME: remove this test once all of the empty descriptions
|
||||
have been removed; see `FIXME: describe' lines. */
|
||||
fputs(_("\n DESCRIPTION\n"), stdout);
|
||||
fprintf(stdout, " %s\n", desc);
|
||||
}
|
||||
|
||||
if (def->opts) {
|
||||
const vshCmdOptDef *opt;
|
||||
fputs(_("\n OPTIONS\n"), stdout);
|
||||
for (opt = def->opts; opt->name; opt++) {
|
||||
char buf[256];
|
||||
|
||||
if (opt->type == VSH_OT_BOOL)
|
||||
snprintf(buf, sizeof(buf), "--%s", opt->name);
|
||||
else if (opt->type == VSH_OT_INT)
|
||||
@ -6912,12 +6928,9 @@ vshDeinit(vshControl *ctl)
|
||||
* Print usage
|
||||
*/
|
||||
static void
|
||||
vshUsage(vshControl *ctl, const char *cmdname)
|
||||
vshUsage(void)
|
||||
{
|
||||
const vshCmdDef *cmd;
|
||||
|
||||
/* global help */
|
||||
if (!cmdname) {
|
||||
fprintf(stdout, _("\n%s [options] [commands]\n\n"
|
||||
" options:\n"
|
||||
" -c | --connect <uri> hypervisor connection URI\n"
|
||||
@ -6939,9 +6952,6 @@ vshUsage(vshControl *ctl, const char *cmdname)
|
||||
_("\n (specify help <command> for details about the command)\n\n"));
|
||||
return;
|
||||
}
|
||||
if (!vshCmddefHelp(ctl, cmdname, TRUE))
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* argv[]: virsh [options] [command]
|
||||
@ -7038,8 +7048,12 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
|
||||
}
|
||||
|
||||
if (help) {
|
||||
/* global or command specific help */
|
||||
vshUsage(ctl, argc > end ? argv[end] : NULL);
|
||||
if (end < argc)
|
||||
vshError(ctl, TRUE,
|
||||
_("extra argument '%s'. See --help."), argv[end]);
|
||||
|
||||
/* list all command */
|
||||
vshUsage();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user