diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2020-06-08 05:13:54 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2020-06-08 05:13:54 +0200 |
commit | ddccda603dc56d94eaa81775859ddd9d0a29ce06 (patch) | |
tree | e96a2149ec4f711f1e6edab399448b3b91d731ef | |
parent | 23bd461efadf946c5266a535a9bc3294e2ca7147 (diff) | |
download | ltask-ddccda603dc56d94eaa81775859ddd9d0a29ce06.tar.gz |
refactor
-rwxr-xr-x | ltask | 59 |
1 files changed, 26 insertions, 33 deletions
@@ -49,32 +49,6 @@ function perror() { echo -e $@ 1>&2 } -function parse_args() { - for (( i=0; i < $ARGC;i++ )); do - local ARGREGEX="^-.*" - if [[ ! ${ARGV[$i]} =~ $ARGREGEX ]]; then - [ -z $TASK ] && TASK=${ARGV[$i]} && continue - [ -z $TARGET ] && TARGET=${ARGV[$i]} && continue - - print_help 1 - fi - - case ${ARGV[$i]} in - -H) - i=$((i+1)) - HOSTS+=(${ARGV[$i]});; - -p) - PARALLEL="yes";; - -h) - print_help 0;; - *) - echo Invalid Argument ${ARGV[$i]} - echo $0 -h for help - exit 1;; - esac - done -} - selector() { local regex="^-?[0-9]+\$" @@ -107,7 +81,32 @@ EOF exit $1 } -function interactive() { +#Parse args +for (( i=0; i < $ARGC;i++ )); do + ARGREGEX="^-.*" + if [[ ! ${ARGV[$i]} =~ $ARGREGEX ]]; then + [ -z $TASK ] && TASK=${ARGV[$i]} && continue + [ -z $TARGET ] && TARGET=${ARGV[$i]} && continue + + print_help 1 + fi + + case ${ARGV[$i]} in + -H) + i=$((i+1)) + HOSTS+=(${ARGV[$i]});; + -p) + PARALLEL="yes";; + -h) + print_help 0;; + *) + echo Invalid Argument ${ARGV[$i]} + echo $0 -h for help + exit 1;; + esac +done + +if [ -z $TASK ]; then TASK_LIST=( $(ls $TASK_DIR) ) TARGET_LIST=( $(ls $TARGET_DIR) ) @@ -118,12 +117,6 @@ function interactive() { perror "\nSelect a Target" >&2 selector ${TARGET_LIST[@]} TARGET=${TARGET_LIST[$?]} -} - -parse_args - -if [ -z $TASK ]; then - interactive fi unset TASK_ISSET |