All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bandan Das <bsd@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org, Luiz Capitulino <lcapitulino@redhat.com>
Subject: [Qemu-devel] [PATCH] monitor: suggest running "help" for command errors
Date: Wed, 13 May 2015 17:08:05 -0400	[thread overview]
Message-ID: <jpgr3qk9oei.fsf_-_@redhat.com> (raw)
In-Reply-To: <jpgfv70cif5.fsf@redhat.com> (Bandan Das's message of "Wed, 13 May 2015 16:49:02 -0400")


When a command fails due to incorrect syntax or input,
suggest using the "help" command to get more information
about the command. This is only applicable for HMP.

Before:
(qemu) drive_add usb_flash_drive
drive_add: string expected
After:
(qemu) drive_add usb_flash_drive
drive_add: string expected
Try "help drive_add" for more information

Signed-off-by: Bandan Das <bsd@redhat.com>
---
 monitor.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/monitor.c b/monitor.c
index b2561e1..46e8880 100644
--- a/monitor.c
+++ b/monitor.c
@@ -939,7 +939,7 @@ static int qmp_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd,
     return cmd->mhandler.cmd_async(mon, params, qmp_monitor_complete, mon);
 }
 
-static void user_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd,
+static int user_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd,
                                    const QDict *params)
 {
     int ret;
@@ -954,6 +954,8 @@ static void user_async_cmd_handler(Monitor *mon, const mon_cmd_t *cmd,
         monitor_resume(mon);
         g_free(cb_data);
     }
+
+    return ret;
 }
 
 static void hmp_info_help(Monitor *mon, const QDict *qdict)
@@ -3698,7 +3700,8 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                                               const char *cmdline,
                                               int start,
                                               mon_cmd_t *table,
-                                              QDict *qdict)
+                                              QDict *qdict,
+                                              int *failed)
 {
     const char *p, *typestr;
     int c;
@@ -3734,7 +3737,7 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
             return cmd;
         }
         return monitor_parse_command(mon, cmdline, p - cmdline,
-                                     cmd->sub_table, qdict);
+                                     cmd->sub_table, qdict, failed);
     }
 
     /* parse the parameters */
@@ -4084,8 +4087,9 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
     return cmd;
 
 fail:
+    *failed = 1;
     g_free(key);
-    return NULL;
+    return cmd;
 }
 
 void monitor_set_error(Monitor *mon, QError *qerror)
@@ -4114,20 +4118,22 @@ static void handle_user_command(Monitor *mon, const char *cmdline)
 {
     QDict *qdict;
     const mon_cmd_t *cmd;
+    int failed = 0;
 
     qdict = qdict_new();
 
-    cmd = monitor_parse_command(mon, cmdline, 0, mon->cmd_table, qdict);
-    if (!cmd)
+    cmd = monitor_parse_command(mon, cmdline, 0, mon->cmd_table,
+                                qdict, &failed);
+    if (!cmd || failed) {
         goto out;
+    }
 
     if (handler_is_async(cmd)) {
-        user_async_cmd_handler(mon, cmd, qdict);
+        failed = user_async_cmd_handler(mon, cmd, qdict);
     } else if (handler_is_qobject(cmd)) {
         QObject *data = NULL;
 
-        /* XXX: ignores the error code */
-        cmd->mhandler.cmd_new(mon, qdict, &data);
+        failed = cmd->mhandler.cmd_new(mon, qdict, &data);
         assert(!monitor_has_error(mon));
         if (data) {
             cmd->user_print(mon, data);
@@ -4138,6 +4144,10 @@ static void handle_user_command(Monitor *mon, const char *cmdline)
     }
 
 out:
+    if (failed && cmd) {
+        monitor_printf(mon, "Try \"help %s\" for more information\n",
+                       cmd->name);
+    }
     QDECREF(qdict);
 }
 
-- 
2.1.0

  reply	other threads:[~2015-05-13 21:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-12 21:37 [Qemu-devel] [PATCH] monitor: print help for command errors Bandan Das
2015-05-13  7:10 ` Markus Armbruster
2015-05-13 20:49   ` Bandan Das
2015-05-13 21:08     ` Bandan Das [this message]
2015-05-14 11:27       ` [Qemu-devel] [PATCH] monitor: suggest running "help" " Markus Armbruster
2015-05-15  4:37         ` Bandan Das
2015-05-15 11:29           ` Markus Armbruster

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=jpgr3qk9oei.fsf_-_@redhat.com \
    --to=bsd@redhat.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.