I would like to write a script that requires -c and -f where each requires an option.
When I run my script below I get some unexpected errors:
$ ./user.sh -c
./user.sh: option requires an argument -- c
Usage: user.sh -c username -f filename
   -c username
   -f SSH public key
$ ./user.sh -c gg
Error: You have not given a filename.
In the first case, I would have liked it said I am missing the option for -c and in the second case I would have liked it said I am missing -f.
Question
How do I make such error handing, and what am I doing wrong?
user.sh
#!/bin/bash                                                                                             
usage () {
    echo "Usage: user.sh -c username -f filename"
    echo "   -c username"
    echo "   -f SSH public key"
    echo ""
}
if ! [ "$*"  ]; then
    usage
    exit 1
fi
while getopts "c:f:" opt; do
    case $opt in
        c) user=$OPTARG;;
        f) filename=$OPTARG;;
        \?)
            echo
            usage
            exit 1;;
        *) echo "Internal error: Unknown option.";;
    esac
done
if ! [ $filename ]; then
    echo "Error: You have not given a filename."
    exit 1
fi
if ! [ $user ]; then
    echo "Error: You have not given an username."
    exit 1
fi