Skip to content

Commit 9de7cb4

Browse files
finikorgfabiobaltieri
authored andcommitted
eeprom: shell: Add device autocompletion support
Add autocompletion for device names. Signed-off-by: Andrei Emeltchenko <[email protected]>
1 parent 41e040a commit 9de7cb4

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

drivers/eeprom/eeprom_shell.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,28 @@ static int cmd_fill(const struct shell *shell, size_t argc, char **argv)
213213
return 0;
214214
}
215215

216+
/* Device name autocompletion support */
217+
static void device_name_get(size_t idx, struct shell_static_entry *entry)
218+
{
219+
const struct device *dev = shell_device_lookup(idx, NULL);
220+
221+
entry->syntax = (dev != NULL) ? dev->name : NULL;
222+
entry->handler = NULL;
223+
entry->help = NULL;
224+
entry->subcmd = NULL;
225+
}
226+
227+
SHELL_DYNAMIC_CMD_CREATE(dsub_device_name, device_name_get);
228+
216229
SHELL_STATIC_SUBCMD_SET_CREATE(eeprom_cmds,
217-
SHELL_CMD_ARG(read, NULL, "<device> <offset> <length>", cmd_read, 4, 0),
218-
SHELL_CMD_ARG(write, NULL,
230+
SHELL_CMD_ARG(read, &dsub_device_name,
231+
"<device> <offset> <length>", cmd_read, 4, 0),
232+
SHELL_CMD_ARG(write, &dsub_device_name,
219233
"<device> <offset> [byte0] <byte1> .. <byteN>", cmd_write,
220234
4, CONFIG_EEPROM_SHELL_BUFFER_SIZE - 1),
221-
SHELL_CMD_ARG(size, NULL, "<device>", cmd_size, 2, 0),
222-
SHELL_CMD_ARG(fill, NULL, "<device> <offset> <length> <pattern>",
223-
cmd_fill, 5, 0),
235+
SHELL_CMD_ARG(size, &dsub_device_name, "<device>", cmd_size, 2, 0),
236+
SHELL_CMD_ARG(fill, &dsub_device_name,
237+
"<device> <offset> <length> <pattern>", cmd_fill, 5, 0),
224238
SHELL_SUBCMD_SET_END
225239
);
226240

0 commit comments

Comments
 (0)