[master] 563df677c param: Parse param.show like param.show -j
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Tue Dec 14 08:38:06 UTC 2021
commit 563df677cdd1836cf391ce824f683230d20de8ff
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Dec 14 09:25:41 2021 +0100
param: Parse param.show like param.show -j
And complain when two parameters are passed instead of one parameter and
one option.
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 4a4ecbfcc..4070ddb42 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -242,29 +242,42 @@ mcf_wrap(struct cli *cli, const char *text)
static void v_matchproto_(cli_func_t)
mcf_param_show(struct cli *cli, const char * const *av, void *priv)
{
- int n;
struct plist *pl;
const struct parspec *pp;
- int lfmt = 0, chg = 0;
+ int n, lfmt = 0, chg = 0;
struct vsb *vsb;
+ const char *show = NULL;
vsb = VSB_new_auto();
AN(vsb);
(void)priv;
- if (av[2] != NULL && !strcmp(av[2], "changed"))
- chg = 1;
- else if (av[2] != NULL)
+ for (n = 2; av[n] != NULL; n++) {
+ if (strcmp(av[n], "-l") == 0) {
+ lfmt = 1;
+ continue;
+ }
+ if (strcmp(av[n], "changed") == 0) {
+ chg = 1;
+ continue;
+ }
+ if (show != NULL) {
+ VCLI_SetResult(cli, CLIS_TOOMANY);
+ VCLI_Out(cli, "Too many parameters");
+ return;
+ }
+ show = av[n];
lfmt = 1;
+ }
n = 0;
VTAILQ_FOREACH(pl, &phead, list) {
pp = pl->spec;
- if (lfmt && strcmp(pp->name, av[2]) && strcmp("-l", av[2]))
+ if (lfmt && show != NULL && strcmp(pp->name, show))
continue;
- if (pp->func == tweak_alias && !lfmt)
+ if (pp->func == tweak_alias && show == NULL)
continue;
- if (pp->func == tweak_alias && strcmp(pp->name, av[2]))
+ if (pp->func == tweak_alias && strcmp(pp->name, show))
continue;
n++;
@@ -333,9 +346,9 @@ mcf_param_show(struct cli *cli, const char * const *av, void *priv)
VCLI_Out(cli, "\n\n");
}
}
- if (av[2] != NULL && lfmt && strcmp(av[2], "-l") && n == 0) {
+ if (show != NULL && n == 0) {
VCLI_SetResult(cli, CLIS_PARAM);
- VCLI_Out(cli, "Unknown parameter \"%s\".", av[2]);
+ VCLI_Out(cli, "Unknown parameter \"%s\".", show);
}
VSB_destroy(&vsb);
}
@@ -372,6 +385,11 @@ mcf_param_show_json(struct cli *cli, const char * const *av, void *priv)
}
if (strcmp(av[i], "-j") == 0)
continue;
+ if (show != NULL) {
+ VCLI_SetResult(cli, CLIS_TOOMANY);
+ VCLI_Out(cli, "Too many parameters");
+ return;
+ }
show = av[i];
}
diff --git a/bin/varnishtest/tests/b00042.vtc b/bin/varnishtest/tests/b00042.vtc
index 6c338ae51..02a969082 100644
--- a/bin/varnishtest/tests/b00042.vtc
+++ b/bin/varnishtest/tests/b00042.vtc
@@ -40,3 +40,5 @@ varnish v1 -clijson "param.show -j changed"
varnish v1 -clijson "param.show -j"
varnish v1 -clierr "106" "param.show -j -l"
varnish v1 -clierr "106" "param.show -j fofofofo"
+varnish v1 -clierr "105" "param.show debug debug"
+varnish v1 -clierr "105" "param.show -j debug debug"
diff --git a/bin/varnishtest/tests/u00017.vtc b/bin/varnishtest/tests/u00017.vtc
index a7fa82598..86e6e018b 100644
--- a/bin/varnishtest/tests/u00017.vtc
+++ b/bin/varnishtest/tests/u00017.vtc
@@ -13,7 +13,7 @@ varnish v1 -vcl+backend {
}
} -start
-varnish v1 -cliok "param.show vsl_mask +Debug"
+varnish v1 -cliok "param.set vsl_mask +Debug"
client c1 {
txreq
More information about the varnish-commit
mailing list