All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/6] common: command: Expose a generic helper to auto-complete sub commands
Date: Thu, 29 Nov 2018 16:16:17 +0100	[thread overview]
Message-ID: <20181129161617.044db2cd@bbrezillon> (raw)
In-Reply-To: <20181128233921.16675-3-boris.brezillon@bootlin.com>

On Thu, 29 Nov 2018 00:39:17 +0100
Boris Brezillon <boris.brezillon@bootlin.com> wrote:

> Some commands have a table of sub-commands. With a minor adjustments,

						   ^ s/a//

> 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>
> ---
>  common/command.c  | 20 ++++++++++++++++----
>  include/command.h |  3 +++
>  2 files changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/common/command.c b/common/command.c
> index 435824356b50..e13cb47ac18b 100644
> --- a/common/command.c
> +++ b/common/command.c
> @@ -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
> -	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 char *p;
>  	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 */
>  	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) {
>  			cmdv[0] = NULL;
>  			return 0;
> @@ -238,6 +238,18 @@ static int complete_cmdv(int argc, char * const argv[], char last_char, int maxv
>  #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[])
>  {
>  	int argc = 0;
> diff --git a/include/command.h b/include/command.h
> index 200c7a5e9f4e..89efcecfa926 100644
> --- a/include/command.h
> +++ b/include/command.h
> @@ -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[]);
>  cmd_tbl_t *find_cmd(const char *cmd);
>  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);
>  

  parent reply	other threads:[~2018-11-29 15:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28 23:39 [U-Boot] [PATCH v2 0/6] cmd: Simplify support for sub-commands Boris Brezillon
2018-11-28 23:39 ` [U-Boot] [PATCH v2 1/6] common: command: Fix command auto-completion Boris Brezillon
2018-11-29 14:19   ` Tom Rini
2018-11-28 23:39 ` [U-Boot] [PATCH v2 2/6] common: command: Expose a generic helper to auto-complete sub commands Boris Brezillon
2018-11-29 14:19   ` Tom Rini
2018-11-29 15:16   ` Boris Brezillon [this message]
2018-11-28 23:39 ` [U-Boot] [PATCH v2 3/6] common: command: Rework the 'cmd is repeatable' logic Boris Brezillon
2018-11-29 14:19   ` Tom Rini
2018-11-28 23:39 ` [U-Boot] [PATCH v2 4/6] command: commands: Add macros to declare commands with subcmds Boris Brezillon
2018-11-29 14:20   ` Tom Rini
2018-11-29 15:22   ` Boris Brezillon
2018-11-28 23:39 ` [U-Boot] [PATCH v2 5/6] cmd: mtd: Use the subcmd infrastructure to declare mtd sub-commands Boris Brezillon
2018-11-29 14:21   ` Tom Rini
2018-11-28 23:39 ` [U-Boot] [PATCH v2 6/6] cmd: adc: Use the sub-command infrastructure Boris Brezillon
2018-11-29 14:21   ` Tom Rini
2018-11-29 15:26 ` [U-Boot] [PATCH v2 0/6] cmd: Simplify support for sub-commands Boris Brezillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181129161617.044db2cd@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.