[master] fa0f8b4 Add -h option to print usage and exit

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


commit fa0f8b407595212ca987dde08be808caab5a3c83
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Oct 10 14:54:52 2013 +0200

    Add -h option to print usage and exit

diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index 84a23ae..571c7d7 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -53,14 +53,14 @@
 static const char progname[] = "varnishlog";
 
 static void
-usage(void)
+usage(int status)
 {
 	const char **opt;
 	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));
-	exit(1);
+	exit(status);
 }
 
 int
@@ -72,14 +72,16 @@ main(int argc, char * const *argv)
 
 	while ((opt = getopt(argc, argv, vopt_optstring)) != -1) {
 		switch (opt) {
+		case 'h':
+			usage(0);
 		default:
 			if (!VUT_Arg(opt, optarg))
-				usage();
+				usage(1);
 		}
 	}
 
 	if (optind != argc)
-		usage();
+		usage(1);
 
 	VUT_Setup();
 	VUT_Main(NULL, NULL);
diff --git a/bin/varnishlog/varnishlog_options.h b/bin/varnishlog/varnishlog_options.h
index b58c54f..b1e4c67 100644
--- a/bin/varnishlog/varnishlog_options.h
+++ b/bin/varnishlog/varnishlog_options.h
@@ -37,6 +37,7 @@ VSL_OPT_C
 VUT_OPT_d
 VUT_OPT_D
 VUT_OPT_g
+VUT_OPT_h
 VSL_OPT_i
 VSL_OPT_I
 VSL_OPT_L
diff --git a/include/vut_options.h b/include/vut_options.h
index feab4ab..730fe8a 100644
--- a/include/vut_options.h
+++ b/include/vut_options.h
@@ -52,6 +52,11 @@
 	    " by request."						\
 	)
 
+#define VUT_OPT_h							\
+	VOPT("h", "[-h]", "Usage help",					\
+	    "Print program usage and exit"				\
+	)
+
 #define VUT_OPT_n							\
 	VOPT("n:", "[-n name]", "Varnish instance name",		\
 	    "Specify the name of the varnishd instance to get logs"	\



More information about the varnish-commit mailing list