I have got few methods (for example: addUser, addProject, addRepository). In all of them i am using curl option and they have specified local(another) variables. In first function I can have:
addUser{
username
user
password
email}
Second method has got just the name of the project and in the third method (addRepository):
addRepository{
nameOfProject
nameOfRepository}
My question is how to connect it with getopts? Shouild i do in all of the functions getopts or just make one getopts outside of any function and add parameters?
My idea was:
while getopts ":p:,:a:b:,:c:d:e:f:" option;
do
case $option in
#p=nameOfProject - addProject method
p)
p="$OPTARG"
addProject_usage
;;
#a=nameOfProject - addRepository method
a)
a="$OPTARG"
addRepository_usage
;;
#b=nameOfRepository - addRepository method
b)
b="$OPTARG"
addRepository_usage
;;
// c.d.e.f like p,a,b)
\?) echo "Error: Invalid option -$OPTARG"
exit 1
;;
esac
done
shift $((OPTIND-1))
Of course there should be functions like:
addProject_usage() { echo "addProject: [-p <string>]" 1>&2; exit; }
addRepository_usage() { echo "addRepository: [-a <string>] [-b <string>]" 1>&2; exit; }
addUser_usage ...
Plus instances of methods i mean - but I am not sure:
addProject -p "$p"
addRepository -a "$a" -b "$b"
addUser ...
Am I thinking in a good way ? If not please give me some advice. I am new to scripting. Thank you!