mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
virsh: distinguish errors between missing argument and wrong option
Specifying ':' to suppress the error messages printed by getopt(). Then, distinguish the two types of errors. Before: # virsh -c virsh: option requires an argument -- 'c' error: unsupported option '-?'. See --help. After: # virsh -c error: option '-c' requires an argument # virsh -x error: unsupported option '-x'. See --help.
This commit is contained in:
parent
f190a636e5
commit
dd71fa110a
@ -2919,7 +2919,7 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
|
|||||||
/* Standard (non-command) options. The leading + ensures that no
|
/* Standard (non-command) options. The leading + ensures that no
|
||||||
* argument reordering takes place, so that command options are
|
* argument reordering takes place, so that command options are
|
||||||
* not confused with top-level virsh options. */
|
* not confused with top-level virsh options. */
|
||||||
while ((arg = getopt_long(argc, argv, "+d:hqtc:vVrl:e:", opt, NULL)) != -1) {
|
while ((arg = getopt_long(argc, argv, "+:d:hqtc:vVrl:e:", opt, NULL)) != -1) {
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case 'd':
|
case 'd':
|
||||||
if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
|
if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
|
||||||
@ -2973,8 +2973,14 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ':':
|
||||||
|
vshError(ctl, _("option '-%c' requires an argument"), optopt);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
case '?':
|
||||||
|
vshError(ctl, _("unsupported option '-%c'. See --help."), optopt);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
default:
|
default:
|
||||||
vshError(ctl, _("unsupported option '-%c'. See --help."), arg);
|
vshError(ctl, _("unknown option"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user