add 'command type' introspective handler
authorZachary T Welch <zw@superlucidity.net>
Sat, 28 Nov 2009 02:59:14 +0000 (18:59 -0800)
committerZachary T Welch <zw@superlucidity.net>
Sat, 28 Nov 2009 20:58:35 +0000 (12:58 -0800)
Adds the 'command' group handler, with the 'type' command producing
a string that tells whether the given command is 'native' (for Jim-based
command handlers), 'simple' (for simple built-in commands), 'group'
for command group placeholders, and 'unknown' if not found in the
command registration tables (e.g. core built-ins functions).

src/helper/command.c

index 65421f58fbbb4216bdb501563c37fb71d155ad05..23175baf2cda31aab5ee563076a2145731b05b42 100644 (file)
@@ -948,6 +948,31 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
        return script_command_run(interp, count, start, c, found);
 }
 
+static int jim_command_type(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+{
+       if (1 == argc)
+               return JIM_ERR;
+
+       struct command_context *cmd_ctx = current_command_context();
+       struct command *c = cmd_ctx->commands;
+       int remaining = command_unknown_find(argc - 1, argv + 1, c, &c, true);
+       // if nothing could be consumed, then it's an unknown command
+       if (remaining == argc - 1)
+       {
+               Jim_SetResultString(interp, "unknown", -1);
+               return JIM_OK;
+       }
+
+       if (c->jim_handler)
+               Jim_SetResultString(interp, "native", -1);
+       else if (c->handler)
+               Jim_SetResultString(interp, "simple", -1);
+       else
+               Jim_SetResultString(interp, "group", -1);
+
+       return JIM_OK;
+}
+
 int help_add_command(struct command_context *cmd_ctx, struct command *parent,
                const char *cmd_name, const char *help_text, const char *usage)
 {
@@ -1069,6 +1094,18 @@ COMMAND_HANDLER(handle_sleep_command)
        return ERROR_OK;
 }
 
+static const struct command_registration command_subcommand_handlers[] = {
+       {
+               .name = "type",
+               .mode = COMMAND_ANY,
+               .jim_handler = &jim_command_type,
+               .usage = "<name> ...",
+               .help = "Returns the type of built-in command:"
+                       "'native', 'simple', 'group', or 'unknown'",
+       },
+       COMMAND_REGISTRATION_DONE
+};
+
 static const struct command_registration command_builtin_handlers[] = {
        {
                .name = "add_help_text",
@@ -1106,6 +1143,12 @@ static const struct command_registration command_builtin_handlers[] = {
                .help = "show basic command usage",
                .usage = "[<command> ...]",
        },
+       {
+               .name = "command",
+               .mode= COMMAND_ANY,
+               .help = "core command group (introspection)",
+               .chain = command_subcommand_handlers,
+       },
        COMMAND_REGISTRATION_DONE
 };
 

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)