git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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;
 	}
Previous: Pierre HabouzitNext: Pierre Habouzit
Message 5 of 8 in “Bring parse_options to the shell”
  1. Pierre HabouzitNov 2, 2007
  2. Add git-parseopt(1) to bring parse-options to shell scripts.Pierre Habouzit, Nov 2, 2007
  3. Update git-sh-setup(1) to allow transparent use of git-parseopt(1)Pierre Habouzit, Nov 2, 2007
  4. Pierre HabouzitNov 2, 2007
  5. Linus TorvaldsNov 2, 2007
  6. Pierre HabouzitNov 2, 2007
  7. Johannes SchindelinNov 2, 2007
  8. Pierre HabouzitNov 2, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.