[email_account] Use getopt to parse options
- Parse options using getopts - Delete --help option
This commit is contained in:
parent
068d816a82
commit
5fe150c2a8
|
@ -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,30 +82,42 @@ 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
|
||||
usage $(basename "$0")
|
||||
exit 0 ;;
|
||||
esac
|
||||
done
|
||||
if [ $# -eq 1 -a -z "$1" ]
|
||||
then
|
||||
usage $(basename "$0")
|
||||
exit 0
|
||||
fi
|
||||
if [ $# -gt $((OPTIND+1)) ]
|
||||
then
|
||||
echo "Error! Too many arguments." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$1" -o "$1" = "-h" -o "$1" = "-help" ]
|
||||
# Test email arguments
|
||||
eval test_email "\$$OPTIND"
|
||||
emailuser="$user"
|
||||
emaildomain="$domain"
|
||||
if [ $# -eq $((OPTIND+1)) ]
|
||||
then
|
||||
usage $(basename $0)
|
||||
exit 0
|
||||
else
|
||||
# Test email arguments
|
||||
test_email "$1"
|
||||
emailuser="$user"
|
||||
emaildomain="$domain"
|
||||
if [ $# -eq 2 ]
|
||||
eval test_email "\$$((OPTIND+1))"
|
||||
aliasuser="$user"
|
||||
aliasdomain="$domain"
|
||||
if [ "$emaildomain" != "$aliasdomain" ]
|
||||
then
|
||||
test_email "$2"
|
||||
aliasuser="$user"
|
||||
aliasdomain="$domain"
|
||||
if [ "$emaildomain" != "$aliasdomain" ]
|
||||
then
|
||||
echo "Error! Domain of the alias must be identical to the domain of the email account." >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Error! Domain of the alias must be identical to the domain of the email account." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue