[master] bdf2e0608 Polish implementation of "cli help"
Poul-Henning Kamp
phk at FreeBSD.org
Tue Nov 23 11:42:05 UTC 2021
commit bdf2e0608436b17b903393e65adc57514b6eb89c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Nov 23 09:51:36 2021 +0000
Polish implementation of "cli help"
diff --git a/bin/varnishtest/tests/b00008.vtc b/bin/varnishtest/tests/b00008.vtc
index 4fdf4205b..755d6e4b4 100644
--- a/bin/varnishtest/tests/b00008.vtc
+++ b/bin/varnishtest/tests/b00008.vtc
@@ -10,6 +10,8 @@ varnish v1 -cliok "help -a"
varnish v1 -cliok "help -d"
+varnish v1 -clierr 101 "help -x"
+
varnish v1 -cliok "help vcl.load"
varnish v1 -clierr 101 "help ban"
diff --git a/lib/libvarnish/vcli_serve.c b/lib/libvarnish/vcli_serve.c
index 1dcbb7da5..c5b8c82fa 100644
--- a/lib/libvarnish/vcli_serve.c
+++ b/lib/libvarnish/vcli_serve.c
@@ -120,25 +120,30 @@ void v_matchproto_(cli_func_t)
VCLS_func_help(struct cli *cli, const char * const *av, void *priv)
{
struct cli_proto *clp;
- unsigned all, debug, d;
+ unsigned all = 0, debug = 0, d;
struct VCLS *cs;
(void)priv;
cs = cli->cls;
CHECK_OBJ_NOTNULL(cs, VCLS_MAGIC);
- if (av[2] == NULL) {
- all = debug = 0;
- } else if (!strcmp(av[2], "-a")) {
- all = 1;
- debug = 0;
- } else if (!strcmp(av[2], "-d")) {
- all = 0;
- debug = 1;
- } else {
+ for (av += 2; av[0] != NULL && av[0][0] == '-'; av++) {
+ if (!strcmp(av[0], "-a")) {
+ all = 1;
+ debug = 0;
+ } else if (!strcmp(av[0], "-d")) {
+ all = 0;
+ debug = 1;
+ } else {
+ VCLI_Out(cli, "Unknown flag\n");
+ VCLI_SetResult(cli, CLIS_UNKNOWN);
+ return;
+ }
+ }
+ if (av[0] != NULL) {
VTAILQ_FOREACH(clp, &cs->funcs, list) {
if (clp->auth <= cli->auth &&
- !strcmp(clp->desc->request, av[2])) {
+ !strcmp(clp->desc->request, av[0])) {
VCLI_Out(cli, "%s\n%s\n",
clp->desc->syntax, clp->desc->help);
return;
@@ -151,13 +156,13 @@ VCLS_func_help(struct cli *cli, const char * const *av, void *priv)
VTAILQ_FOREACH(clp, &cs->funcs, list) {
if (clp->auth > cli->auth)
continue;
- d = strchr(clp->flags, 'd') != NULL ? 1 : 0;
+ d = strchr(clp->flags, 'd') != NULL ? 1 : 0;
if (d && (!all && !debug))
continue;
if (debug && !d)
continue;
- if (clp->desc->syntax != NULL)
- VCLI_Out(cli, "%s\n", clp->desc->syntax);
+ AN(clp->desc->syntax);
+ VCLI_Out(cli, "%s\n", clp->desc->syntax);
}
}
More information about the varnish-commit
mailing list