Re: Bring parse_options to the shell
- From
Linus Torvalds <torvalds@linux-foundation.org>
- Date
- Nov 2, 2007, 15:51 UTC
- Message-ID
- <alpine.LFD.0.999.0711020844310.3342@woody.linux-foundation.org>
- In-Reply-To
- <20071102151453.GB27505@artemis.corp>
On Fri, 2 Nov 2007, Pierre Habouzit wrote:
Show 9 quoted lines
> On Fri, Nov 02, 2007 at 03:09:18PM +0000, Pierre Habouzit wrote: > > This is also something that itches me, so here is a proposal for a > > git-parseopt helper that can be used in shell scripts as an option > > normalizer like getopt(1) does. > > > > I migrated the discussed git-clean.sh to use it as a proof of concept. > > Needless to say, this is fetchable from > git://git.madism.org/git.git#ph/parseopt
Hmm. Any reason why you didn't just extend on "git rev-parse"?
That command was written exactly to parse a command line. This is really cheesy, and doesn't really work right (it splits up numbers too), but you get the idea..
Linus
--- builtin-rev-parse.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c index 8d78b69..10b62f7 100644 --- a/builtin-rev-parse.c +++ b/builtin-rev-parse.c @@ -116,6 +116,17 @@ static int show_flag(const char *arg) if (!(filter & DO_FLAGS)) return 0; if (filter & (is_rev_argument(arg) ? DO_REVS : DO_NOREV)) { + if (arg[0] == '-' && arg[1] != '-') { + char split[3]; + split[0] = '-'; + split[2] = 0; + while (arg[1]) { + split[1] = arg[1]; + arg++; + show(split); + } + return 1; + } show(arg); return 1; }