Skip to contentSkip to conversation

: Use ARGS, not positional arguments

PATCH New Pavel Roskin 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : Use ARGS, not positional arguments

Some scripts need to be fixed to use ARGS properly.

Positional arguments are no longer preserved in cg-Xlib, so they may not be used. cg-export uses standard option parsing now.

cg-admin-lsobj +1 -1
index 8899037..bf3413f 100755
@@ -39,7 +39,7 @@ USAGE="cg-admin-lsobj [OBJECT_TYPE]"
 
 . ${COGITO_LIB}cg-Xlib || exit 1
 
-target=$1
+target=${ARGS[0]}
 
 
 subdir=$_git_objects
cg-branch-add +2 -2
index eb20598..c5462cf 100755
@@ -63,8 +63,8 @@ USAGE="cg-branch-add BRANCH_NAME LOCATIO
 
 . ${COGITO_LIB}cg-Xlib || exit 1
 
-name=$1
-location=$2
+name=${ARGS[0]}
+location=${ARGS[1]}
 
 ([ "$name" ] && [ "$location" ]) || usage
 (echo $name | egrep -qv '[^a-zA-Z0-9_.@!:-]') || \
cg-branch-chg +2 -2
index 6ac8d15..9c98f6b 100755
@@ -9,8 +9,8 @@ USAGE="cg-branch-chg BRANCH_NAME NEW_LOC
 
 . ${COGITO_LIB}cg-Xlib || exit 1
 
-name=$1
-location=$2
+name=${ARGS[0]}
+location=${ARGS[1]}
 ([ "$name" ] && [ "$location" ]) || usage
 
 [ -s "$_git/branches/$name" ] || die "branch does not exist"
cg-export +13 -8
index 594e225..ef9e7cc 100755
@@ -15,17 +15,22 @@ _git_requires_root=1
 
 . ${COGITO_LIB}cg-Xlib || exit 1
 
-if [ "$1" = "-r" ]; then
-	shift
-	# We do not resolve to tree id since git-tar-tree can utilize some commit
-	# information.
-	id="$(cg-object-id -c "$1" 2>/dev/null)" || id="$1"
-	shift
-else
+id=
+while optparse; do
+	if optparse -r=; then
+		# We do not resolve to tree id since git-tar-tree can
+		# utilize some commit information.
+		id="$(cg-object-id -c "$OPTARG" 2>/dev/null)" || id="$OPTARG"
+	else
+		optfail
+	fi
+done
+
+if [ -z "$id" ]; then
 	id="$(cg-object-id -c)"
 fi
 
-dest=$1
+dest=${ARGS[0]}
 
 ([ "$dest" ] && [ "$id" ]) || usage
 
cg-patch +1 -1
index 2aecd1a..153376e 100755
@@ -70,7 +70,7 @@ redzone_border()
 
 
 reverse=
-if [ "$1" = "-R" ]; then
+if [ "${ARGS[0]}" = "-R" ]; then
 	reverse=1
 	shift
 fi
cg-reset +1 -1
index dbd69c6..38b7361 100755
@@ -20,7 +20,7 @@ _git_requires_root=1
 . ${COGITO_LIB}cg-Xlib || exit 1
 deprecated_alias cg-reset cg-cancel
 
-[ "$1" ] && die "this command takes no parameters; use cg-restore to restore individual files"
+[ "${ARGS[0]}" ] && die "this command takes no parameters; use cg-restore to restore individual files"
 
 if ! [ -s $_git/HEAD ]; then
 	rm -f $_git/HEAD
cg-seek +1 -1
index f07b90c..d2aeb0a 100755
@@ -24,7 +24,7 @@ _git_requires_root=1
 
 . ${COGITO_LIB}cg-Xlib || exit 1
 
-dstcommit=$1
+dstcommit=${ARGS[0]}
 
 
 [ -s $_git/blocked ] && grep -vq '^seeked from ' $_git/blocked && die "action blocked: $(cat $_git/blocked)"
Signature · 2 lines
Regards,
Pavel Roskin