Skip to content

Commit 4275280

Browse files
committed
adapter: simplify command 'adapter list'
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 <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8672 Tested-by: jenkins Reviewed-by: Tomas Vanek <[email protected]>
1 parent 6beb628 commit 4275280

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/jtag/adapter.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,8 @@ COMMAND_HANDLER(handle_adapter_name)
392392
return ERROR_OK;
393393
}
394394

395-
COMMAND_HANDLER(handle_adapter_list_command)
395+
COMMAND_HANDLER(dump_adapter_driver_list)
396396
{
397-
if (strcmp(CMD_NAME, "list") == 0 && CMD_ARGC > 0)
398-
return ERROR_COMMAND_SYNTAX_ERROR;
399-
400-
command_print(CMD, "The following debug adapters are available:");
401397
for (unsigned int i = 0; adapter_drivers[i]; i++) {
402398
const char *name = adapter_drivers[i]->name;
403399
command_print(CMD, "%u: %s", i + 1, name);
@@ -406,6 +402,14 @@ COMMAND_HANDLER(handle_adapter_list_command)
406402
return ERROR_OK;
407403
}
408404

405+
COMMAND_HANDLER(handle_adapter_list_command)
406+
{
407+
if (CMD_ARGC)
408+
return ERROR_COMMAND_SYNTAX_ERROR;
409+
410+
return CALL_COMMAND_HANDLER(dump_adapter_driver_list);
411+
}
412+
409413
COMMAND_HANDLER(handle_adapter_driver_command)
410414
{
411415
int retval;
@@ -440,7 +444,8 @@ COMMAND_HANDLER(handle_adapter_driver_command)
440444
*/
441445
LOG_ERROR("The specified debug interface was not found (%s)",
442446
CMD_ARGV[0]);
443-
CALL_COMMAND_HANDLER(handle_adapter_list_command);
447+
command_print(CMD, "The following adapter drivers are available:");
448+
CALL_COMMAND_HANDLER(dump_adapter_driver_list);
444449
return ERROR_JTAG_INVALID_INTERFACE;
445450
}
446451

0 commit comments

Comments
 (0)