]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
color: disable color when json output is requested
authorVincent Bernat <vincent@bernat.im>
Tue, 20 Feb 2018 23:28:04 +0000 (00:28 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 23 Feb 2018 16:18:33 +0000 (08:18 -0800)
Instead of declaring -color and -json exclusive, ignore -color when
-json is provided. The rationale is to allow to put -color in an alias
for ip while still being able to use -json. -color is merely a
presentation suggestion and we can assume there is nothing to color in
the JSON output.

Signed-off-by: Vincent Bernat <vincent@bernat.im>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
include/color.h
ip/ip.c
lib/color.c

index f6c351b7774674c555c599eb6b0ffa0170746086..c80359d3e2e95d6fd5ebe9cd4674e5e3847d04f6 100644 (file)
@@ -13,7 +13,6 @@ enum color_attr {
 };
 
 void enable_color(void);
-void check_if_color_enabled(void);
 void set_color_palette(void);
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...);
 enum color_attr ifa_family_color(__u8 ifa_family);
diff --git a/ip/ip.c b/ip/ip.c
index ee0d6346b275e8aea3ebad68e90b78c321d712f4..e0cd96cb1c15975f3f14745dd57c9cffe486719f 100644 (file)
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -172,6 +172,7 @@ int main(int argc, char **argv)
 {
        char *basename;
        char *batch_file = NULL;
+       int color = 0;
 
        basename = strrchr(argv[0], '/');
        if (basename == NULL)
@@ -269,7 +270,7 @@ int main(int argc, char **argv)
                        }
                        rcvbuf = size;
                } else if (matches(opt, "-color") == 0) {
-                       enable_color();
+                       ++color;
                } else if (matches(opt, "-help") == 0) {
                        usage();
                } else if (matches(opt, "-netns") == 0) {
@@ -289,8 +290,8 @@ int main(int argc, char **argv)
 
        _SL_ = oneline ? "\\" : "\n";
 
-       if (json)
-               check_if_color_enabled();
+       if (color && !json)
+               enable_color();
 
        if (batch_file)
                return batch(batch_file);
index a13a4930b10c11aca902b61ff1f73c39dbd3bf7f..da1f516cb2492f1c4515274c741218951b969a63 100644 (file)
@@ -92,14 +92,6 @@ void set_color_palette(void)
                is_dark_bg = 1;
 }
 
-void check_if_color_enabled(void)
-{
-       if (color_is_enabled) {
-               fprintf(stderr, "Option \"-json\" conflicts with \"-color\".\n");
-               exit(1);
-       }
-}
-
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...)
 {
        int ret = 0;