#!/usr/bin/env bash
# Wrapper to start tool of the VILLASnode suite
#
# This allows you to use VILLASnode tools like this:
#    $ villas node /etc/villas/test.cfg
#
# Install by:
#    $ make install
#
# Author: Steffen Vogel <post@steffenvogel.de>
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
# SPDX-License-Identifier: Apache-2.0

# Get a list of all available tools
SUBTOOLS="api node compare pipe hook conf2json convert graph relay signal test-config test-rtt zmq-keygen"

# First argument to wrapper is the tool which should be started
SUBTOOL=$1

# Following arguments will be passed directly to tool
ARGS=${@:2}

# Check if tool is available
if ! echo ${SUBTOOLS} | grep -wqFe "${SUBTOOL}"; then
    echo "Usage: villas [-h | --help | TOOL]"
    echo "  TOOL     is one of ${SUBTOOLS}"
    echo
    echo "For detailed documentation, please see: 'villas node'"
    echo "  http://villas.fein-aachen.org/doc/"
    echo

    # Show VILLASnode copyright and contact info
    villas-node -h | tail -n3
    echo "-h" "--help" | grep -wqFe "${SUBTOOL}"
    exit $?
fi

exec villas-${SUBTOOL} ${ARGS}
