From 06d0e2e034632df92a3a67318185a96fdb381f1c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 29 Mar 2022 15:25:30 +0200 Subject: [PATCH] MINOR: cli: add a new keyword dump function New function cli_list_keywords() scans the list of registered CLI keywords and dumps them on stdout. It's now called from dump_registered_keywords() for the class "cli". Some keywords are valid for the master, they'll be suffixed with "[MASTER]". Others are valid for the worker, they'll have "[WORKER]". Those accessible only in expert mode will show "[EXPERT]" and the experimental ones will show "[EXPERIM]". --- include/haproxy/cli.h | 1 + src/cli.c | 24 ++++++++++++++++++++++++ src/haproxy.c | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/include/haproxy/cli.h b/include/haproxy/cli.h index 6d66157d4..f202a4f43 100644 --- a/include/haproxy/cli.h +++ b/include/haproxy/cli.h @@ -33,6 +33,7 @@ void cli_register_kw(struct cli_kw_list *kw_list); struct cli_kw* cli_find_kw_exact(char **args); +void cli_list_keywords(void); int cli_has_level(struct appctx *appctx, int level); diff --git a/src/cli.c b/src/cli.c index 6f617b2fd..9f4b8df5a 100644 --- a/src/cli.c +++ b/src/cli.c @@ -368,6 +368,30 @@ void cli_register_kw(struct cli_kw_list *kw_list) LIST_APPEND(&cli_keywords.list, &kw_list->list); } +/* list all known keywords on stdout, one per line */ +void cli_list_keywords(void) +{ + struct cli_kw_list *kw_list; + struct cli_kw *kw; + int idx; + + list_for_each_entry(kw_list, &cli_keywords.list, list) { + for (kw = &kw_list->kw[0]; kw->str_kw[0]; kw++) { + for (idx = 0; kw->str_kw[idx]; idx++) { + printf("%s ", kw->str_kw[idx]); + } + if (kw->level & (ACCESS_MASTER_ONLY|ACCESS_MASTER)) + printf("[MASTER] "); + if (!(kw->level & ACCESS_MASTER_ONLY)) + printf("[WORKER] "); + if (kw->level & ACCESS_EXPERT) + printf("[EXPERT] "); + if (kw->level & ACCESS_EXPERIMENTAL) + printf("[EXPERIM] "); + printf("\n"); + } + } +} /* allocate a new stats frontend named , and return it * (or NULL in case of lack of memory). diff --git a/src/haproxy.c b/src/haproxy.c index a2b7d9193..16fafc393 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1826,6 +1826,7 @@ static void dump_registered_keywords(void) printf("# List of supported keyword classes:\n"); printf("all: list all keywords\n"); printf("cfg: configuration keywords\n"); + printf("cli: CLI keywords\n"); printf("flt: filter names\n"); printf("svc: service names\n"); continue; @@ -1839,6 +1840,11 @@ static void dump_registered_keywords(void) cfg_dump_registered_keywords(); } + if (all || strcmp(kwd_dump, "cli") == 0) { + printf("# List of registered CLI keywords:\n"); + cli_list_keywords(); + } + if (all || strcmp(kwd_dump, "flt") == 0) { printf("# List of registered filter names:\n"); flt_dump_kws(NULL);