Re: git-repack made my pack 317x larger...
- From
- Benjamin Sergeant <bsergean@gmail.com>
- Date
- Jun 15, 2007, 15:10 UTC
- Message-ID
- <1621f9fa0706150810m1d1bc31ua485db72f6e0bca1@mail.gmail.com>
- In-Reply-To
- <20070615145433.22970.qmail@science.horizon.com>
> (I might complan a little less if git-repack would take -adlf rather > than insisting on -a -d -l -f. Is that a deliberate choice or has just > nobody stepped up to revamp the option parsing?)
getopt is our friend, indeed.
(http://www.hmug.org/man/1/getopt.php)
The following code fragment shows how one might process the arguments for
a command that can take the options -a and -b, and the option -o, which
requires an argument. args=`getopt abo: $*`
# you should not use `getopt abo: "$@"` since that would parse
# the arguments differently from what the set command below does.
if [ $? != 0 ]
then
echo 'Usage: ...'
exit 2
fi
set -- $args
# You cannot use the set command with a backquoted getopt directly,
# since the exit code from getopt would be shadowed by those of set,
# which is zero by definition.
for i
do
case "$i"
in
-a|-b)
echo flag $i set; sflags="${i#-}$sflags";
shift;;
-o)
echo oarg is "'"$2"'"; oarg="$2"; shift;
shift;;
--)
shift; break;;
esac
done
echo single-char flags: "'"$sflags"'"
echo oarg is "'"$oarg"'"This code will accept any of the following as equivalent:
cmd -aoarg file file
cmd -a -o arg file file
cmd -oarg -a file file
cmd -a -oarg -- file file