mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
vshCmddefHelp: Refactor and fix printing of help for _STRING/_INT arguments
Use the new flags to do the decisions which will also fix the case when an _INT option is required but non-positional. This fixes the help for the 'timeout' argument of 'daemon-timeout' virt-admin command: SYNOPSIS - daemon-timeout <timeout> + daemon-timeout --timeout <number> [...] OPTIONS - [--timeout] <number> number of seconds the daemon will run without any active connection + --timeout <number> number of seconds the daemon will run without any active connection Resolves: https://issues.redhat.com/browse/RHEL-25993 Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
e177b0fca6
commit
36132ff984
42
tools/vsh.c
42
tools/vsh.c
@ -642,31 +642,33 @@ vshCmddefHelp(const vshCmdDef *def)
|
|||||||
if (def->opts) {
|
if (def->opts) {
|
||||||
const vshCmdOptDef *opt;
|
const vshCmdOptDef *opt;
|
||||||
for (opt = def->opts; opt->name; opt++) {
|
for (opt = def->opts; opt->name; opt++) {
|
||||||
bool required_option = opt->flags & VSH_OFLAG_REQ;
|
|
||||||
|
|
||||||
switch (opt->type) {
|
switch (opt->type) {
|
||||||
case VSH_OT_BOOL:
|
case VSH_OT_BOOL:
|
||||||
fprintf(stdout, " [--%s]", opt->name);
|
fprintf(stdout, " [--%s]", opt->name);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VSH_OT_INT:
|
|
||||||
if (required_option) {
|
|
||||||
fprintf(stdout, " <%s>", opt->name);
|
|
||||||
} else {
|
|
||||||
fprintf(stdout, _(" [--%1$s <number>]"), opt->name);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VSH_OT_STRING:
|
case VSH_OT_STRING:
|
||||||
fprintf(stdout, _(" [--%1$s <string>]"), opt->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VSH_OT_DATA:
|
case VSH_OT_DATA:
|
||||||
if (required_option) {
|
case VSH_OT_INT:
|
||||||
fprintf(stdout, " <%s>", opt->name);
|
if (opt->required) {
|
||||||
|
fprintf(stdout, " ");
|
||||||
} else {
|
} else {
|
||||||
fprintf(stdout, " [<%s>]", opt->name);
|
fprintf(stdout, " [");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opt->positional) {
|
||||||
|
fprintf(stdout, "<%s>", opt->name);
|
||||||
|
} else {
|
||||||
|
if (opt->type == VSH_OT_INT) {
|
||||||
|
fprintf(stdout, _("--%1$s <number>"), opt->name);
|
||||||
|
} else {
|
||||||
|
fprintf(stdout, _("--%1$s <string>"), opt->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!opt->required)
|
||||||
|
fprintf(stdout, "]");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VSH_OT_ARGV:
|
case VSH_OT_ARGV:
|
||||||
@ -704,7 +706,6 @@ vshCmddefHelp(const vshCmdDef *def)
|
|||||||
const vshCmdOptDef *opt;
|
const vshCmdOptDef *opt;
|
||||||
fputs(_("\n OPTIONS\n"), stdout);
|
fputs(_("\n OPTIONS\n"), stdout);
|
||||||
for (opt = def->opts; opt->name; opt++) {
|
for (opt = def->opts; opt->name; opt++) {
|
||||||
bool required_option = opt->flags & VSH_OFLAG_REQ;
|
|
||||||
g_autofree char *optstr = NULL;
|
g_autofree char *optstr = NULL;
|
||||||
|
|
||||||
switch (opt->type) {
|
switch (opt->type) {
|
||||||
@ -713,7 +714,7 @@ vshCmddefHelp(const vshCmdDef *def)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VSH_OT_INT:
|
case VSH_OT_INT:
|
||||||
if (required_option) {
|
if (opt->positional) {
|
||||||
optstr = g_strdup_printf(_("[--%1$s] <number>"), opt->name);
|
optstr = g_strdup_printf(_("[--%1$s] <number>"), opt->name);
|
||||||
} else {
|
} else {
|
||||||
optstr = g_strdup_printf(_("--%1$s <number>"), opt->name);
|
optstr = g_strdup_printf(_("--%1$s <number>"), opt->name);
|
||||||
@ -721,11 +722,12 @@ vshCmddefHelp(const vshCmdDef *def)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VSH_OT_STRING:
|
case VSH_OT_STRING:
|
||||||
optstr = g_strdup_printf(_("--%1$s <string>"), opt->name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VSH_OT_DATA:
|
case VSH_OT_DATA:
|
||||||
|
if (opt->positional) {
|
||||||
optstr = g_strdup_printf(_("[--%1$s] <string>"), opt->name);
|
optstr = g_strdup_printf(_("[--%1$s] <string>"), opt->name);
|
||||||
|
} else {
|
||||||
|
optstr = g_strdup_printf(_("--%1$s <string>"), opt->name);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VSH_OT_ARGV:
|
case VSH_OT_ARGV:
|
||||||
|
Loading…
Reference in New Issue
Block a user