chiark / gitweb /
udevadm,scsi_id: add short options to help strings and to the man page
[elogind.git] / src / udev / udevadm-test.c
index 2d8aa7913e517cde70705a2df3b4aa26953762a4..cd75fad674dd72dbdf5ef400d381bc7d10dae037 100644 (file)
@@ -43,7 +43,7 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
         struct udev_list_entry *entry;
         sigset_t mask, sigmask_orig;
         int err;
-        int rc = 0;
+        int rc = 0, c;
 
         static const struct option options[] = {
                 { "action", required_argument, NULL, 'a' },
@@ -54,23 +54,17 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
 
         log_debug("version %s\n", VERSION);
 
-        for (;;) {
-                int option;
-
-                option = getopt_long(argc, argv, "a:s:N:fh", options, NULL);
-                if (option == -1)
-                        break;
-
-                switch (option) {
+        while((c = getopt_long(argc, argv, "a:N:h", options, NULL)) >= 0)
+                switch (c) {
                 case 'a':
                         action = optarg;
                         break;
                 case 'N':
-                        if (strcmp (optarg, "early") == 0) {
+                        if (streq (optarg, "early")) {
                                 resolve_names = 1;
-                        } else if (strcmp (optarg, "late") == 0) {
+                        } else if (streq (optarg, "late")) {
                                 resolve_names = 0;
-                        } else if (strcmp (optarg, "never") == 0) {
+                        } else if (streq (optarg, "never")) {
                                 resolve_names = -1;
                         } else {
                                 fprintf(stderr, "resolve-names must be early, late or never\n");
@@ -80,15 +74,18 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
                         break;
                 case 'h':
                         printf("Usage: udevadm test OPTIONS <syspath>\n"
-                               "  --action=<string>     set action string\n"
-                               "  --help\n\n");
+                               "  -a,--action=ACTION                  set action string\n"
+                               "  -N,--resolve-names=early|late|never when to resolve names\n"
+                               "  -h,--help                           print this help string\n"
+                               "\n");
                         exit(EXIT_SUCCESS);
-                default:
+                case '?':
                         exit(EXIT_FAILURE);
+                default:
+                        assert_not_reached("Unknown option");
                 }
-        }
-        syspath = argv[optind];
 
+        syspath = argv[optind];
         if (syspath == NULL) {
                 fprintf(stderr, "syspath parameter missing\n");
                 rc = 2;
@@ -113,9 +110,9 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
 
         /* add /sys if needed */
         if (!startswith(syspath, "/sys"))
-                util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL);
+                strscpyl(filename, sizeof(filename), "/sys", syspath, NULL);
         else
-                util_strscpy(filename, sizeof(filename), syspath);
+                strscpy(filename, sizeof(filename), syspath);
         util_remove_trailing_chars(filename, '/');
 
         dev = udev_device_new_from_syspath(udev, filename);