diff mbox series

[v5,4/5] cec-ctl: Add version command

Message ID 20200715102640.17554-4-paul.elder@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series [v5,1/5] v4l2-compliance: Add version command | expand

Commit Message

Paul Elder July 15, 2020, 10:26 a.m. UTC
Add a --version option to cec-ctl to retrieve the version of cec-ctl.

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

---
Changes in v5:
- update manpage

Changes in v4:
- add git commit count to version

Changes in v3:
- embed PACKAGE_VERSION instead of string concatenation
---
 utils/cec-ctl/Makefile.am  |  2 +-
 utils/cec-ctl/cec-ctl.1.in |  3 +++
 utils/cec-ctl/cec-ctl.cpp  | 15 +++++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/utils/cec-ctl/Makefile.am b/utils/cec-ctl/Makefile.am
index 24341ed7..278fcc47 100644
--- a/utils/cec-ctl/Makefile.am
+++ b/utils/cec-ctl/Makefile.am
@@ -2,7 +2,7 @@  bin_PROGRAMS = cec-ctl
 man_MANS = cec-ctl.1
 
 cec_ctl_SOURCES = cec-ctl.cpp cec-pin.cpp cec-ctl.h
-cec_ctl_CPPFLAGS = -I$(top_srcdir)/utils/libcecutil
+cec_ctl_CPPFLAGS = -I$(top_srcdir)/utils/libcecutil $(GIT_COMMIT_CNT)
 cec_ctl_LDADD = -lrt ../libcecutil/libcecutil.la
 
 EXTRA_DIST = cec-ctl.1
diff --git a/utils/cec-ctl/cec-ctl.1.in b/utils/cec-ctl/cec-ctl.1.in
index f767b479..fac3a92e 100644
--- a/utils/cec-ctl/cec-ctl.1.in
+++ b/utils/cec-ctl/cec-ctl.1.in
@@ -52,6 +52,9 @@  having to rely on the device node number.
 \fB\-v\fR, \fB\-\-verbose\fR
 Turn on verbose reporting.
 .TP
+\fB\-\-version\fR
+Show version information.
+.TP
 \fB\-w\fR, \fB\-\-wall\-clock\fR
 Show timestamps as wall-clock time. This also turns on verbose reporting. 
 .TP
diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
index 455cdaeb..47867f87 100644
--- a/utils/cec-ctl/cec-ctl.cpp
+++ b/utils/cec-ctl/cec-ctl.cpp
@@ -133,6 +133,7 @@  enum Option {
 	OptVendorCommandWithID,
 	OptVendorRemoteButtonDown,
 	OptCustomCommand,
+	OptVersion,
 };
 
 struct node {
@@ -218,6 +219,8 @@  static struct option long_options[] = {
 	{ "unregistered", no_argument, 0, OptUnregistered },
 	{ "help-all", no_argument, 0, OptHelpAll },
 
+	{ "version", no_argument, 0, OptVersion },
+
 	CEC_PARSE_LONG_OPTS
 
 	{ "vendor-remote-button-down", required_argument, 0, OptVendorRemoteButtonDown }, \
@@ -231,6 +234,13 @@  static struct option long_options[] = {
 	{ 0, 0, 0, 0 }
 };
 
+static void print_version()
+{
+#define STR(x) #x
+#define STRING(x) STR(x)
+	printf("cec-ctl %s%s\n", PACKAGE_VERSION, STRING(GIT_COMMIT_CNT));
+}
+
 static void usage()
 {
 	printf("Usage:\n"
@@ -262,6 +272,7 @@  static void usage()
 	       "  --help-all               Show all help messages\n"
 	       "  -T, --trace              Trace all called ioctls\n"
 	       "  -v, --verbose            Turn on verbose reporting\n"
+	       "  --version                Show version information\n"
 	       "  -w, --wall-clock         Show timestamps as wall-clock time (implies -v)\n"
 	       "  -W, --wait-for-msgs      Wait for messages and events for up to --monitor-time secs.\n"
 	       "  --cec-version-1.4        Use CEC Version 1.4 instead of 2.0\n"
@@ -2296,6 +2307,10 @@  int main(int argc, char **argv)
 			break;
 		}
 
+		case OptVersion:
+			print_version();
+			std::exit(EXIT_SUCCESS);
+
 		default:
 			if (ch >= OptHelpAll) {
 				cec_parse_usage_options(options);