From 6606ed3cd29dfac1bf4f52814152fcea3f996a1e Mon Sep 17 00:00:00 2001 From: Ben Peddell Date: Fri, 11 Dec 2015 05:36:36 +1000 Subject: [PATCH] Allow all commands to take options --- tools/arkmanager | 62 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/tools/arkmanager b/tools/arkmanager index 4547ebe..7bb5993 100755 --- a/tools/arkmanager +++ b/tools/arkmanager @@ -1456,12 +1456,51 @@ useConfig() { checkConfig while true; do - case "$1" in + options=( ) + args=( ) + command="$1" + shift + nrarg=0 + + # get the number of arguments for commands that take arguments + case "$command" in + installmod) nrarg=1; ;; + broadcast) nrarg=1; ;; + rconcmd) nrarg=1; ;; + useconfig) nrarg=1; ;; + esac + + # Enumerate the options and arguments + while [ $# -ne 0 ]; do + case "$1" in + --) + shift + break + ;; + --args) + nrarg=$# + ;; + --*) + options+=( "$1" ) + ;; + *) + if [ $nrarg -gt 0 ]; then + args+=( "$1" ) + (( nrarg-- )) + else + break + fi + ;; + esac + shift + done + + case "$command" in run) doRun ;; start) - if [ "$2" == "--all" ]; then + if [ " ${options[*]} " =~ " --all " ]; then doStartAll shift else @@ -1469,6 +1508,7 @@ while true; do fi ;; stop) + if [ " ${options[*]} " =~ " --all " ]; then if [ "$2" == "--all" ]; then doStopAll shift @@ -1477,6 +1517,7 @@ while true; do fi ;; restart) + if [ " ${options[*]} " =~ " --all " ]; then if [ "$2" == "--all" ]; then doStopAll else @@ -1484,6 +1525,7 @@ while true; do fi echo "`timestamp`: stop" >> "$logdir/$arkmanagerLog" sleep 1 + if [ " ${options[*]} " =~ " --all " ]; then if [ "$2" == "--all" ]; then doStartAll shift @@ -1497,34 +1539,27 @@ while true; do doInstall ;; update) - args=() - - while [[ "$2" =~ ^-- ]]; do - args=( "${args[@]}" "$2" ) - shift - done - - doUpdate "${args[@]}" + doUpdate "${options[@]}" ;; checkupdate) checkForUpdate ;; installmod) - doInstallMod "$2" + doInstallMod "${args[@]}" shift ;; backup) doBackup ;; broadcast) - doBroadcast "$2" + doBroadcast "${args[@]}" shift ;; saveworld) doSaveWorld ;; rconcmd) - rconcmd "$2" + rconcmd "${args[@]}" shift ;; status) @@ -1597,7 +1632,6 @@ while true; do ;; esac status=$? - shift if [ $# -eq 0 ]; then break fi