[master] c5676a866 vcl.show no param defaults to active vcl

Poul-Henning Kamp phk at FreeBSD.org
Mon Dec 6 14:07:06 UTC 2021


commit c5676a866ce59f7796859477201967c286ba728a
Author: Lachlan Abbott <lachie at varnish-software.com>
Date:   Wed Dec 1 10:58:51 2021 +1100

    vcl.show no param defaults to active vcl

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 50c1228ba..18d820fe4 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -946,28 +946,33 @@ vcl_cli_show(struct cli *cli, const char * const *av, void *priv)
 {
 	struct vcl *vcl;
 	int verbose = 0;
-	int i;
+	int i = 2;
 
 	ASSERT_CLI();
 	ASSERT_VCL_ACTIVE();
 	AZ(priv);
-	if (!strcmp(av[2], "-v") && av[3] == NULL) {
-		VCLI_Out(cli, "Too few parameters");
-		VCLI_SetResult(cli, CLIS_TOOFEW);
-		return;
-	} else if (strcmp(av[2], "-v") && av[3] != NULL) {
-		VCLI_Out(cli, "Unknown options '%s'", av[2]);
+
+	if (av[i] != NULL && !strcmp(av[i], "-v")) {
+		verbose = 1;
+		i++;
+	}
+
+	if (av[i] == NULL) {
+		vcl = vcl_active;
+		AN(vcl);
+	} else {
+		vcl = vcl_find(av[i]);
+		i++;
+	}
+
+	if (av[i] != NULL) {
+		VCLI_Out(cli, "Too many parameters: '%s'", av[i]);
 		VCLI_SetResult(cli, CLIS_PARAM);
 		return;
-	} else if (av[3] != NULL) {
-		verbose = 1;
-		vcl = vcl_find(av[3]);
-	} else
-		vcl = vcl_find(av[2]);
+	}
 
 	if (vcl == NULL) {
-		VCLI_Out(cli, "No VCL named '%s'",
-		    av[3] == NULL ? av[2] : av[3]);
+		VCLI_Out(cli, "No VCL named '%s'", av[i - 1]);
 		VCLI_SetResult(cli, CLIS_PARAM);
 		return;
 	}
diff --git a/bin/varnishtest/tests/c00015.vtc b/bin/varnishtest/tests/c00015.vtc
index 1acbbd297..1f1e1a479 100644
--- a/bin/varnishtest/tests/c00015.vtc
+++ b/bin/varnishtest/tests/c00015.vtc
@@ -53,7 +53,8 @@ varnish v1 -cli "vcl.show vcl2"
 varnish v1 -cli "vcl.show -v vcl2"
 varnish v1 -cli "vcl.discard vcl2"
 varnish v1 -cli "vcl.list"
-varnish v1 -clierr 104 "vcl.show -v"
+varnish v1 -cli "vcl.show"
+varnish v1 -cli "vcl.show -v"
 varnish v1 -clierr 106 "vcl.show -x nowhere"
 varnish v1 -clierr 106 "vcl.show nothere"
 varnish v1 -clierr 106 "vcl.use nothere"
diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h
index 3814a1615..7b989e2ca 100644
--- a/include/tbl/cli_cmds.h
+++ b/include/tbl/cli_cmds.h
@@ -146,10 +146,10 @@ CLI_CMD(VCL_DEPS,
 
 CLI_CMD(VCL_SHOW,
 	"vcl.show",
-	"vcl.show [-v] <configname>",
+	"vcl.show [-v] [<configname>]",
 	"Display the source code for the specified configuration.",
 	"",
-	1, 2
+	0, 2
 )
 
 CLI_CMD(VCL_USE,


More information about the varnish-commit mailing list