From: "Benjamin Sergeant" <bsergean@gmail.com>
To: "linux@horizon.com" <linux@horizon.com>
Cc: nico@cam.org, git@vger.kernel.org
Subject: Re: git-repack made my pack 317x larger...
Date: Fri, 15 Jun 2007 08:10:09 -0700 [thread overview]
Message-ID: <1621f9fa0706150810m1d1bc31ua485db72f6e0bca1@mail.gmail.com> (raw)
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
next prev parent reply other threads:[~2007-06-15 15:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-15 8:50 git-repack made my pack 317x larger linux
2007-06-15 13:39 ` Nicolas Pitre
2007-06-15 14:54 ` linux
2007-06-15 15:10 ` Benjamin Sergeant [this message]
2007-06-15 15:53 ` Nicolas Pitre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1621f9fa0706150810m1d1bc31ua485db72f6e0bca1@mail.gmail.com \
--to=bsergean@gmail.com \
--cc=git@vger.kernel.org \
--cc=linux@horizon.com \
--cc=nico@cam.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox