From 035397e87f8a88fb37f27ddd19b9ca12465b57c6 Mon Sep 17 00:00:00 2001 From: Richard Alpe Date: Mon, 21 Aug 2023 09:47:36 +0200 Subject: [PATCH] cli: add color to state in show interfaces Signed-off-by: Richard Alpe --- board/netconf/rootfs/lib/infix/json-cfg-pretty | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/board/netconf/rootfs/lib/infix/json-cfg-pretty b/board/netconf/rootfs/lib/infix/json-cfg-pretty index e8f5463a..fbd531ba 100755 --- a/board/netconf/rootfs/lib/infix/json-cfg-pretty +++ b/board/netconf/rootfs/lib/infix/json-cfg-pretty @@ -1,6 +1,8 @@ #!/bin/bash CYAN='\033[0;36m' # Used in headers +RED='\033[0;31m' +GREEN='\033[0;32m' NC='\033[0m' # No Color usage() { @@ -64,9 +66,16 @@ show_ietf_interfaces() { printf "${CYAN}%-15s %-15s %-18s %s${NC}\n" "NAME" "STATE" "MAC" "IPv4" for iface in $interfaces; do name="$(echo "$iface" | jq -r '.["name"]')" - status="$(echo "$iface" | jq -r '.["oper-status"]')" + state="$(echo "$iface" | jq -r '.["oper-status"]')" mac="$(echo "$iface" | jq -r '.["phys-address"]')" - printf "%-15s %-15s %-18s " "$name" "$status" "$mac" + state_color="" + + if [ "$state" = "up" ]; then + state_color="$GREEN" + elif [ "$state" = "down" ]; then + state_color="$RED" + fi + printf "%-15s ${state_color}%-15s${NC} %-18s " "$name" "$state" "$mac" addresses=$(echo "$iface" | jq -c --arg field "$field" '.["ietf-ip:ipv4"].address[]' 2>/dev/null) first="true"