]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm: getopt() and help message cleanup
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 5 Dec 2017 14:30:10 +0000 (23:30 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 5 Dec 2017 14:30:10 +0000 (23:30 +0900)
This adds missing options, mainly '--version' in getopt(), removes
an unused option from getopt().
Also, this adds a deprecate message in `udevadm hwdb`, and cleanups
help messages.

Follow-up for 65eb4378c3e1de25383d8cd606909e64c71edc80.

src/udev/udevadm-control.c
src/udev/udevadm-hwdb.c
src/udev/udevadm-info.c
src/udev/udevadm-monitor.c
src/udev/udevadm-settle.c
src/udev/udevadm-test-builtin.c
src/udev/udevadm-test.c
src/udev/udevadm-trigger.c
src/udev/udevadm-util.h

index a10621a468a6bd59a95c5560665561703d5f608f..ab9237ff7857010610a03e1179cfe50ef8abb2f3 100644 (file)
 #include "time-util.h"
 #include "udev-util.h"
 #include "udev.h"
+#include "udevadm-util.h"
 
 static void print_help(void) {
-        printf("%s control COMMAND\n\n"
+        printf("%s control OPTION\n\n"
                "Control the udev daemon.\n\n"
                "  -h --help                Show this help\n"
-               "     --version             Show package version\n"
+               "  -V --version             Show package version\n"
                "  -e --exit                Instruct the daemon to cleanup and exit\n"
                "  -l --log-priority=LEVEL  Set the udev log level for the daemon\n"
                "  -s --stop-exec-queue     Do not execute events, queue only\n"
@@ -57,6 +58,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
                 { "env",              required_argument, NULL, 'p' }, /* alias for -p */
                 { "children-max",     required_argument, NULL, 'm' },
                 { "timeout",          required_argument, NULL, 't' },
+                { "version",          no_argument,       NULL, 'V' },
                 { "help",             no_argument,       NULL, 'h' },
                 {}
         };
@@ -70,7 +72,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
         if (uctrl == NULL)
                 return 2;
 
-        while ((c = getopt_long(argc, argv, "el:sSRp:m:h", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "el:sSRp:m:t:Vh", options, NULL)) >= 0)
                 switch (c) {
                 case 'e':
                         if (udev_ctrl_send_exit(uctrl, timeout) < 0)
@@ -153,6 +155,10 @@ static int adm_control(struct udev *udev, int argc, char *argv[]) {
                         }
                         break;
                 }
+                case 'V':
+                        print_version();
+                        rc = 0;
+                        break;
                 case 'h':
                         print_help();
                         rc = 0;
index ba7a15e6e9d07b7c9256ab3b68c86bbd6e90d2fc..ab5dc7ab6420102be14e868a125fe748854afbfb 100644 (file)
@@ -34,6 +34,7 @@
 #include "strbuf.h"
 #include "string-util.h"
 #include "udev.h"
+#include "udevadm-util.h"
 #include "util.h"
 
 /*
@@ -546,12 +547,17 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam
 }
 
 static void help(void) {
-        printf("Usage: udevadm hwdb OPTIONS\n"
-               "  -u,--update          update the hardware database\n"
-               "  --usr                generate in " UDEVLIBEXECDIR " instead of /etc/udev\n"
-               "  -t,--test=MODALIAS   query database and print result\n"
-               "  -r,--root=PATH       alternative root path in the filesystem\n"
-               "  -h,--help\n\n");
+        printf("%s hwdb [OPTIONS]\n\n"
+               "  -h --help            Print this message\n"
+               "  -V --version         Print version of the program\n"
+               "  -u --update          Update the hardware database\n"
+               "     --usr             Generate in " UDEVLIBEXECDIR " instead of /etc/udev\n"
+               "  -t --test=MODALIAS   Query database and print result\n"
+               "  -r --root=PATH       Alternative root path in the filesystem\n\n"
+               "NOTE:\n"
+               "The sub-command 'hwdb' is deprecated, and is left for backwards compatibility.\n"
+               "Please use systemd-hwdb instead.\n"
+               , program_invocation_short_name);
 }
 
 static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
@@ -560,11 +566,12 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
         };
 
         static const struct option options[] = {
-                { "update", no_argument,       NULL, 'u' },
-                { "usr",    no_argument,       NULL, ARG_USR },
-                { "test",   required_argument, NULL, 't' },
-                { "root",   required_argument, NULL, 'r' },
-                { "help",   no_argument,       NULL, 'h' },
+                { "update",  no_argument,       NULL, 'u'     },
+                { "usr",     no_argument,       NULL, ARG_USR },
+                { "test",    required_argument, NULL, 't'     },
+                { "root",    required_argument, NULL, 'r'     },
+                { "version", no_argument,       NULL, 'V'     },
+                { "help",    no_argument,       NULL, 'h'     },
                 {}
         };
         const char *test = NULL;
@@ -575,7 +582,7 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
         int err, c;
         int rc = EXIT_SUCCESS;
 
-        while ((c = getopt_long(argc, argv, "ut:r:h", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "ut:r:Vh", options, NULL)) >= 0)
                 switch(c) {
                 case 'u':
                         update = true;
@@ -589,6 +596,9 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
                 case 'r':
                         root = optarg;
                         break;
+                case 'V':
+                        print_version();
+                        return EXIT_SUCCESS;
                 case 'h':
                         help();
                         return EXIT_SUCCESS;
index b39f1a637e6118b54737c021379ab3b93a1ecef7..396ccfb4e2047baafa2c3734d9b8df0b4e1943c6 100644 (file)
@@ -377,7 +377,7 @@ static int uinfo(struct udev *udev, int argc, char *argv[]) {
                         export_prefix = optarg;
                         break;
                 case 'V':
-                        printf("%s\n", PACKAGE_VERSION);
+                        print_version();
                         return 0;
                 case 'h':
                         help();
index c8b85fb0f4c218f5d60b274ae202b539dfc47741..028ef92bc2e79ccb355fde21d1e5cc6db9d55141 100644 (file)
@@ -30,6 +30,7 @@
 #include "format-util.h"
 #include "udev-util.h"
 #include "udev.h"
+#include "udevadm-util.h"
 
 static bool udev_exit;
 
@@ -60,10 +61,10 @@ static void print_device(struct udev_device *device, const char *source, int pro
 }
 
 static void help(void) {
-        printf("%s monitor [--property] [--kernel] [--udev] [--help]\n\n"
+        printf("%s monitor [OPTIONS]\n\n"
                "Listen to kernel and udev events.\n\n"
                "  -h --help                                Show this help\n"
-               "     --version                             Show package version\n"
+               "  -V --version                             Show package version\n"
                "  -p --property                            Print the event properties\n"
                "  -k --kernel                              Print kernel uevents\n"
                "  -u --udev                                Print udev events\n"
@@ -94,6 +95,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
                 { "udev",            no_argument,       NULL, 'u' },
                 { "subsystem-match", required_argument, NULL, 's' },
                 { "tag-match",       required_argument, NULL, 't' },
+                { "version",         no_argument,       NULL, 'V' },
                 { "help",            no_argument,       NULL, 'h' },
                 {}
         };
@@ -101,7 +103,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
         udev_list_init(udev, &subsystem_match_list, true);
         udev_list_init(udev, &tag_match_list, true);
 
-        while ((c = getopt_long(argc, argv, "pekus:t:h", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "pekus:t:Vh", options, NULL)) >= 0)
                 switch (c) {
                 case 'p':
                 case 'e':
@@ -130,6 +132,9 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[]) {
                 case 't':
                         udev_list_entry_add(&tag_match_list, optarg, NULL);
                         break;
+                case 'V':
+                        print_version();
+                        return 0;
                 case 'h':
                         help();
                         return 0;
index d72b6ffe208b43d1a11f0ac8278536dbe92ce92d..0af3e6412b0c72d3be977edd67e8575dfbae221f 100644 (file)
 
 #include "parse-util.h"
 #include "udev.h"
+#include "udevadm-util.h"
 #include "util.h"
 
 static void help(void) {
-        printf("%s settle OPTIONS\n\n"
+        printf("%s settle [OPTIONS]\n\n"
                "Wait for pending udev events.\n\n"
                "  -h --help                 Show this help\n"
-               "     --version              Show package version\n"
+               "  -V --version              Show package version\n"
                "  -t --timeout=SECONDS      Maximum time to wait for events\n"
                "  -E --exit-if-exists=FILE  Stop waiting if file exists\n"
                , program_invocation_short_name);
@@ -45,6 +46,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
         static const struct option options[] = {
                 { "timeout",        required_argument, NULL, 't' },
                 { "exit-if-exists", required_argument, NULL, 'E' },
+                { "version",        no_argument,       NULL, 'V' },
                 { "help",           no_argument,       NULL, 'h' },
                 { "seq-start",      required_argument, NULL, 's' }, /* removed */
                 { "seq-end",        required_argument, NULL, 'e' }, /* removed */
@@ -59,7 +61,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
         struct udev_queue *queue;
         int rc = EXIT_FAILURE;
 
-        while ((c = getopt_long(argc, argv, "t:E:hs:e:q", options, NULL)) >= 0) {
+        while ((c = getopt_long(argc, argv, "t:E:Vhs:e:q", options, NULL)) >= 0) {
                 switch (c) {
 
                 case 't': {
@@ -77,6 +79,10 @@ static int adm_settle(struct udev *udev, int argc, char *argv[]) {
                         exists = optarg;
                         break;
 
+                case 'V':
+                        print_version();
+                        return EXIT_SUCCESS;
+
                 case 'h':
                         help();
                         return EXIT_SUCCESS;
index 2cdbec050f0309bb517a3ece115bc33bb11f873a..f5a39a11c11c7094977f0979f86fedfa6b118b13 100644 (file)
 #include "path-util.h"
 #include "string-util.h"
 #include "udev.h"
+#include "udevadm-util.h"
 
 static void help(struct udev *udev) {
-        printf("%s builtin [--help] COMMAND SYSPATH\n\n"
+        printf("%s test-builtin [OPTIONS] COMMAND DEVPATH\n\n"
                "Test a built-in command.\n\n"
                "  -h --help     Print this message\n"
-               "     --version  Print version of the program\n\n"
+               "  -V --version  Print version of the program\n\n"
                "Commands:\n"
                , program_invocation_short_name);
 
@@ -39,7 +40,8 @@ static void help(struct udev *udev) {
 
 static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
         static const struct option options[] = {
-                { "help", no_argument, NULL, 'h' },
+                { "version", no_argument, NULL, 'V' },
+                { "help",    no_argument, NULL, 'h' },
                 {}
         };
         char *command = NULL;
@@ -49,8 +51,11 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) {
         enum udev_builtin_cmd cmd;
         int rc = EXIT_SUCCESS, c;
 
-        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "Vh", options, NULL)) >= 0)
                 switch (c) {
+                case 'V':
+                        print_version();
+                        goto out;
                 case 'h':
                         help(udev);
                         goto out;
index 6d20987fa2ea5440486ee3e5bd99bc65392e10ec..ef1f2f0269a257269a6c5c6d057ca5e374e8913d 100644 (file)
 #include "string-util.h"
 #include "udev-util.h"
 #include "udev.h"
+#include "udevadm-util.h"
 
 static void help(void) {
 
-        printf("%s test OPTIONS <syspath>\n\n"
-               "Test an event run.\n"
+        printf("%s test [OPTIONS] DEVPATH\n\n"
+               "Test an event run.\n\n"
                "  -h --help                            Show this help\n"
-               "     --version                         Show package version\n"
+               "  -V --version                         Show package version\n"
                "  -a --action=ACTION                   Set action string\n"
                "  -N --resolve-names=early|late|never  When to resolve names\n"
                , program_invocation_short_name);
@@ -54,15 +55,16 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
         int rc = 0, c;
 
         static const struct option options[] = {
-                { "action", required_argument, NULL, 'a' },
+                { "action",        required_argument, NULL, 'a' },
                 { "resolve-names", required_argument, NULL, 'N' },
-                { "help", no_argument, NULL, 'h' },
+                { "version",       no_argument,       NULL, 'V' },
+                { "help",          no_argument,       NULL, 'h' },
                 {}
         };
 
         log_debug("version %s", PACKAGE_VERSION);
 
-        while ((c = getopt_long(argc, argv, "a:N:h", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "a:N:Vh", options, NULL)) >= 0)
                 switch (c) {
                 case 'a':
                         action = optarg;
@@ -80,6 +82,9 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
                                 exit(EXIT_FAILURE);
                         }
                         break;
+                case 'V':
+                        print_version();
+                        exit(EXIT_SUCCESS);
                 case 'h':
                         help();
                         exit(EXIT_SUCCESS);
index 23aaa474233f96f69a54009586c78993eaaa55cf..f78a2ba4373eb11466750831ac5dcf4c99d94791 100644 (file)
@@ -68,10 +68,10 @@ static const char *keyval(const char *str, const char **val, char *buf, size_t s
 }
 
 static void help(void) {
-        printf("%s trigger OPTIONS\n\n"
+        printf("%s trigger [OPTIONS] DEVPATH\n\n"
                "Request events from the kernel.\n\n"
                "  -h --help                         Show this help\n"
-               "     --version                      Show package version\n"
+               "  -V --version                      Show package version\n"
                "  -v --verbose                      Print the list of devices while running\n"
                "  -n --dry-run                      Do not actually trigger the events\n"
                "  -t --type=                        Type of events to trigger\n"
@@ -109,6 +109,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
                 { "sysname-match",     required_argument, NULL, 'y'      },
                 { "name-match",        required_argument, NULL, ARG_NAME },
                 { "parent-match",      required_argument, NULL, 'b'      },
+                { "version",           no_argument,       NULL, 'V'      },
                 { "help",              no_argument,       NULL, 'h'      },
                 {}
         };
@@ -124,7 +125,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
         if (udev_enumerate == NULL)
                 return 1;
 
-        while ((c = getopt_long(argc, argv, "vno:t:c:s:S:a:A:p:g:y:b:h", options, NULL)) >= 0) {
+        while ((c = getopt_long(argc, argv, "vnt:c:s:S:a:A:p:g:y:b:Vh", options, NULL)) >= 0) {
                 const char *key;
                 const char *val;
                 char buf[UTIL_PATH_SIZE];
@@ -240,6 +241,9 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
                         break;
                 }
 
+                case 'V':
+                        print_version();
+                        return 0;
                 case 'h':
                         help();
                         return 0;
index 7963acaa53e344acfa3d40d9ab0338c69e406e83..8262a8343f77b81421d9a0cb168b5403da65bb2c 100644 (file)
@@ -23,3 +23,7 @@
 struct udev_device *find_device(struct udev *udev,
                                 const char *id,
                                 const char *prefix);
+
+static inline void print_version(void) {
+        printf("%s\n", PACKAGE_VERSION);
+}