Commit 83cd27f841bd6479abfad4c2e3c4bd870dd8ab7e

Stefan Sperling 2020-01-13T15:59:47

make got and tog accept a --version argument; -V option is a bit obscure prompted by a question from tedu@

diff --git a/got/got.1 b/got/got.1
index c37e7ca..3cc5be6 100644
--- a/got/got.1
+++ b/got/got.1
@@ -54,7 +54,7 @@ Global options must precede the command name, and are as follows:
 .Bl -tag -width tenletters
 .It Fl h
 Display usage information and exit immediately.
-.It Fl V
+.It Fl V, -version
 Display program version and exit immediately.
 .El
 .Pp
diff --git a/got/got.c b/got/got.c
index 9949c54..38d9e61 100644
--- a/got/got.c
+++ b/got/got.c
@@ -36,6 +36,7 @@
 #include <time.h>
 #include <paths.h>
 #include <regex.h>
+#include <getopt.h>
 
 #include "got_version.h"
 #include "got_error.h"
@@ -176,10 +177,14 @@ main(int argc, char *argv[])
 	unsigned int i;
 	int ch;
 	int hflag = 0, Vflag = 0;
+	static struct option longopts[] = {
+	     { "version", no_argument, NULL, 'V' },
+	     { NULL, 0, NULL, 0}
+	};
 
 	setlocale(LC_CTYPE, "");
 
-	while ((ch = getopt(argc, argv, "hV")) != -1) {
+	while ((ch = getopt_long(argc, argv, "hV", longopts, NULL)) != -1) {
 		switch (ch) {
 		case 'h':
 			hflag = 1;
diff --git a/tog/tog.1 b/tog/tog.1
index 19ba4d6..8bb9658 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -68,7 +68,7 @@ Global options must precede the command name, and are as follows:
 .Bl -tag -width tenletters
 .It Fl h
 Display usage information.
-.It Fl V
+.It Fl V, -version
 Display program version and exit immediately.
 .El
 .Pp
diff --git a/tog/tog.c b/tog/tog.c
index f743343..7c13005 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -5099,10 +5099,14 @@ main(int argc, char *argv[])
 	struct tog_cmd *cmd = NULL;
 	int ch, hflag = 0, Vflag = 0;
 	char **cmd_argv = NULL;
+	static struct option longopts[] = {
+	     { "version", no_argument, NULL, 'V' },
+	     { NULL, 0, NULL, 0}
+	};
 
 	setlocale(LC_CTYPE, "");
 
-	while ((ch = getopt(argc, argv, "hV")) != -1) {
+	while ((ch = getopt_long(argc, argv, "hV", longopts, NULL)) != -1) {
 		switch (ch) {
 		case 'h':
 			hflag = 1;