#!/pkg/bin/ksh
# ---------------------------------------------------------------------
# isis_show_lslib - Show lslib cache information for isis
#
# September 2022, Paul Wells
#
# Copyright (c) 2022 by cisco Systems, Inc.
# All rights reserved.
#--------------------------------------------------------------------

. /pkg/bin/isis_show_functions

__line_length=79

usage() {
  echo "Usage: $0 [-Z instance ] {-a -c}" 1>&2
  exit 1
}

#
# Define a shell-function for every action we can take.
#
show_lslib_one() {
    lslib_show_cmd -P isis -I $1 -A -D
}

show_lslib_all() {
    print_command_heading "IS-IS $1 lslib cache"
    lslib_show_cmd -P isis -I $1 -A -D
}

#
# Parse the command-line parameters.
#
while [ "$#" -gt "0" ]; do
    case "$1" in
        -Z) instance="$2"; shift 2;;
        -a) cmd="-a"; shift 1;;
        -c) cmd="-c"; shift 1;;
         *) usage;;
    esac
done

#
# Determine the process-ids and instance-names of the isis processes.
#
if [ -z "$instance" ]; then
    inst_str=`isis_show -f 0x0 | grep "IS-IS Router:" | sed s/"IS-IS Router:"// `
else
    inst_str="$instance"
fi

if [ -z "$inst_str" ]; then
    echo "Can not determine IS-IS Instance name."
    exit 1
fi

inst_array=($inst_str)

#
# Call the requested script.
#
for i in "${!inst_array[@]}"
do
    case "$cmd" in
        -c) show_lslib_one ${inst_array[i]};;
        -a) show_lslib_all ${inst_array[i]};;
    esac
done

