浏览代码

Add version info

Björn Åström 1 年之前
父节点
当前提交
14a9dbfed2
共有 2 个文件被更改,包括 17 次插入3 次删除
  1. 2 1
      Makefile
  2. 15 2
      qcmd.c

+ 2 - 1
Makefile

@@ -1,3 +1,4 @@
+VERSION = 0.1-beta
 CC ?= gcc
 DEBUG ?= 0
 
@@ -5,7 +6,7 @@ ifeq ($(DEBUG), 1)
 	DEBUGFLAGS = -g -DDEBUG
 endif
 
-CCFLAGS = $(DEBUGFLAGS) -Wall -lm -ltcl \
+CCFLAGS = $(DEBUGFLAGS) '-DVERSION="$(VERSION)"' -Wall -lm -ltcl \
 	$(shell pkg-config --cflags --libs glib-2.0)\
 	$(shell pkg-config --cflags --libs libnotify)
 

+ 15 - 2
qcmd.c

@@ -148,11 +148,21 @@ static int cmd_open(char *cmd, int *pid) {
 	}
 }
 
+void print_version()
+{
+#ifdef VERSION
+	printf("qcmd version %s\n", VERSION);
+#else
+	printf("qcmd (unknown version)\n");
+#endif
+}
+
 void print_help()
 {
 	printf(
 			"usage: qcmd [options] [command]\n"
 			"  -h, --help           Display this help text.\n"
+			"  -v, --version        Display version information.\n"
 			"  -r, --rows           Number of rows in terminal output.\n"
 			"  -c, --cols           Number of columns in terminal output.\n"
 			"  -C, --close-on-exit  Close the notification on command exit.\n"
@@ -172,11 +182,12 @@ int main(int argc, char *argv[])
 	while (1) {
 		static struct option long_options[] = {
 			{"help", no_argument, 0, 'h'},
+			{"version", no_argument, 0, 'v'},
 			{"close-on-exit", no_argument, 0, 'C'},
 			{0, 0, 0, 0},
 		};
 
-		c = getopt_long(argc, argv, "hCc:r:", long_options, &option_index);
+		c = getopt_long(argc, argv, "hvCc:r:", long_options, &option_index);
 
 		if (c == -1) {
 			break;
@@ -186,7 +197,9 @@ int main(int argc, char *argv[])
 		case 'h':
 			print_help();
 			return EXIT_SUCCESS;
-
+		case 'v':
+			print_version();
+			return EXIT_SUCCESS;
 		case 'C':
 			state.close_on_exit = 1;
 			break;