include mode information in help text.
authorZachary T Welch <zw@superlucidity.net>
Sat, 28 Nov 2009 20:42:06 +0000 (12:42 -0800)
committerZachary T Welch <zw@superlucidity.net>
Sat, 28 Nov 2009 21:00:39 +0000 (13:00 -0800)
Extends the help output to list the valid modes for each commands.
Fixes a memory leak of the returned command_name() string.

src/helper/command.c

index 3f439426a1764fba9e977cef3fcc176e6729f04d..4b7d8cb9b4d86f282806a0ab9341eab0f19c7c3a 100644 (file)
@@ -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;
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)