diff mbox series

[v4,6/7] cec-follower: Add version command

Message ID 20200714055915.640438-6-paul.elder@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series [v4,1/7] configure.ac: Export git commit count | expand

Commit Message

Paul Elder July 14, 2020, 5:59 a.m. UTC
Add a --version option to cec-follower to retrieve the version of
cec-follower. Whilte at it, factor out printing the SHA.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

---
Changes in v4:
- add git commit count to version
- move printing sha into print_sha()

Changes in v3:
- embed PACKAGE_VERSION instead of string concatenation
---
 utils/cec-follower/Makefile.am      |  2 +-
 utils/cec-follower/cec-follower.cpp | 30 ++++++++++++++++++++++-------
 2 files changed, 24 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/utils/cec-follower/Makefile.am b/utils/cec-follower/Makefile.am
index a550cd1d..96e0f890 100644
--- a/utils/cec-follower/Makefile.am
+++ b/utils/cec-follower/Makefile.am
@@ -2,7 +2,7 @@  bin_PROGRAMS = cec-follower
 man_MANS = cec-follower.1
 
 cec_follower_SOURCES = cec-follower.cpp cec-follower.h cec-processing.cpp cec-tuner.cpp
-cec_follower_CPPFLAGS = -I$(top_srcdir)/utils/libcecutil
+cec_follower_CPPFLAGS = -I$(top_srcdir)/utils/libcecutil $(GIT_COMMIT_CNT)
 cec_follower_LDADD = -lrt ../libcecutil/libcecutil.la
 
 cec-follower.cpp: version.h
diff --git a/utils/cec-follower/cec-follower.cpp b/utils/cec-follower/cec-follower.cpp
index 9cead57a..b3f9d615 100644
--- a/utils/cec-follower/cec-follower.cpp
+++ b/utils/cec-follower/cec-follower.cpp
@@ -46,6 +46,7 @@  enum Option {
 	OptShowState = 's',
 	OptWallClock = 'w',
 	OptServiceByDigID = 128,
+	OptVersion,
 	OptLast = 256
 };
 
@@ -70,10 +71,27 @@  static struct option long_options[] = {
 	{ "wall-clock", no_argument, 0, OptWallClock },
 	{ "service-by-dig-id", no_argument, 0, OptServiceByDigID },
 	{ "ignore", required_argument, 0, OptIgnore },
+	{ "version", no_argument, 0, OptVersion },
 
 	{ 0, 0, 0, 0 }
 };
 
+static void print_sha()
+{
+#ifdef SHA
+#define STR(x) #x
+#define STRING(x) STR(x)
+	printf("cec-follower SHA                   : %s\n", STRING(SHA));
+#else
+	printf("cec-follower SHA                   : not available\n");
+#endif
+}
+
+static void print_version()
+{
+	printf("cec-follower %s%s\n", PACKAGE_VERSION, STRING(GIT_COMMIT_CNT));
+}
+
 static void usage()
 {
 	printf("Usage:\n"
@@ -93,6 +111,7 @@  static void usage()
 	       "                      Ignore messages from logical address <la> and opcode\n"
 	       "                      <opcode>. 'all' can be used for <la> or <opcode> to match\n"
 	       "                      all logical addresses or opcodes.\n"
+	       "  --version           Show version information\n"
 	       );
 }
 
@@ -427,6 +446,9 @@  int main(int argc, char **argv)
 			show_msgs = true;
 			show_state = true;
 			break;
+		case OptVersion:
+			print_version();
+			std::exit(EXIT_SUCCESS);
 		case ':':
 			fprintf(stderr, "Option '%s' requires a value\n",
 				argv[optind]);
@@ -475,13 +497,7 @@  int main(int argc, char **argv)
 	node.state.service_by_dig_id = options[OptServiceByDigID];
 	state_init(node);
 
-#ifdef SHA
-#define STR(x) #x
-#define STRING(x) STR(x)
-	printf("cec-follower SHA                   : %s\n", STRING(SHA));
-#else
-	printf("cec-follower SHA                   : not available\n");
-#endif
+	print_sha();
 
 	doioctl(&node, CEC_ADAP_G_PHYS_ADDR, &node.phys_addr);