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

[TopGit PATCH] tg.sh: Runtime tg-* command check

From
Bert Wesarg <bert.wesarg@googlemail.com>
Date
Aug 6, 2008, 07:49 UTC
Message-ID
<1218008964-27286-1-git-send-email-bert.wesarg@googlemail.com>
Check for tg commands at runtime, not the hard coded list inside tg.sh.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 tg.sh |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/tg.sh b/tg.sh
index 03a392b..179f0de 100644
--- a/tg.sh
+++ b/tg.sh
@@ -152,8 +152,21 @@ switch_to_base()
 do_help()
 {
 	if [ -z "$1" ] ; then
+		## Build available commands list for help output
+
+		cmds=
+		sep=
+		for cmd in "@cmddir@"/tg-*; do
+			! [ -r "$cmd" ] && continue
+			# strip directory part and "tg-" prefix
+			cmd="$(basename "$cmd")"
+			cmd="${cmd#tg-}"
+			cmds="$cmds$sep$cmd"
+			sep="|"
+		done
+
 		echo "TopGit v0.1 - A different patch queue manager"
-		echo "Usage: tg (create|delete|info|patch|summary|update|help) ..."
+		echo "Usage: tg ($cmds|help) ..."
 	elif [ -f "@sharedir@/tg-$1.txt" ] ; then
 		cat "@sharedir@/tg-$1.txt"
 	else
@@ -171,6 +184,8 @@ root_dir="$(git rev-parse --show-cdup)"; root_dir="${root_dir:-.}"
 setup_ours
 setup_hook "pre-commit"
 
+[ -d "@cmddir@" ] ||
+	die "No command directory: '@cmddir@'"
 
 ## Dispatch
 
@@ -186,12 +201,13 @@ case "$cmd" in
 help)
 	do_help "$1"
 	exit 1;;
-create|delete|info|patch|summary|update)
-	. "@cmddir@"/tg-$cmd;;
 --hooks-path)
 	# Internal command
 	echo "@hooksdir@";;
 *)
-	echo "Unknown subcommand: $cmd" >&2
-	exit 1;;
+	[ -r "@cmddir@"/tg-$cmd ] || {
+		echo "Unknown subcommand: $cmd" >&2
+		exit 1
+	}
+	. "@cmddir@"/tg-$cmd;;
 esac
-- 
tg: (e311d15..) t/auto-generate-command-list-for-tg.sh (depends on: master)
Message 1 of 1 in “tg.sh: Runtime tg-* command check”
  1. tg.sh: Runtime tg-* command checkBert Wesarg, Aug 6, 2008

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.