tl;dr

while getopts "hvf:" flag; do
 case $flag in
   h) # Handle the -h flag
   # Display script help information
   ;;
   v) # Handle the -v flag
   # Enable verbose mode
   ;;
   f) # Handle the -f flag with an argument
   filename=$OPTARG
   # Process the specified file
   ;;
   \?)
   # Handle invalid options
   ;;
 esac
done

Source: https://medium.com/@wujido20/handling-flags-in-bash-scripts-4b06b4d0ed04