aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-06-08 05:13:54 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-06-08 05:13:54 +0200
commitddccda603dc56d94eaa81775859ddd9d0a29ce06 (patch)
treee96a2149ec4f711f1e6edab399448b3b91d731ef
parent23bd461efadf946c5266a535a9bc3294e2ca7147 (diff)
downloadltask-ddccda603dc56d94eaa81775859ddd9d0a29ce06.tar.gz
refactor
-rwxr-xr-xltask59
1 files changed, 26 insertions, 33 deletions
diff --git a/ltask b/ltask
index c75be20..d9a8b6a 100755
--- a/ltask
+++ b/ltask
@@ -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