cli: add color to state in show interfaces

Signed-off-by: Richard Alpe <richard@bit42.se>
This commit is contained in:
Richard Alpe
2023-08-23 14:45:38 +02:00
committed by Tobias Waldekranz
parent 03f99d7252
commit 035397e87f
+11 -2
View File
@@ -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"