Specifying ':' to suppress the error messages printed by getopt().
Then, distinguish the two types of errors.
Before:
virsh: option requires an argument -- 'c'
error: unsupported option '-?'. See --help.
After:
error: option '-c' requires an argument
error: unsupported option '-x'. See --help.
---
tools/virsh.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index f5a01b3..c0e62eb 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2919,7 +2919,7 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
/* Standard (non-command) options. The leading + ensures that no
* argument reordering takes place, so that command options are
* 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) {
case 'd':
if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
@@ -2973,8 +2973,14 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
exit(EXIT_FAILURE);
}
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:
- vshError(ctl, _("unsupported option '-%c'. See --help."),
arg);
+ vshError(ctl, _("unknown option"));
exit(EXIT_FAILURE);
}
}
--
1.7.11.2
Show replies by date
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.
---
tools/virsh.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index f5a01b3..c0e62eb 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2919,7 +2919,7 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
/* Standard (non-command) options. The leading + ensures that no
* argument reordering takes place, so that command options are
* 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) {
case 'd':
if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) {
@@ -2973,8 +2973,14 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
exit(EXIT_FAILURE);
}
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:
- vshError(ctl, _("unsupported option '-%c'. See --help."),
arg);
+ vshError(ctl, _("unknown option"));
exit(EXIT_FAILURE);
}
}
--
1.7.11.2
On 02/19/2013 01:50 AM, Guannan Ren wrote:
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.
ACK.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org
On 02/20/2013 12:33 AM, Eric Blake wrote:
On 02/19/2013 01:50 AM, Guannan Ren wrote:
> 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.
ACK.
Thanks and pushed
Guannan