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

[PATCH] Update git-sh-setup(1) to allow transparent use of git-parseopt(1)

From
Pierre Habouzit <madcoder@debian.org>
Date
Nov 2, 2007, 15:09 UTC
Message-ID
<1194016162-23599-3-git-send-email-madcoder@debian.org>
In-Reply-To
<1194016162-23599-2-git-send-email-madcoder@debian.org>

If you set OPTIONS_SPEC, git-sh-setups uses git-parseopt automatically. It also diverts usage to re-exec $0 with the -h option as parse-options.c will catch that.

PARSEOPT_OPTS can also be used to pass options git git-parseopt(1) (like
--keep-dashdash).
---
 git-sh-setup.sh |   44 ++++++++++++++++++++++++++------------------
 1 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 86d7d4c..d7b13e0 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -16,9 +16,32 @@ die() {
 	exit 1
 }
 
-usage() {
-	die "Usage: $0 $USAGE"
-}
+if test -n "$OPTIONS_SPEC"; then
+	usage() {
+		exec "$0" -h
+	}
+
+	eval `echo "$OPTIONS_SPEC" | git parseopt $PARSEOPT_OPTS -- "$@" || echo exit $?`
+else
+	usage() {
+		die "Usage: $0 $USAGE"
+	}
+
+	if [ -z "$LONG_USAGE" ]
+	then
+		LONG_USAGE="Usage: $0 $USAGE"
+	else
+		LONG_USAGE="Usage: $0 $USAGE
+
+$LONG_USAGE"
+	fi
+
+	case "$1" in
+		-h|--h|--he|--hel|--help)
+		echo "$LONG_USAGE"
+		exit
+	esac
+fi
 
 set_reflog_action() {
 	if [ -z "${GIT_REFLOG_ACTION:+set}" ]
@@ -91,21 +114,6 @@ get_author_ident_from_commit () {
 	LANG=C LC_ALL=C sed -ne "$pick_author_script"
 }
 
-if [ -z "$LONG_USAGE" ]
-then
-	LONG_USAGE="Usage: $0 $USAGE"
-else
-	LONG_USAGE="Usage: $0 $USAGE
-
-$LONG_USAGE"
-fi
-
-case "$1" in
-	-h|--h|--he|--hel|--help)
-	echo "$LONG_USAGE"
-	exit
-esac
-
 # Make sure we are in a valid repository of a vintage we understand.
 if [ -z "$SUBDIRECTORY_OK" ]
 then
-- 
1.5.3.5.1458.g2aa13-dirty
Previous: Pierre HabouzitNext: Pierre Habouzit
Message 3 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.