]> www.infradead.org Git - users/borneoa/openocd-next.git/commitdiff
adapter: simplify command 'adapter list'
authorAntonio Borneo <borneo.antonio@gmail.com>
Sat, 30 Nov 2024 23:01:00 +0000 (00:01 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 15 Mar 2025 10:20:47 +0000 (10:20 +0000)
The code of command 'adapter list' is called by command 'adapter
driver' to list the available drivers in case of error.
This dual possible entry points require a conditional check on the
number of command line arguments, reducing the code readability.

Split the command in a simpler code for the command 'adapter list'
that only checks the command line, and move in a common helper the
code that list the drivers.

While there, fix the output and the comments to report 'adapter
driver' instead of 'debug adapters'; we are not parsing the HW to
know which adapter is present.

Change-Id: I17538e86dc4a31a9589d404e49dcc65a29393390
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8672
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/jtag/adapter.c

index db3d3b0fe8b15845e6e86774ccc298520f910a4f..2fcbd609e8fd3538b76d4d5959caadb0b38ebc81 100644 (file)
@@ -392,12 +392,8 @@ COMMAND_HANDLER(handle_adapter_name)
        return ERROR_OK;
 }
 
-COMMAND_HANDLER(handle_adapter_list_command)
+COMMAND_HANDLER(dump_adapter_driver_list)
 {
-       if (strcmp(CMD_NAME, "list") == 0 && CMD_ARGC > 0)
-               return ERROR_COMMAND_SYNTAX_ERROR;
-
-       command_print(CMD, "The following debug adapters are available:");
        for (unsigned int i = 0; adapter_drivers[i]; i++) {
                const char *name = adapter_drivers[i]->name;
                command_print(CMD, "%u: %s", i + 1, name);
@@ -406,6 +402,14 @@ COMMAND_HANDLER(handle_adapter_list_command)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(handle_adapter_list_command)
+{
+       if (CMD_ARGC)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       return CALL_COMMAND_HANDLER(dump_adapter_driver_list);
+}
+
 COMMAND_HANDLER(handle_adapter_driver_command)
 {
        int retval;
@@ -440,7 +444,8 @@ COMMAND_HANDLER(handle_adapter_driver_command)
         */
        LOG_ERROR("The specified debug interface was not found (%s)",
                                CMD_ARGV[0]);
-       CALL_COMMAND_HANDLER(handle_adapter_list_command);
+       command_print(CMD, "The following adapter drivers are available:");
+       CALL_COMMAND_HANDLER(dump_adapter_driver_list);
        return ERROR_JTAG_INVALID_INTERFACE;
 }