]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
kjournalprint: add options for turning output colorization on and off
authorDavid Vašek <david.vasek@nic.cz>
Thu, 19 Aug 2021 09:21:55 +0000 (11:21 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Wed, 25 Aug 2021 15:22:02 +0000 (17:22 +0200)
doc/man/kjournalprint.8in
doc/man_kjournalprint.rst
src/utils/kjournalprint/main.c

index c9272869a7ea70ba4be5f3580cfa3ca95d539733..de7defd1443fa736d2d61e8e2911c176124afdc5 100644 (file)
@@ -49,9 +49,6 @@ Start at a specific SOA serial.
 \fB\-d\fP, \fB\-\-debug\fP
 Debug mode brief output.
 .TP
-\fB\-n\fP, \fB\-\-no\-color\fP
-Removes changes coloring.
-.TP
 \fB\-z\fP, \fB\-\-zone\-list\fP
 Instead of reading the journal, display the list of zones in the DB.
 (\fIzone_name\fP not needed)
@@ -59,6 +56,15 @@ Instead of reading the journal, display the list of zones in the DB.
 \fB\-c\fP, \fB\-\-check\fP
 Enable additional journal semantic checks during printing.
 .TP
+\fB\-x\fP, \fB\-\-mono\fP
+Don\(aqt generate colorized output.
+.TP
+\fB\-n\fP, \fB\-\-no\-color\fP
+An alias for \fB\-x\fP\&. Use of this option is deprecated, it will be removed in the future.
+.TP
+\fB\-X\fP, \fB\-\-color\fP
+Force colorized output.
+.TP
 \fB\-h\fP, \fB\-\-help\fP
 Print the program help.
 .TP
index 6574431e367a7bf9d5dcff446a808827afc76bcf..eb2161e4d71d2269d6e33e49a045d6f7eff982ab 100644 (file)
@@ -26,9 +26,6 @@ Options
 **-d**, **--debug**
   Debug mode brief output.
 
-**-n**, **--no-color**
-  Removes changes coloring.
-
 **-z**, **--zone-list**
   Instead of reading the journal, display the list of zones in the DB.
   (*zone_name* not needed)
@@ -36,6 +33,15 @@ Options
 **-c**, **--check**
   Enable additional journal semantic checks during printing.
 
+**-x**, **--mono**
+  Don't generate colorized output.
+
+**-n**, **--no-color**
+  An alias for **-x**. Use of this option is deprecated, it will be removed in the future.
+
+**-X**, **--color**
+  Force colorized output.
+
 **-h**, **--help**
   Print the program help.
 
index 10dbcf431e961a276cff109904d4b7c735d6ef6a..378e08fee70320f4212ffb5ef7d869efbc3842f1 100644 (file)
@@ -17,6 +17,7 @@
 #include <getopt.h>
 #include <stdlib.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 #include "libknot/libknot.h"
 #include "knot/journal/journal_basic.h"
@@ -38,11 +39,13 @@ static void print_help(void)
               "Parameters:\n"
               " -l, --limit <num>  Read only <num> newest changes.\n"
               " -s, --serial <soa> Start with a specific SOA serial.\n"
-              " -n, --no-color     Get output without terminal coloring.\n"
               " -z, --zone-list    Instead of reading the journal, display the list\n"
               "                    of zones in the DB (<zone_name> not needed).\n"
               " -c, --check        Additional journal semantic checks.\n"
               " -d, --debug        Debug mode output.\n"
+              " -x, --mono         Get output without coloring.\n"
+              " -n, --no-color     An alias for -x, deprecated.\n"
+              " -X, --color        Force output coloring.\n"
               " -h, --help         Print the program help.\n"
               " -V, --version      Print the program version.\n",
               PROGRAM_NAME);
@@ -295,7 +298,7 @@ int main(int argc, char *argv[])
 
        print_params_t params = {
                .debug = false,
-               .color = true,
+               .color = isatty(STDOUT_FILENO),
                .check = false,
                .limit = -1,
                .from_serial = false,
@@ -304,17 +307,19 @@ int main(int argc, char *argv[])
        struct option opts[] = {
                { "limit",     required_argument, NULL, 'l' },
                { "serial",    required_argument, NULL, 's' },
-               { "no-color",  no_argument,       NULL, 'n' },
                { "zone-list", no_argument,       NULL, 'z' },
                { "check",     no_argument,       NULL, 'c' },
                { "debug",     no_argument,       NULL, 'd' },
+               { "mono",      no_argument,       NULL, 'x' },
+               { "no-color",  no_argument,       NULL, 'n' },
+               { "color",     no_argument,       NULL, 'X' },
                { "help",      no_argument,       NULL, 'h' },
                { "version",   no_argument,       NULL, 'V' },
                { NULL }
        };
 
        int opt = 0;
-       while ((opt = getopt_long(argc, argv, "l:s:nzcdhV", opts, NULL)) != -1) {
+       while ((opt = getopt_long(argc, argv, "l:s:zcdxnXhV", opts, NULL)) != -1) {
                switch (opt) {
                case 'l':
                        if (str_to_int(optarg, &params.limit, 0, INT_MAX) != KNOT_EOK) {
@@ -329,9 +334,6 @@ int main(int argc, char *argv[])
                        }
                        params.from_serial = true;
                        break;
-               case 'n':
-                       params.color = false;
-                       break;
                case 'z':
                        justlist = true;
                        break;
@@ -341,6 +343,13 @@ int main(int argc, char *argv[])
                case 'd':
                        params.debug = true;
                        break;
+               case 'n':
+               case 'x':
+                       params.color = false;
+                       break;
+               case 'X':
+                       params.color = true;
+                       break;
                case 'h':
                        print_help();
                        return EXIT_SUCCESS;