]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
color: Introduce and use default_color_opt() function
authorBen Hutchings <benh@debian.org>
Wed, 19 Mar 2025 21:51:01 +0000 (22:51 +0100)
committerDavid Ahern <dsahern@kernel.org>
Mon, 24 Mar 2025 02:50:50 +0000 (02:50 +0000)
As a preparatory step for supporting the NO_COLOR environment
variable, replace the direct use of CONF_COLOR with a
default_color_opt() function which initially returns CONF_COLOR.

Signed-off-by: Ben Hutchings <benh@debian.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
bridge/bridge.c
include/color.h
ip/ip.c
lib/color.c
tc/tc.c

index f8b5646af88d408bef78f25dd47140542359b183..d993ba194f34e0389c90675d4ffa4d1cdc94c9c6 100644 (file)
@@ -103,7 +103,7 @@ static int batch(const char *name)
 int
 main(int argc, char **argv)
 {
-       int color = CONF_COLOR;
+       int color = default_color_opt();
 
        while (argc > 1) {
                const char *opt = argv[1];
index 17ec56f3d7b4716ad085fb46a66aa13c66106480..b543c267e828a900da704bb42e7ec0532860c25b 100644 (file)
@@ -20,6 +20,7 @@ enum color_opt {
        COLOR_OPT_ALWAYS = 2
 };
 
+int default_color_opt(void);
 bool check_enable_color(int color, int json);
 bool matches_color(const char *arg, int *val);
 int color_fprintf(FILE *fp, enum color_attr attr, const char *fmt, ...);
diff --git a/ip/ip.c b/ip/ip.c
index c7151fbdc798fe0a62e25b2b6ae1fcb1c620daae..e4b71bde94b4b92f1051412599bfa45daac3074d 100644 (file)
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -166,7 +166,7 @@ int main(int argc, char **argv)
        const char *libbpf_version;
        char *batch_file = NULL;
        char *basename;
-       int color = CONF_COLOR;
+       int color = default_color_opt();
 
        /* to run vrf exec without root, capabilities might be set, drop them
         * if not needed as the first thing.
index cd0f9f7509b5f73598ae794c0c6bfec16d49a254..5c4cc3294e48d98bf81666a32395caeed3f3bb2c 100644 (file)
@@ -81,6 +81,11 @@ static void enable_color(void)
        set_color_palette();
 }
 
+int default_color_opt(void)
+{
+       return CONF_COLOR;
+}
+
 bool check_enable_color(int color, int json)
 {
        if (json || color == COLOR_OPT_NEVER)
diff --git a/tc/tc.c b/tc/tc.c
index beb88111dc7925b4f836118aca5059de6952e022..0fc658c881f0f553f1f1f8d87b46943d4d0eed8f 100644 (file)
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -254,7 +254,7 @@ int main(int argc, char **argv)
 {
        const char *libbpf_version;
        char *batch_file = NULL;
-       int color = CONF_COLOR;
+       int color = default_color_opt();
        int ret;
 
        while (argc > 1) {