[email_account] Use getopt to parse options

- Parse options using getopts
- Delete --help option
This commit is contained in:
Thomas Preud'homme 2010-01-26 19:14:51 +01:00 committed by Thomas Preud'homme
parent 068d816a82
commit 5fe150c2a8
1 changed files with 31 additions and 19 deletions

View File

@ -29,7 +29,7 @@ usage ()
echo "Usage :"
echo
echo "$progname emailaccount [emailalias]"
echo "$progname -h | --help"
echo "$progname -h"
echo
echo "Fist form adds an email account named emailaccount if it doesn't already exist"
echo "and creates an alias named emailalias for this email account if specified."
@ -82,23 +82,36 @@ ask_user_default_no ()
test_args ()
{
local - user domain
if [ \( $# -gt 1 -a "$1" = "-h" \) -o $# -gt 2 ]
while getopts "h" opt
do
case $opt in
"h")
if [ $# -gt 1 ]
then
echo "Error! Too many arguments." >&2
exit 1
fi
if [ -z "$1" -o "$1" = "-h" -o "$1" = "-help" ]
usage $(basename "$0")
exit 0 ;;
esac
done
if [ $# -eq 1 -a -z "$1" ]
then
usage $(basename $0)
usage $(basename "$0")
exit 0
else
fi
if [ $# -gt $((OPTIND+1)) ]
then
echo "Error! Too many arguments." >&2
exit 1
fi
# Test email arguments
test_email "$1"
eval test_email "\$$OPTIND"
emailuser="$user"
emaildomain="$domain"
if [ $# -eq 2 ]
if [ $# -eq $((OPTIND+1)) ]
then
test_email "$2"
eval test_email "\$$((OPTIND+1))"
aliasuser="$user"
aliasdomain="$domain"
if [ "$emaildomain" != "$aliasdomain" ]
@ -107,7 +120,6 @@ test_args ()
exit 1
fi
fi
fi
}
# Are we root?