mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-19 20:27:01 +00:00
MINOR: cli: sort the output of the "help" keywords
It's still very difficult to find all commands starting with a given keyword like "set", "show" etc. Let's sort the lines by usage message, this is much more convenient.
This commit is contained in:
parent
0b1b830e88
commit
92fbbcc4c6
@ -44,6 +44,7 @@
|
||||
|
||||
#define CLI_PREFIX_KW_NB 5
|
||||
#define CLI_MAX_MATCHES 5
|
||||
#define CLI_MAX_HELP_ENTRIES 1024
|
||||
|
||||
/* CLI states */
|
||||
enum {
|
||||
|
22
src/cli.c
22
src/cli.c
@ -84,12 +84,21 @@ extern const char *stat_status_codes[];
|
||||
|
||||
struct proxy *mworker_proxy; /* CLI proxy of the master */
|
||||
|
||||
static int cmp_kw_entries(const void *a, const void *b)
|
||||
{
|
||||
const struct cli_kw *l = *(const struct cli_kw **)a;
|
||||
const struct cli_kw *r = *(const struct cli_kw **)b;
|
||||
|
||||
return strcmp(l->usage ? l->usage : "", r->usage ? r->usage : "");
|
||||
}
|
||||
|
||||
/* This will show the help message and list the commands supported at the
|
||||
* current level that match all of the first words of <args> if args is not
|
||||
* NULL, or all args if none matches or if args is null.
|
||||
*/
|
||||
static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
|
||||
{
|
||||
struct cli_kw *entries[CLI_MAX_HELP_ENTRIES];
|
||||
struct cli_kw_list *kw_list;
|
||||
struct cli_kw *kw;
|
||||
struct buffer *tmp = get_trash_chunk();
|
||||
@ -98,6 +107,7 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
|
||||
int idx;
|
||||
int ishelp = 0;
|
||||
int length = 0;
|
||||
int help_entries = 0;
|
||||
|
||||
ha_free(&dynamic_usage_msg);
|
||||
|
||||
@ -220,7 +230,8 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
|
||||
if (matches[idx].dist > 5*matches[0].dist/2)
|
||||
break;
|
||||
|
||||
chunk_appendf(tmp, " %s\n", kw->usage);
|
||||
if (help_entries < CLI_MAX_HELP_ENTRIES)
|
||||
entries[help_entries++] = kw;
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,11 +264,16 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
|
||||
break;
|
||||
}
|
||||
|
||||
if (kw->usage && idx == length)
|
||||
chunk_appendf(tmp, " %s\n", kw->usage);
|
||||
if (kw->usage && idx == length && help_entries < CLI_MAX_HELP_ENTRIES)
|
||||
entries[help_entries++] = kw;
|
||||
}
|
||||
}
|
||||
|
||||
qsort(entries, help_entries, sizeof(*entries), cmp_kw_entries);
|
||||
|
||||
for (idx = 0; idx < help_entries; idx++)
|
||||
chunk_appendf(tmp, " %s\n", entries[idx]->usage);
|
||||
|
||||
/* always show the prompt/help/quit commands */
|
||||
chunk_strcat(tmp,
|
||||
" help [<command>] : list matching or all commands\n"
|
||||
|
Loading…
Reference in New Issue
Block a user