]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: use exclusive_option()
authorSami Kerola <kerolasa@iki.fi>
Thu, 14 Jun 2012 19:46:16 +0000 (21:46 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sun, 17 Jun 2012 15:59:59 +0000 (17:59 +0200)
This commit fixes exclusions which where meant to happen, but where not
successful.  For example

lsblk -r -l # did exclude
lsblk -l -r # did not exclude

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/lsblk.c

index 24fb44f6de3a477749d52f5184fca002d921d721..ec1ca37d917f1468157d994685f689b90cf7b329 100644 (file)
@@ -60,6 +60,7 @@
 #include "sysfs.h"
 #include "closestream.h"
 #include "mangle.h"
+#include "optutils.h"
 
 /* column IDs */
 enum {
@@ -1140,12 +1141,6 @@ static void __attribute__((__noreturn__)) help(FILE *out)
        exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
-static void __attribute__((__noreturn__))
-errx_mutually_exclusive(const char *opts)
-{
-       errx(EXIT_FAILURE, "%s %s", opts, _("options are mutually exclusive"));
-}
-
 static void check_sysdevblock(void)
 {
        if (access(_PATH_SYS_DEVBLOCK, R_OK) != 0)
@@ -1159,6 +1154,19 @@ int main(int argc, char *argv[])
        int tt_flags = TT_FL_TREE;
        int i, c, status = EXIT_FAILURE;
 
+       enum {
+               EXCL_NONE,
+
+               EXCL_RAW,
+               EXCL_LIST,
+               EXCL_PAIRS,
+
+               EXCL_ALL,
+               EXCL_EXCLUDE
+       };
+       int excl_rlP = EXCL_NONE;
+       int excl_ae = EXCL_NONE;
+
        static const struct option longopts[] = {
                { "all",        0, 0, 'a' },
                { "bytes",      0, 0, 'b' },
@@ -1191,6 +1199,7 @@ int main(int argc, char *argv[])
        while((c = getopt_long(argc, argv, "abdDe:fhlnmo:PirstV", longopts, NULL)) != -1) {
                switch(c) {
                case 'a':
+                       exclusive_option(&excl_ae, EXCL_ALL, "--{all,exclude}");
                        lsblk->all_devices = 1;
                        break;
                case 'b':
@@ -1207,15 +1216,14 @@ int main(int argc, char *argv[])
                        columns[ncolumns++] = COL_DZERO;
                        break;
                case 'e':
+                       exclusive_option(&excl_ae, EXCL_EXCLUDE, "--{all,exclude}");
                        parse_excludes(optarg);
                        break;
                case 'h':
                        help(stdout);
                        break;
                case 'l':
-                       if ((tt_flags & TT_FL_RAW)|| (tt_flags & TT_FL_EXPORT))
-                               errx_mutually_exclusive("--{raw,list,export}");
-
+                       exclusive_option(&excl_rlP, EXCL_LIST, "--{raw,list,pairs}");
                        tt_flags &= ~TT_FL_TREE; /* disable the default */
                        break;
                case 'n':
@@ -1229,6 +1237,7 @@ int main(int argc, char *argv[])
                                return EXIT_FAILURE;
                        break;
                case 'P':
+                       exclusive_option(&excl_rlP, EXCL_PAIRS, "--{raw,list,pairs}");
                        tt_flags |= TT_FL_EXPORT;
                        tt_flags &= ~TT_FL_TREE;        /* disable the default */
                        break;
@@ -1236,6 +1245,7 @@ int main(int argc, char *argv[])
                        tt_flags |= TT_FL_ASCII;
                        break;
                case 'r':
+                       exclusive_option(&excl_rlP, EXCL_RAW, "--{raw,list,pairs}");
                        tt_flags &= ~TT_FL_TREE;        /* disable the default */
                        tt_flags |= TT_FL_RAW;          /* enable raw */
                        break;
@@ -1288,9 +1298,7 @@ int main(int argc, char *argv[])
                columns[ncolumns++] = COL_TARGET;
        }
 
-       if (nexcludes && lsblk->all_devices)
-               errx_mutually_exclusive("--{all,exclude}");
-       else if (!nexcludes)
+       if (!nexcludes)
                excludes[nexcludes++] = 1;      /* default: ignore RAM disks */
 
        mnt_init_debug(0);