#!/bin/bash
source "$(dirname ${BASH_SOURCE[0]})/config.sh"



# Retrieves the configuration for a specified network interface to stdout in json format
# The function takes a dynamic configuration path and an interface name as arguments.
# If any error occures, it prints error message to stderr and help to stdout, then terminates the process
function show() {
    local dynamic_config_path="${1}"
    shift
    local pos_args=("${@}")
    if [[ ${#pos_args[@]} -gt 1 ]]; then
        echo "ipman show has maximun one argument: <interface-name>"
        return 1;
    fi
    if ! config_data=$(ipman_read_config "${dynamic_config_path}"); then
        echo "Status command failed! Reason: Dynamic config read failed."
        return 1
    fi

    if [[ ${#pos_args[@]} -eq 0 ]]; then
        echo "${config_data}"
        return 0;
    fi

    local interface_name="${pos_args[0]}"

    ipman_get_interface_config "${interface_name}" "${config_data}"
}

show "${@}"