From 12400cdcd69895ef364e0efe57815ce76ea5d6fd Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 23 Jan 2010 16:58:56 +0000 Subject: [PATCH] Automatically show help for a command when it fails with a syntax error git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1703 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 3 +++ urjtag/src/cmd/cmd_cmd.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index e7925d9e..0f8e3932 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -3,6 +3,9 @@ * src/cmd/cmd.h, src/cmd/cmd_list.h, src/cmd/cmd_cmd.c: Unify the list of commands in one place. + * src/cmd/cmd_cmd.c (urj_cmd_run): Automatically show help for a command + when it fails with a syntax error. + 2010-01-22 Mike Frysinger * src/cmd/cmd_bit.c (cmd_bit_print_params): Fix strncat length handling. diff --git a/urjtag/src/cmd/cmd_cmd.c b/urjtag/src/cmd/cmd_cmd.c index ae3a37b2..a849e7a9 100644 --- a/urjtag/src/cmd/cmd_cmd.c +++ b/urjtag/src/cmd/cmd_cmd.c @@ -105,7 +105,13 @@ urj_cmd_run (urj_chain_t *chain, char *params[]) if (strcasecmp (urj_cmds[i]->name, params[0]) == 0) { run_cmd: - return urj_cmds[i]->run (chain, params); + i = urj_cmds[i]->run (chain, params); + if (i != URJ_STATUS_OK && urj_error_get () == URJ_ERROR_SYNTAX) + { + char *help_params[3] = { "help", params[0], NULL }; + urj_cmd_run( chain, help_params ); + } + return i; } else if (strncasecmp (urj_cmds[i]->name, params[0], len) == 0) {