From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsHra-0002A7-Dg for qemu-devel@nongnu.org; Tue, 12 May 2015 17:37:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YsHrX-0004h7-ES for qemu-devel@nongnu.org; Tue, 12 May 2015 17:37:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39173) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsHrW-0004gz-VW for qemu-devel@nongnu.org; Tue, 12 May 2015 17:37:15 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4CLbBQg006451 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 12 May 2015 17:37:12 -0400 From: Bandan Das Date: Tue, 12 May 2015 17:37:09 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH] monitor: print help for command errors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Markus Armbruster , Luiz Capitulino Unlike machines, humans will be (mostly) appreciative on seeing help output when a command fails due to incorrect syntax or input. By default, print output of help_cmd() to the monitor in such cases. The only exceptions are if a command does not exist or parsing failed for some other reason. Before: (qemu) drive_add usb_flash_drive drive_add: string expected After: (qemu) drive_add usb_flash_drive drive_add: string expected Usage: drive_add [[:]:] [file=file][,if=type][,bus=n] [,unit=m][,media=d][,index=i] [,cyls=c,heads=h,secs=s[,trans=t]] [,snapshot=on|off][,cache=on|off] [,readonly=on|off][,copy-on-read=on|off] -- add drive to PCI storage controller Signed-off-by: Bandan Das --- monitor.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/monitor.c b/monitor.c index b2561e1..37f00d9 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, "Usage:\n"); + help_cmd(mon, cmd->name); + } QDECREF(qdict); } -- 2.1.0