qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: <meadori@codesourcery.com>
To: qemu-devel@nongnu.org
Cc: riku.voipio@iki.fi, Meador Inge <meadori@codesourcery.com>
Subject: [Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad options
Date: Mon, 6 Jul 2015 11:03:40 -0700	[thread overview]
Message-ID: <1436205821-20320-4-git-send-email-meadori@codesourcery.com> (raw)
In-Reply-To: <1436205821-20320-1-git-send-email-meadori@codesourcery.com>

From: Meador Inge <meadori@codesourcery.com>

This patch adds better support for diagnosing option
parser errors.  The previous implementation just printed
the usage text and exited when a bad option or argument
was found.  This made it very difficult to determine why
the usage was being displayed and it was doubly confusing
for cases like '--help' (it wasn't clear that --help was
actually an error).

Signed-off-by: Meador Inge <meadori@codesourcery.com>
---
 linux-user/main.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 2922d23..94badfc 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3806,7 +3806,9 @@ static int parse_args(int argc, char **argv)
             if (!strcmp(r, arginfo->argv)) {
                 if (arginfo->has_arg) {
                     if (optind >= argc) {
-                        usage(1);
+                        (void) fprintf(stderr,
+                            "qemu: missing argument for option '%s'\n", r);
+                        exit(1);
                     }
                     arginfo->handle_opt(argv[optind]);
                     optind++;
@@ -3819,12 +3821,14 @@ static int parse_args(int argc, char **argv)
 
         /* no option matched the current argv */
         if (arginfo->handle_opt == NULL) {
-            usage(1);
+            (void) fprintf(stderr, "qemu: unknown option '%s'\n", r);
+            exit(1);
         }
     }
 
     if (optind >= argc) {
-        usage(1);
+        (void) fprintf(stderr, "qemu: no user program specified\n");
+        exit(1);
     }
 
     filename = argv[optind];
-- 
1.8.1.1

  parent reply	other threads:[~2015-07-06 18:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 18:03 [Qemu-devel] [PATCH 0/4] linux-user: CLI cleanup meadori
2015-07-06 18:03 ` [Qemu-devel] [PATCH 1/4] linux-user: Exit 0 when -h is used meadori
2015-07-06 19:43   ` Laurent Vivier
2015-07-08 20:02     ` Meador Inge
2015-07-13 20:08     ` Meador Inge
2015-09-28 13:22       ` Riku Voipio
2015-07-06 18:03 ` [Qemu-devel] [PATCH 2/4] linux-user: Add -help meadori
2015-07-06 18:03 ` meadori [this message]
2015-07-06 18:03 ` [Qemu-devel] [PATCH 4/4] linux-user: Treat --foo options the same as -foo meadori
2015-07-06 19:59 ` [Qemu-devel] [PATCH 0/4] linux-user: CLI cleanup Laurent Vivier
2015-09-28 13:15 ` Riku Voipio
  -- strict thread matches above, loose matches on Subject: below --
2012-03-27 22:44 [Qemu-devel] [PATCH 0/4] linux-user: Option parser cleanup Meador Inge
2012-03-27 22:44 ` [Qemu-devel] [PATCH 3/4] linux-user: Add proper error messages for bad options Meador Inge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436205821-20320-4-git-send-email-meadori@codesourcery.com \
    --to=meadori@codesourcery.com \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).