summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-28 12:42:06 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-28 13:00:39 -0800
commit42e00bb379fe7591b6d74768a45855ed5cd0c24f (patch)
treef81e450052f69d792ec00a82328a4394ce34df95 /src
parentfd343bea7f11796a9fba77158fe84b0ccaac1a4b (diff)
downloadopenocd+libswd-42e00bb379fe7591b6d74768a45855ed5cd0c24f.tar.gz
openocd+libswd-42e00bb379fe7591b6d74768a45855ed5cd0c24f.tar.bz2
openocd+libswd-42e00bb379fe7591b6d74768a45855ed5cd0c24f.tar.xz
openocd+libswd-42e00bb379fe7591b6d74768a45855ed5cd0c24f.zip
include mode information in help text.
Extends the help output to list the valid modes for each commands. Fixes a memory leak of the returned command_name() string.
Diffstat (limited to 'src')
-rw-r--r--src/helper/command.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/helper/command.c b/src/helper/command.c
index 3f439426..4b7d8cb9 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -862,16 +862,40 @@ static void command_help_show_wrap(const char *str, unsigned n, unsigned n2)
static COMMAND_HELPER(command_help_show, struct command *c, unsigned n,
bool show_help)
{
+ char *cmd_name = command_name(c, ' ');
+ if (NULL == cmd_name)
+ return -ENOMEM;
+
command_help_show_indent(n);
- LOG_USER_N("%s", command_name(c, ' '));
+ LOG_USER_N("%s", cmd_name);
+ free(cmd_name);
+
if (c->usage) {
LOG_USER_N(" ");
command_help_show_wrap(c->usage, 0, n + 5);
}
else
LOG_USER_N("\n");
- if (show_help && c->help)
- command_help_show_wrap(c->help, n + 3, n + 3);
+
+ if (show_help)
+ {
+ const char *stage_msg;
+ switch (c->mode) {
+ case COMMAND_CONFIG: stage_msg = "CONFIG"; break;
+ case COMMAND_EXEC: stage_msg = "EXEC"; break;
+ case COMMAND_ANY: stage_msg = "CONFIG or EXEC"; break;
+ default: stage_msg = "***UNKNOWN***"; break;
+ }
+ char *msg = alloc_printf("%s%sValid Modes: %s",
+ c->help ? : "", c->help ? " " : "", stage_msg);
+ if (NULL != msg)
+ {
+ command_help_show_wrap(msg, n + 3, n + 3);
+ free(msg);
+ } else
+ return -ENOMEM;
+ }
+
if (++n >= 2)
return ERROR_OK;