[master] 075e6e6 Implement -V (version) for vut (varnishlog)

Martin Blix Grydeland martin at varnish-cache.org
Thu Oct 10 16:48:39 CEST 2013


commit 075e6e64060ce0be47cd3b8b36dfac780386e791
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Oct 10 14:32:35 2013 +0200

    Implement -V (version) for vut (varnishlog)

diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index a10c595..84a23ae 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -50,11 +50,13 @@
 #include "vtim.h"
 #include "vut.h"
 
+static const char progname[] = "varnishlog";
+
 static void
 usage(void)
 {
 	const char **opt;
-	fprintf(stderr, "Usage: varnishlog <options>\n\n");
+	fprintf(stderr, "Usage: %s <options>\n\n", progname);
 	fprintf(stderr, "Options:\n");
 	for (opt = vopt_usage; *opt != NULL; opt += 2)
 		fprintf(stderr, "  %-25s %s\n", *opt, *(opt + 1));
@@ -66,7 +68,7 @@ main(int argc, char * const *argv)
 {
 	char opt;
 
-	VUT_Init();
+	VUT_Init(progname);
 
 	while ((opt = getopt(argc, argv, vopt_optstring)) != -1) {
 		switch (opt) {
diff --git a/bin/varnishlog/varnishlog_options.h b/bin/varnishlog/varnishlog_options.h
index f03b2ce..b58c54f 100644
--- a/bin/varnishlog/varnishlog_options.h
+++ b/bin/varnishlog/varnishlog_options.h
@@ -48,6 +48,7 @@ VUT_OPT_r
 VSL_OPT_T
 VUT_OPT_u
 VSL_OPT_v
+VUT_OPT_V
 VUT_OPT_w
 VSL_OPT_x
 VSL_OPT_X
diff --git a/doc/sphinx/reference/varnishlog.rst b/doc/sphinx/reference/varnishlog.rst
index 50329e1..6021fd4 100644
--- a/doc/sphinx/reference/varnishlog.rst
+++ b/doc/sphinx/reference/varnishlog.rst
@@ -43,12 +43,6 @@ The following options are available:
 
 	XXX: Not yet implemented
 
--V
-
-	Display the version number and exit.
-
-	XXX: Not yet implemented
-
 SIGNALS
 =======
 
diff --git a/include/vut.h b/include/vut.h
index 51f2552..5ba134b 100644
--- a/include/vut.h
+++ b/include/vut.h
@@ -32,6 +32,8 @@
 #include "vdef.h"
 
 struct VUT {
+	const char	*progname;
+
 	/* Options */
 	int		a_opt;
 	int		d_opt;
@@ -65,7 +67,7 @@ int VUT_Arg(int opt, const char *arg);
 
 void VUT_Setup(void);
 
-void VUT_Init(void);
+void VUT_Init(const char *progname);
 
 void VUT_Fini(void);
 
diff --git a/include/vut_options.h b/include/vut_options.h
index cc25ae8..feab4ab 100644
--- a/include/vut_options.h
+++ b/include/vut_options.h
@@ -84,6 +84,11 @@
 	    "Unbuffered binary file output mode."			\
 	)
 
+#define VUT_OPT_V							\
+	VOPT("V", "[-V]", "Version",					\
+	    "Print version information and exit."			\
+	)
+
 #define VUT_OPT_w							\
 	VOPT("w:", "[-w filename]", "Binary output filename",		\
 	    "Write log entries to this file instead of displaying"	\
diff --git a/lib/libvarnishtools/vut.c b/lib/libvarnishtools/vut.c
index 709b6bd..8f454ca 100644
--- a/lib/libvarnishtools/vut.c
+++ b/lib/libvarnishtools/vut.c
@@ -48,6 +48,7 @@
 #include "vtim.h"
 #include "vas.h"
 #include "miniobj.h"
+#include "vcs.h"
 
 #include "vut.h"
 
@@ -164,6 +165,10 @@ VUT_Arg(int opt, const char *arg)
 		/* Unbuffered binary output */
 		VUT.u_opt = 1;
 		return (1);
+	case 'V':
+		/* Print version number and exit */
+		VCS_Message(VUT.progname);
+		exit(1);
 	case 'w':
 		/* Binary file output */
 		REPLACE(VUT.w_arg, arg);
@@ -178,8 +183,9 @@ VUT_Arg(int opt, const char *arg)
 }
 
 void
-VUT_Init(void)
+VUT_Init(const char *progname)
 {
+	VUT.progname = progname;
 	VUT.g_arg = VSL_g_vxid;
 	AZ(VUT.vsl);
 	VUT.vsl = VSL_New();



More information about the varnish-commit mailing list