mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-09-27 15:10:26 +09:00
common: command: Expose a generic helper to auto-complete sub commands
Some commands have a table of sub-commands. With minor adjustments, complete_cmdv() is able to provide auto-completion for sub-commands (it's just about passing the table of commands instead of taking the global one). We rename this function into complete_subcmd() and implement complete_cmdv() as a wrapper around complete_subcmdv(). Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com> Reviewed-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
parent
cbe07ebeaf
commit
6fb61445bb
@ -161,11 +161,11 @@ int var_complete(int argc, char * const argv[], char last_char, int maxv, char *
|
|||||||
|
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv, char *cmdv[])
|
int complete_subcmdv(cmd_tbl_t *cmdtp, int count, int argc,
|
||||||
|
char * const argv[], char last_char,
|
||||||
|
int maxv, char *cmdv[])
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_CMDLINE
|
#ifdef CONFIG_CMDLINE
|
||||||
cmd_tbl_t *cmdtp = ll_entry_start(cmd_tbl_t, cmd);
|
|
||||||
const int count = ll_entry_count(cmd_tbl_t, cmd);
|
|
||||||
const cmd_tbl_t *cmdend = cmdtp + count;
|
const cmd_tbl_t *cmdend = cmdtp + count;
|
||||||
const char *p;
|
const char *p;
|
||||||
int len, clen;
|
int len, clen;
|
||||||
@ -193,7 +193,7 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv
|
|||||||
|
|
||||||
/* more than one arg or one but the start of the next */
|
/* more than one arg or one but the start of the next */
|
||||||
if (argc > 1 || last_char == '\0' || isblank(last_char)) {
|
if (argc > 1 || last_char == '\0' || isblank(last_char)) {
|
||||||
cmdtp = find_cmd(argv[0]);
|
cmdtp = find_cmd_tbl(argv[0], cmdtp, count);
|
||||||
if (cmdtp == NULL || cmdtp->complete == NULL) {
|
if (cmdtp == NULL || cmdtp->complete == NULL) {
|
||||||
cmdv[0] = NULL;
|
cmdv[0] = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
@ -238,6 +238,18 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int complete_cmdv(int argc, char * const argv[], char last_char,
|
||||||
|
int maxv, char *cmdv[])
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_CMDLINE
|
||||||
|
return complete_subcmdv(ll_entry_start(cmd_tbl_t, cmd),
|
||||||
|
ll_entry_count(cmd_tbl_t, cmd), argc, argv,
|
||||||
|
last_char, maxv, cmdv);
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static int make_argv(char *s, int argvsz, char *argv[])
|
static int make_argv(char *s, int argvsz, char *argv[])
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -54,6 +54,9 @@ int _do_help (cmd_tbl_t *cmd_start, int cmd_items, cmd_tbl_t * cmdtp, int
|
|||||||
flag, int argc, char * const argv[]);
|
flag, int argc, char * const argv[]);
|
||||||
cmd_tbl_t *find_cmd(const char *cmd);
|
cmd_tbl_t *find_cmd(const char *cmd);
|
||||||
cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
|
cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len);
|
||||||
|
int complete_subcmdv(cmd_tbl_t *cmdtp, int count, int argc,
|
||||||
|
char * const argv[], char last_char, int maxv,
|
||||||
|
char *cmdv[]);
|
||||||
|
|
||||||
extern int cmd_usage(const cmd_tbl_t *cmdtp);
|
extern int cmd_usage(const cmd_tbl_t *cmdtp);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user