Changed option handling to getopts shell-builtin
The long option support, made available through the Linux version of getopt, is incompatible with BSD getopt, found on macOS and OpenBSD. So I decided to keep it simple and support single-letter options only.
This commit is contained in:
parent
c83be332d5
commit
9a754c83fa
59
mkproj.sh
59
mkproj.sh
@ -29,29 +29,50 @@ check_gitroot() {
|
||||
|
||||
progname=${0##*/}
|
||||
|
||||
# argument normalizing; use colon for required arg,
|
||||
# double colon for optional arg.
|
||||
TEMP=$(getopt -o dfGg:lst:v --long default,filter,gitfav,gitroot,library,simple,tplroot,version -n "$progname" -- "$@")
|
||||
[ $? -eq 0 ] || die "invalid arguments"
|
||||
eval set -- "$TEMP"
|
||||
|
||||
# option processing
|
||||
while true
|
||||
# option processing, using silent mode
|
||||
while getopts :dfGg:lst:v opt
|
||||
do
|
||||
case "$1" in
|
||||
-d | --default ) default=1 ; shift ;;
|
||||
-f | --filter ) mainfile=filter.cpp ; shift ;;
|
||||
-G | --gitfav ) gitfav=1 ; shift ;;
|
||||
-g | --gitroot ) gitroot="$2" ; usegitroot=1 ; shift 2 ;;
|
||||
-l | --library ) library=1 ; shift ;;
|
||||
-s | --simple ) simple=1 ; shift ;;
|
||||
-t | --tplroot ) tplroot="$2" ; shift 2 ;;
|
||||
-v | --version ) echo "$progname version 2.0.0" ; exit 0 ;;
|
||||
-- ) shift ; break ;;
|
||||
* ) break ;;
|
||||
case $opt in
|
||||
d)
|
||||
default=1
|
||||
;;
|
||||
f)
|
||||
mainfile=filter.cpp
|
||||
;;
|
||||
G)
|
||||
gitfav=1
|
||||
;;
|
||||
g)
|
||||
gitroot=$OPTARG
|
||||
usegitroot=1
|
||||
;;
|
||||
l)
|
||||
library=1
|
||||
;;
|
||||
s)
|
||||
simple=1
|
||||
;;
|
||||
t)
|
||||
tplroot=$OPTARG
|
||||
;;
|
||||
v)
|
||||
echo "$progname version 2.0.0"
|
||||
exit 0
|
||||
;;
|
||||
\?)
|
||||
msg "invalid option -$OPTARG"
|
||||
usage
|
||||
;;
|
||||
:)
|
||||
msg "option -$OPTARG needs argument"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# leave only file arguments
|
||||
shift $(( OPTIND - 1 ))
|
||||
|
||||
[ $# -gt 0 ] || usage
|
||||
[ -n "$tplroot" ] || die "no template root directory defined"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user