Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 0721e6b

Browse files
committedApr 7, 2018
argument parser upgraded
1 parent e8bba6f commit 0721e6b

File tree

4 files changed

+83
-23
lines changed

4 files changed

+83
-23
lines changed
 

‎.gitmodules

-3
This file was deleted.

‎modules/bash-argmument-parser

-1
This file was deleted.

‎p.sh

+49-19
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#!/bin/zsh
2+
# TODO task cli integration
23

34
LOC="`dirname \"$0\"`"
45
declare -a dirs
56

67
function usage {
7-
echo "usage: ProLo(ProjectLocator) [l [dirs]] [a] [0-9]"
8-
echo " [no args] show last 10 projects."
9-
echo " l goto last project you selected."
10-
echo " l dirs goto last project's sub directory."
11-
echo " a show all project directories."
12-
echo " 0-9 goto one of the project (if you know its current project id)"
13-
echo " -h display help"
14-
exit 1
8+
cat<<-EOF
9+
Locates and changes directories to your projects and does other stuffs relating to them.
10+
usage: ProLo(ProjectLocator) [l [dirs]] [a] [0-9]
11+
[no args] show last 10 projects.
12+
l goto last project you selected.
13+
l dirs goto last project's sub directory.
14+
a show all project directories.
15+
0-9 goto one of the project (if you know its current project id)
16+
-h display help
17+
EOF
18+
return;
1519
}
1620

1721

@@ -171,24 +175,50 @@ function get_project_at() {
171175

172176

173177
function isValidRange() {
178+
# TODO get range from the file
174179
if [ $1 -lt 10 ]; then
175180
return 0
176181
fi
177182
return 1
178183
}
179184

185+
186+
180187
# for i in `seq ${#DIRS[@]}`;
181188

182-
if [ -z $1 ]; then
183-
show_menu $1
184-
else
185-
case "$1" in
186-
# TODO need better argument parsing
187-
"p") get_last;;
188-
"a") show_menu ${@};;
189-
"l") gotolast `get_last` ${@:2};;
190-
''|*[0-9]*) if isValidRange $1; then get_project_at ${@:2} ; fi
189+
# start parsing args
190+
while [ "$1" != "" ]; do
191+
PARAM=`echo $1 | awk -F= '{print $1}'`
192+
VALUE=`echo $1 | awk -F= '{print $2}'`
193+
case $PARAM in
194+
-h | --help)
195+
usage
196+
exit
197+
;;
198+
p)
199+
get_last
200+
exit
201+
;;
202+
a)
203+
show_menu ${@}
204+
exit
205+
;;
206+
l)
207+
gotolast `get_last` ${@:2}
208+
exit
209+
;;
210+
*[0-9]*)
211+
if isValidRange $1; then get_project_at ${@:2}; fi
212+
exit
213+
;;
214+
t)
215+
;;
216+
*)
217+
echo "ERROR: unknown parameter \"$PARAM\""
218+
usage
219+
exit 1
220+
;;
191221
esac
192-
fi
193-
222+
shift
223+
done
194224

‎tests/argtest.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function usage() {
2+
printf "Testing Arg\n"
3+
printf "\n"
4+
printf "\t-h --help\n"
5+
printf "\t--environment=$ENVIRONMENT\n"
6+
printf "\t--db-path=$DB_PATH\n"
7+
printf "\n"
8+
}
9+
10+
echo starting test
11+
12+
while [ "$1" != "" ]; do
13+
PARAM=`echo $1 | awk -F= '{print $1}'`
14+
VALUE=`echo $1 | awk -F= '{print $2}'`
15+
case $PARAM in
16+
-h | --help)
17+
usage
18+
exit
19+
;;
20+
--environment)
21+
echo environment
22+
;;
23+
--db-path)
24+
echo dpath
25+
;;
26+
*)
27+
echo "ERROR: unknown parameter \"$PARAM\""
28+
usage
29+
exit 1
30+
;;
31+
esac
32+
shift
33+
done
34+

0 commit comments

Comments
 (0)
This repository has been archived.