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##*/}
|
progname=${0##*/}
|
||||||
|
|
||||||
# argument normalizing; use colon for required arg,
|
# option processing, using silent mode
|
||||||
# double colon for optional arg.
|
while getopts :dfGg:lst:v opt
|
||||||
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
|
|
||||||
do
|
do
|
||||||
case "$1" in
|
case $opt in
|
||||||
-d | --default ) default=1 ; shift ;;
|
d)
|
||||||
-f | --filter ) mainfile=filter.cpp ; shift ;;
|
default=1
|
||||||
-G | --gitfav ) gitfav=1 ; shift ;;
|
;;
|
||||||
-g | --gitroot ) gitroot="$2" ; usegitroot=1 ; shift 2 ;;
|
f)
|
||||||
-l | --library ) library=1 ; shift ;;
|
mainfile=filter.cpp
|
||||||
-s | --simple ) simple=1 ; shift ;;
|
;;
|
||||||
-t | --tplroot ) tplroot="$2" ; shift 2 ;;
|
G)
|
||||||
-v | --version ) echo "$progname version 2.0.0" ; exit 0 ;;
|
gitfav=1
|
||||||
-- ) shift ; break ;;
|
;;
|
||||||
* ) break ;;
|
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
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# leave only file arguments
|
||||||
|
shift $(( OPTIND - 1 ))
|
||||||
|
|
||||||
[ $# -gt 0 ] || usage
|
[ $# -gt 0 ] || usage
|
||||||
[ -n "$tplroot" ] || die "no template root directory defined"
|
[ -n "$tplroot" ] || die "no template root directory defined"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user