Skip to content

Commit

Permalink
sys/shell: make find_handler() public
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed May 7, 2024
1 parent 5673a88 commit db829ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions sys/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ static inline void shell_run(const shell_command_t *commands,
shell_run_forever(commands, line_buf, len);
}

/**
* @brief Searches for a handler function associated with a command
*
* @param[in] command_list ptr to array of command structs
* @param[in] command the command name to search for
*
* @returns handler function associated with @p command
* NULL if the command could not be found
*/
shell_command_handler_t shell_find_handler(const shell_command_t *command_list,
const char *command);

#ifndef __cplusplus
/**
* @brief Define shell command
Expand Down
10 changes: 5 additions & 5 deletions sys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static enum parse_state escape_toggle(enum parse_state s)
}

static shell_command_handler_t search_commands(const shell_command_t *entry,
char *command)
const char *command)
{
for (; entry->name != NULL; entry++) {
if (strcmp(entry->name, command) == 0) {
Expand All @@ -95,7 +95,7 @@ static shell_command_handler_t search_commands(const shell_command_t *entry,
return NULL;
}

static shell_command_handler_t search_commands_xfa(char *command)
static shell_command_handler_t search_commands_xfa(const char *command)
{
unsigned n = XFA_LEN(shell_command_t*, shell_commands_xfa);

Expand All @@ -108,8 +108,8 @@ static shell_command_handler_t search_commands_xfa(char *command)
return NULL;
}

static shell_command_handler_t find_handler(
const shell_command_t *command_list, char *command)
shell_command_handler_t shell_find_handler(const shell_command_t *command_list,
const char *command)
{
shell_command_handler_t handler = NULL;

Expand Down Expand Up @@ -321,7 +321,7 @@ static void handle_input_line(const shell_command_t *command_list, char *line)
argv[argc] = NULL;

/* then we call the appropriate handler */
shell_command_handler_t handler = find_handler(command_list, argv[0]);
shell_command_handler_t handler = shell_find_handler(command_list, argv[0]);
if (handler != NULL) {
if (IS_USED(MODULE_SHELL_HOOKS)) {
shell_pre_command_hook(argc, argv);
Expand Down

0 comments on commit db829ac

Please sign in to comment.