about summary refs log tree commit diff
diff options
context:
space:
mode:
authorclassabbyamp <void@placeviolette.net>2022-08-12 03:11:24 -0400
committerLeah Neukirchen <leah@vuxu.org>2022-08-13 15:19:57 +0200
commite3e776ae0c6d6d8b74810dc381cbb621c635e184 (patch)
treed219fc6a3e502469f5beec5ac4ccab7125e455b9
parent6c224dbedf9f8eb24d77ccad54590426884062b7 (diff)
downloadxtools-e3e776ae0c6d6d8b74810dc381cbb621c635e184.tar.gz
xtools-e3e776ae0c6d6d8b74810dc381cbb621c635e184.tar.xz
xtools-e3e776ae0c6d6d8b74810dc381cbb621c635e184.zip
xgensum: use getopts for argument parsing, update completions
Closes: #256 [via git-merge-pr]
-rw-r--r--_xtools3
-rwxr-xr-xxgensum36
2 files changed, 20 insertions, 19 deletions
diff --git a/_xtools b/_xtools
index aed7f86..42b2dc1 100644
--- a/_xtools
+++ b/_xtools
@@ -51,10 +51,11 @@ _xdowngrade() {
 }
 
 _xgensum() {
-	_arguments : \
+	_arguments -s : \
 		'-f[force downloading of files]' \
 		'-c[use content checksum]' \
 		'-i[substitute in-place]' \
+		'-H[Absolute path to hostdir]:hostdir:_files -/' \
 		':available templates:_path_files -g "*(/)|template(N)"'
 }
 
diff --git a/xgensum b/xgensum
index a55ab56..7430fc3 100755
--- a/xgensum
+++ b/xgensum
@@ -1,21 +1,22 @@
 #!/bin/bash
 # xgensum [-f] [-c] [-i] [-H hostdir] TEMPLATE - update SHA256 sums in templates
 
-case "$1" in
-	-f) FLAG_f=$1; shift
-esac
-
-case "$1" in
-	-c) FLAG_c=$1; shift
-esac
-
-case "$1" in
-	-i*) FLAG_i=$1; shift
-esac
+usage() {
+	echo 'Usage: xgensum [-f] [-c] [-i] [-H hostdir] TEMPLATE' 1>&2
+	exit 1
+}
+
+while getopts fciH:h flag; do
+	case $flag in
+		f) FLAG_f=1 ;;
+		c) FLAG_c=1 ;;
+		i) FLAG_i='-i' ;;
+		H) FLAG_h="-H $OPTARG" ;;
+		h|?) usage ;;
+	esac
+done
 
-case "$1" in
-	-H*) FLAG_h="-H $2"; shift; shift
-esac
+shift $(( OPTIND - 1 ))
 
 XBPS_DISTDIR=$(xdistdir) || exit 1
 
@@ -26,8 +27,7 @@ elif [ -f "$1/template" ]; then
 elif [ -f "$XBPS_DISTDIR/srcpkgs/$1/template" ]; then
 	template="$XBPS_DISTDIR/srcpkgs/$1/template"
 else
-	echo 'Usage: xgensum [-f] [-c] [-i] [-H hostdir] TEMPLATE' 1>&2
-	exit 1
+	usage
 fi
 
 . "$template"
@@ -47,7 +47,7 @@ fi
 XBPS_SRCDISTDIR=$("$XBPS_DISTDIR/xbps-src" $FLAG_h show-var XBPS_SRCDISTDIR | tail -1)
 srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
 
-if [ "$FLAG_f" = -f ]; then
+if [ -n "$FLAG_f" ]; then
 	for f in $distfiles; do
 		curfile="${f#*>}"
 		curfile="${curfile##*/}"
@@ -65,7 +65,7 @@ for f in $distfiles; do
 	curfile="${f#*>}"
 	curfile="${curfile##*/}"
 	distfile="$srcdir/$curfile"
-	if [ "$FLAG_c" = -c ];then
+	if [ -n "$FLAG_c" ];then
 		sum="@"
 		case ${distfile} in
 		*tar.lzma|*.tar|*.txz|*.tar.xz|*.tbz|*.tar.gz)