]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sfdisk: add missing --color
authorKarel Zak <kzak@redhat.com>
Wed, 25 Feb 2015 11:35:45 +0000 (12:35 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 25 Feb 2015 11:37:04 +0000 (12:37 +0100)
The util already support lib/colors.c stuff, but without command line
option.

Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/sfdisk.8
disk-utils/sfdisk.c

index 4d001de6d4f1901c5dc9c4723d42779d39214be6..66a8f9955701f5bbbb57b7f93ca9155989032a5f 100644 (file)
@@ -116,6 +116,12 @@ Back up the current partition table sectors before starting the partitioning.
 The default backup file name is ~/sfdisk-<device>-<offset>.bak; to use another
 name see \fB\-\-backup\-file\fR.
 .TP
+.BR "\-\-color"[\fI=when\fR]
+Colorize the output.  The optional argument \fIwhen\fP
+can be \fBauto\fR, \fBnever\fR or \fBalways\fR.  If the \fIwhen\fR argument is omitted,
+it defaults to \fBauto\fR.  The colors can be disabled, for the current built-in default 
+see \fB\-\-help\fR output. See also the COLORS section.
+.TP
 .BR \-f , " \-\-force"
 Disable all consistency checking.
 .TP
@@ -349,6 +355,25 @@ restore sectors.
 .B dd (1)
 provides all necessary functionality.
 
+.SH COLORS
+Implicit coloring can be disabled by an empty file \fI/etc/terminal-colors.d/sfdisk.disable\fR.
+
+See
+.BR terminal-colors.d (5)
+for more details about colorization configuration. The logical color names
+supported by
+.B sfdisk
+are:
+.TP
+.B header
+The header of the output tables.
+.TP
+.B warn
+The warning messages.
+.TP
+.B welcome
+The welcome message.
+
 .SH NOTES
 Since version 2.26 \fBsfdisk\fR no longer provides the \fB\-R\fR or
 \fB\-\-re\-read\fR option to force the kernel to reread the partition table.
index bce94e5044c81e2aa8fd1479ed54dfd27fb31c37..22923a1e6b3fa9e3f747d8627f0f75c93a53cdb5 100644 (file)
@@ -186,8 +186,6 @@ static void sfdisk_init(struct sfdisk *sf)
        fdisk_init_debug(0);
        sfdiskprog_init_debug();
 
-       colors_init(UL_COLORMODE_UNDEF, "sfdisk");
-
        sf->cxt = fdisk_new_context();
        if (!sf->cxt)
                err(EXIT_FAILURE, _("failed to allocate libfdisk context"));
@@ -1340,6 +1338,9 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
        fputs(_(" -b, --backup              backup partition table sectors (see -O)\n"), out);
        fputs(_("     --bytes               print SIZE in bytes rather than in human readable format\n"), out);
        fputs(_(" -f, --force               disable all consistency checking\n"), out);
+       fputs(_("     --color[=<when>]      colorize output (auto, always or never)\n"), out);
+       fprintf(out,
+               "                             %s\n", USAGE_COLORS_DEFAULT);
        fputs(_(" -N, --partno <num>        specify partition number\n"), out);
        fputs(_(" -n, --no-act              do everything except write to device\n"), out);
        fputs(_("     --no-reread           do not check whether the device is in use\n"), out);
@@ -1367,6 +1368,7 @@ int main(int argc, char *argv[])
 {
        const char *outarg = NULL;
        int rc = -EINVAL, c, longidx = -1, bytes = 0;
+       int colormode = UL_COLORMODE_UNDEF;
        struct sfdisk _sf = {
                .partno = -1,
                .interactive = isatty(STDIN_FILENO) ? 1 : 0,
@@ -1381,7 +1383,8 @@ int main(int argc, char *argv[])
                OPT_PARTLABEL,
                OPT_PARTTYPE,
                OPT_PARTATTRS,
-               OPT_BYTES
+               OPT_BYTES,
+               OPT_COLOR
        };
 
        static const struct option longopts[] = {
@@ -1390,6 +1393,7 @@ int main(int argc, char *argv[])
                { "backup",  no_argument,       NULL, 'b' },
                { "backup-file", required_argument, NULL, 'O' },
                { "bytes",   no_argument,       NULL, OPT_BYTES },
+               { "color",   optional_argument, NULL, OPT_COLOR },
                { "dump",    no_argument,       NULL, 'd' },
                { "help",    no_argument,       NULL, 'h' },
                { "force",   no_argument,       NULL, 'f' },
@@ -1526,11 +1530,19 @@ int main(int argc, char *argv[])
                case OPT_BYTES:
                        bytes = 1;
                        break;
+               case OPT_COLOR:
+                       colormode = UL_COLORMODE_AUTO;
+                       if (optarg)
+                               colormode = colormode_or_err(optarg,
+                                               _("unsupported color mode"));
+                       break;
                default:
                        usage(stderr);
                }
        }
 
+       colors_init(colormode, "sfdisk");
+
        sfdisk_init(sf);
        if (bytes)
                fdisk_set_size_unit(sf->cxt, FDISK_SIZEUNIT_BYTES);