allow scripts to update usage information
authorZachary T Welch <zw@superlucidity.net>
Mon, 23 Nov 2009 20:16:27 +0000 (12:16 -0800)
committerZachary T Welch <zw@superlucidity.net>
Wed, 25 Nov 2009 05:37:37 +0000 (21:37 -0800)
The add_usage_text command uses the same C handler, which was updated
to support its new polymorphic role.  This patch updates the two script
commands that needed this support: 'find' and 'script'.

src/helper/command.c
src/helper/startup.tcl

index 3cb36ea27590850c4f18131f10d265604b6af7d4..1263a93142272a5348fe1ced3faacb617dbb41ce 100644 (file)
@@ -951,8 +951,9 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent,
                        return ERROR_FAIL;
                }
                LOG_DEBUG("added '%s' help text", cmd_name);
+               return ERROR_OK;
        }
-       else
+       if (help_text)
        {
                bool replaced = false;
                if (nc->help)
@@ -961,12 +962,25 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent,
                        replaced = true;
                }
                nc->help = strdup(help_text);
-
                if (replaced)
                        LOG_INFO("replaced existing '%s' help", cmd_name);
                else
                        LOG_DEBUG("added '%s' help text", cmd_name);
        }
+       if (usage)
+       {
+               bool replaced = false;
+               if (nc->usage)
+               {
+                       free((void *)nc->usage);
+                       replaced = true;
+               }
+               nc->usage = strdup(usage);
+               if (replaced)
+                       LOG_INFO("replaced existing '%s' usage", cmd_name);
+               else
+                       LOG_DEBUG("added '%s' usage text", cmd_name);
+       }
        return ERROR_OK;
 }
 
@@ -979,7 +993,14 @@ COMMAND_HANDLER(handle_help_add_command)
        }
 
        // save help text and remove it from argument list
-       const char *help_text = CMD_ARGV[--CMD_ARGC];
+       const char *str = CMD_ARGV[--CMD_ARGC];
+       const char *help = !strcmp(CMD_NAME, "add_help_text") ? str : NULL;
+       const char *usage = !strcmp(CMD_NAME, "add_usage_text") ? str : NULL;
+       if (!help && !usage)
+       {
+               LOG_ERROR("command name '%s' is unknown", CMD_NAME);
+               return ERROR_INVALID_ARGUMENTS;
+       }
        // likewise for the leaf command name
        const char *cmd_name = CMD_ARGV[--CMD_ARGC];
 
@@ -991,7 +1012,7 @@ COMMAND_HANDLER(handle_help_add_command)
                if (ERROR_OK != retval)
                        return retval;
        }
-       return help_add_command(CMD_CTX, c, cmd_name, help_text, NULL);
+       return help_add_command(CMD_CTX, c, cmd_name, help, usage);
 }
 
 /* sleep command sleeps for <n> miliseconds
@@ -1038,6 +1059,13 @@ static const struct command_registration command_builtin_handlers[] = {
                .help = "add new command help text",
                .usage = "<command> [...] <help_text>]",
        },
+       {
+               .name = "add_usage_text",
+               .handler = &handle_help_add_command,
+               .mode = COMMAND_ANY,
+               .help = "add new command usage text",
+               .usage = "<command> [...] <usage_text>]",
+       },
        {
                .name = "sleep",
                .handler = &handle_sleep_command,
index ede8cdb9cfd75e03ae549239f998a1905a5ab8ae..5969cfec7a3075d0ec31daca07ace90d08927cb3 100644 (file)
@@ -59,14 +59,15 @@ proc find {filename} {
        # make sure error message matches original input string
        return -code error "Can't find $filename"
 }
-add_help_text find "<file> - print full path to file according to OpenOCD search rules"
+add_usage_text find "<file>"
+add_help_text find "print full path to file according to OpenOCD search rules"
 
 # Run script
 proc script {filename} {
        source [find $filename]
 }
-
-add_help_text script "<filename> - filename of OpenOCD script (tcl) to run"
+add_help_text script "filename of OpenOCD script (tcl) to run"
+add_usage_text script "<file>"
 
 #########
 

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)