Personally, I'm using getopt, not getopts, in a function called option_handling, see my shell-script-template herebelow.
If you want to pass args with your options you can:
Let's say your option is -z 'something'...
[...] --options hVvz: [...] -z)args="$2"; shift2;; You want to hab a look at /usr/share/doc/util-linux/examples/getopt-parse.bash --that should come preinstalled.
Here's the template: