I am writing scripts with the following boilerplate CLI pattern:
usage(){
echo "$0 yada yada"
...
echo
}
for arg in "$@"; do
case "$arg" in
'--help|-help') set -- "$@" '-h';;
...
esac
done
OPTIND=1
while getopts 'h...' opt; do
case "$opt" in
'h') usage; exit 0;;
...
esac
done
shift $((OPTIND-1))
Is there any way to compress or encapsulate this in BASH on linux with other tools, perhaps an additional dependency?