Mailing List Archive

[master] 4ba159323 cli: Make param.set -j output the updated parameter
commit 4ba159323447a469e5717085572681bc6f588465
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Wed Jan 5 23:26:42 2022 +0100

cli: Make param.set -j output the updated parameter

Closes #3756

diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index fd77e2942..1ea94da54 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -580,6 +580,16 @@ mcf_param_set(struct cli *cli, const char * const *av, void *priv)
MCF_ParamSet(cli, av[2], av[3]);
}

+static void v_matchproto_(cli_func_t)
+mcf_param_set_json(struct cli *cli, const char * const *av, void *priv)
+{
+ const char *const avs[] = { av[0], av[1], av[2], av[3], NULL };
+
+ MCF_ParamSet(cli, av[3], av[4]);
+ if (cli->result == CLIS_OK)
+ mcf_param_show_json(cli, avs, priv);
+}
+
/*--------------------------------------------------------------------*/

static void v_matchproto_(cli_func_t)
@@ -683,10 +693,9 @@ mcf_wash_param(struct cli *cli, struct parspec *pp, enum mcf_which_e which,
/*--------------------------------------------------------------------*/

static struct cli_proto cli_params[] = {
- { CLICMD_PARAM_SHOW, "", mcf_param_show,
- mcf_param_show_json },
- { CLICMD_PARAM_SET, "", mcf_param_set },
- { CLICMD_PARAM_RESET, "", mcf_param_reset },
+ { CLICMD_PARAM_SHOW, "", mcf_param_show, mcf_param_show_json },
+ { CLICMD_PARAM_SET, "", mcf_param_set, mcf_param_set_json },
+ { CLICMD_PARAM_RESET, "", mcf_param_reset },
{ NULL }
};

diff --git a/bin/varnishtest/tests/b00042.vtc b/bin/varnishtest/tests/b00042.vtc
index 7f580ef24..037469ec7 100644
--- a/bin/varnishtest/tests/b00042.vtc
+++ b/bin/varnishtest/tests/b00042.vtc
@@ -38,6 +38,7 @@ varnish v1 -clijson "param.show -j pool_req"
varnish v1 -clijson "param.show -j pool_sess"
varnish v1 -clijson "param.show -j changed"
varnish v1 -clijson "param.show -j"
+varnish v1 -clijson "param.set -j default_ttl 0"
varnish v1 -clierr 106 "param.show -j -l"
varnish v1 -clierr 106 "param.show -j fofofofo"
varnish v1 -clierr 105 "param.show debug debug"
diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h
index d4466e4c7..27443bc70 100644
--- a/include/tbl/cli_cmds.h
+++ b/include/tbl/cli_cmds.h
@@ -195,9 +195,14 @@ CLI_CMD(PARAM_SHOW,

CLI_CMD(PARAM_SET,
"param.set",
- "param.set <param> <value>",
+ "param.set [-j] <param> <value>",
"Set parameter value.",
- "",
+ " The JSON output is the same as ``param.show -j <param>`` and"
+ " contains the updated value as it would be represented by a"
+ " subsequent execution of ``param.show``.\n\n"
+ " This can be useful to later verify that a parameter value didn't"
+ " change and to use the value from the JSON output to reset the"
+ " parameter to the desired value.",
2,2
)

_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit