[master] e7ad1e46a Give `varnishadm` a `-p` to disable libreadline and get VCLI compliance.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Feb 15 13:43:08 UTC 2021
commit e7ad1e46a0f51a78db8df431deb07b7282e09a5c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Feb 15 13:41:52 2021 +0000
Give `varnishadm` a `-p` to disable libreadline and get VCLI compliance.
diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c
index e3e76efa3..b9023eb97 100644
--- a/bin/varnishadm/varnishadm.c
+++ b/bin/varnishadm/varnishadm.c
@@ -75,6 +75,7 @@
static const double timeout = 5; // XXX should be settable by arg ?
+static int p_arg = 0;
static void
cli_write(int sock, const char *s)
@@ -254,7 +255,10 @@ pass_answer(int fd)
RL_EXIT(1);
}
- printf("%u\n", status);
+ if (p_arg)
+ printf("%-3u %-8zu\n", status, strlen(answer));
+ else
+ printf("%u\n", status);
if (answer) {
printf("%s\n", answer);
free(answer);
@@ -441,7 +445,7 @@ main(int argc, char * const *argv)
* The '+' stops that from happening
* See #1496
*/
- while ((opt = getopt(argc, argv, "+hn:S:T:t:")) != -1) {
+ while ((opt = getopt(argc, argv, "+hn:pS:T:t:")) != -1) {
switch (opt) {
case 'h':
/* Usage help */
@@ -449,6 +453,9 @@ main(int argc, char * const *argv)
case 'n':
n_arg = optarg;
break;
+ case 'p':
+ p_arg = 1;
+ break;
case 'S':
S_arg = optarg;
break;
@@ -485,7 +492,7 @@ main(int argc, char * const *argv)
NEEDLESS(exit(0));
}
- if (isatty(0))
+ if (isatty(0) && !p_arg)
interactive(sock);
else
pass(sock);
diff --git a/bin/varnishtest/tests/u00012.vtc b/bin/varnishtest/tests/u00012.vtc
index 2744ae40a..4770e0fc9 100644
--- a/bin/varnishtest/tests/u00012.vtc
+++ b/bin/varnishtest/tests/u00012.vtc
@@ -14,15 +14,17 @@ client c1 {
varnish v1 -vsl_catchup
-process p1 -log {cat | varnishadm -n ${v1_name}} -start
+process p1 -log {cat | varnishadm -p -n ${v1_name}} -start
process p1 -write "ping\r"
+process p1 -expect-text 0 1 "200 19"
+
process p1 -expect-text 0 1 "PONG"
process p1 -write "vcl.list\r"
-process p1 -expect-text 0 0 "auto warm"
+process p1 -expect-text 0 0 "auto warm"
process p1 -write "vcl.show vcl1\r"
diff --git a/doc/sphinx/reference/varnishadm.rst b/doc/sphinx/reference/varnishadm.rst
index e503671d9..aa7f3d4a4 100644
--- a/doc/sphinx/reference/varnishadm.rst
+++ b/doc/sphinx/reference/varnishadm.rst
@@ -38,6 +38,11 @@ OPTIONS
-h
Print program usage and exit.
+-p
+ Force `pass` mode and make the output follow the VCLI protocol.
+ This disables command-history/command-completion and makes it
+ easier for programs to parse the response(s).
+
-n ident
Connect to the instance of `varnishd` with this name.
More information about the varnish-commit
mailing list