#!/bin/bash ## ## -h, --help Prints this help message ## ## Run with no arguments to see available commands ## fullprogrampath="$(realpath $0)" PROGRAM="$(basename $0)" descriptionString="Arching Kaos CLI" source $AK_LIBDIR/_ak_log source $AK_LIBDIR/_ak_script if [ $# -eq 0 ] then logit "WARNING" "No command given" ( find $AK_BINDIR | grep 'ak-' | while read available do #subcmd="$(basename $available | cut -d '-' -f 2)" subcmd="$(basename $available)" args="-h" if [ -n "$subcmd" ] then echo $subcmd | cut -d '-' -f 2 | sort | uniq | sed -e 's/^/ak /g' #$(echo $subcmd) $args fi done ) | sort | uniq exit 1 fi if [ $# -eq 1 ] then case "$1" in -h|--help) _ak_title_description _ak_help exit 1 esac fi subcmd="$(echo $* | sed -e 's/ /-/g')" if [ -f "$AK_BINDIR/ak-$subcmd" ] then $(echo ak-$subcmd) _ak_exit_program $? "ak-$subcmd command finished"; else argc=$# argv="$*" counter=1 while [ $counter -lt $argc ] do subcmd="$(echo $argv | cut -d ' ' -f -$counter | sed -e 's/ /\-/g')" args="$(echo "$argv"| cut -d ' ' -f $(($counter + 1))-)" if [ -n "$subcmd" ] && [ -f "$AK_BINDIR/ak-$subcmd" ] then logit "INFO" "Running: ak-$subcmd with args: $args" $(echo ak-$subcmd) $args _ak_exit_program $? "ak-$subcmd command finished"; fi counter=$(($counter + 1)) done find $AK_BINDIR | while read available do echo $(basename $available) |\ grep ak-$(echo $argv | cut -d ' ' -f 1) |\ sed -e 's/-/ /g' done logit "ERROR" "Unknown subcommand: $*" exit 1 fi