diff options
author | Christian Hesse <mail@eworm.de> | 2015-07-03 13:13:46 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2015-07-03 13:13:46 +0200 |
commit | 1c8cdb84f5f55a8e8554fb4d4a642c3da4a56053 (patch) | |
tree | 141bd2896a66ced1cea6a562b55515821fe411c1 | |
parent | 95cc0145767099d2f79fa7204363b87724d6259f (diff) | |
download | udev-block-notify-1c8cdb84f5f55a8e8554fb4d4a642c3da4a56053.tar.gz udev-block-notify-1c8cdb84f5f55a8e8554fb4d4a642c3da4a56053.tar.zst |
add --version option
-rw-r--r-- | udev-block-notify.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/udev-block-notify.c b/udev-block-notify.c index 7f30455..361204d 100644 --- a/udev-block-notify.c +++ b/udev-block-notify.c @@ -9,12 +9,13 @@ #include "config.h" #include "version.h" -const static char optstring[] = "ht:v"; +const static char optstring[] = "ht:vV"; const static struct option options_long[] = { /* name has_arg flag val */ { "help", no_argument, NULL, 'h' }, { "timeout", required_argument, NULL, 't' }, { "verbose", no_argument, NULL, 'v' }, + { "version", no_argument, NULL, 'V' }, { 0, 0, 0, 0 } }; @@ -84,22 +85,35 @@ int main (int argc, char ** argv) { struct udev_monitor *mon = NULL; struct udev *udev = NULL; + unsigned int version = 0, help = 0; + /* get the verbose status */ while ((i = getopt_long(argc, argv, optstring, options_long, NULL)) != -1) { switch (i) { case 'h': - printf("usage: %s [-h] [-t TIMEOUT] [-v]\n", argv[0]); - return EXIT_SUCCESS; + help++; + break; case 't': notification_timeout = atof(optarg) * 1000; break; case 'v': verbose++; break; + case 'V': + verbose++; + version++; + break; } } - printf("%s: %s v%s (compiled: " __DATE__ ", " __TIME__ ")\n", argv[0], PROGNAME, VERSION); + if (verbose > 0) + printf("%s: %s v%s (compiled: " __DATE__ ", " __TIME__ ")\n", argv[0], PROGNAME, VERSION); + + if (help > 0) + printf("usage: %s [-h] [-t TIMEOUT] [-v] [-V]\n", argv[0]); + + if (version > 0 || help > 0) + return EXIT_SUCCESS; if(notify_init("Udev-Block-Notification") == FALSE) { fprintf(stderr, "%s: Can't create notify.\n", argv[0]); |