shell: creating new module for help functionality
1. Created new shell module: shell_help. 2. Simplified command handlers with new shell print macros. 3. Removed help functions from command handlers. Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
parent
e0be6a10b3
commit
3064ca4f2f
27 changed files with 686 additions and 956 deletions
|
@ -6,6 +6,14 @@
|
|||
#include "shell_utils.h"
|
||||
#include <ctype.h>
|
||||
|
||||
extern const struct shell_cmd_entry __shell_root_cmds_start[0];
|
||||
extern const struct shell_cmd_entry __shell_root_cmds_end[0];
|
||||
|
||||
static inline const struct shell_cmd_entry *shell_root_cmd_get(u32_t id)
|
||||
{
|
||||
return &__shell_root_cmds_start[id];
|
||||
}
|
||||
|
||||
/* Calculates relative line number of given position in buffer */
|
||||
static u32_t line_num_with_buffer_offset_get(struct shell_multiline_cons *cons,
|
||||
u16_t buffer_pos)
|
||||
|
@ -209,6 +217,62 @@ void shell_pattern_remove(char *buff, u16_t *buff_len, const char *pattern)
|
|||
memmove(pattern_addr, pattern_addr + pattern_len, shift);
|
||||
}
|
||||
|
||||
static inline u32_t shell_root_cmd_count(void)
|
||||
{
|
||||
return ((u8_t *)__shell_root_cmds_end -
|
||||
(u8_t *)__shell_root_cmds_start)/
|
||||
sizeof(struct shell_cmd_entry);
|
||||
}
|
||||
|
||||
/* Function returning pointer to root command matching requested syntax. */
|
||||
const struct shell_cmd_entry *root_cmd_find(const char *syntax)
|
||||
{
|
||||
const size_t cmd_count = shell_root_cmd_count();
|
||||
const struct shell_cmd_entry *cmd;
|
||||
|
||||
for (size_t cmd_idx = 0; cmd_idx < cmd_count; ++cmd_idx) {
|
||||
cmd = shell_root_cmd_get(cmd_idx);
|
||||
if (strcmp(syntax, cmd->u.entry->syntax) == 0) {
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void shell_cmd_get(const struct shell_cmd_entry *command, size_t lvl,
|
||||
size_t idx, const struct shell_static_entry **entry,
|
||||
struct shell_static_entry *d_entry)
|
||||
{
|
||||
__ASSERT_NO_MSG(entry != NULL);
|
||||
__ASSERT_NO_MSG(d_entry != NULL);
|
||||
|
||||
if (lvl == SHELL_CMD_ROOT_LVL) {
|
||||
if (idx < shell_root_cmd_count()) {
|
||||
const struct shell_cmd_entry *cmd;
|
||||
|
||||
cmd = shell_root_cmd_get(idx);
|
||||
*entry = cmd->u.entry;
|
||||
} else {
|
||||
*entry = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (command == NULL) {
|
||||
*entry = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (command->is_dynamic) {
|
||||
command->u.dynamic_get(idx, d_entry);
|
||||
*entry = (d_entry->syntax != NULL) ? d_entry : NULL;
|
||||
} else {
|
||||
*entry = (command->u.entry[idx].syntax != NULL) ?
|
||||
&command->u.entry[idx] : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int shell_command_add(char *buff, u16_t *buff_len,
|
||||
const char *new_cmd, const char *pattern)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue