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

[PATCH] cg-help: dynamically list commands

From
Jonas Fonseca <fonseca@diku.dk>
Date
Jun 11, 2005, 12:37 UTC
Message-ID
<20050611123742.GA1477@diku.dk>

Use code from the make-cogito-asciidoc script to make the command listing dynamic and hopefully always up-to-date by grepping the USAGE strings.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
 cg-commit |    2 +-
 cg-help   |   47 +++++++++++++++++++++--------------------------
 2 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/cg-commit b/cg-commit
--- a/cg-commit
+++ b/cg-commit
@@ -72,7 +72,7 @@
 # EDITOR::
 #	The editor used for entering revision log information.
 
-USAGE="cg-commit [-mMESSAGE]... [-C] [-e | -E] [FILE]..."
+USAGE="cg-commit [-mMESSAGE]... [-C] [-e | -E] [FILE]... < MESSAGE"
 
 . ${COGITO_LIB}cg-Xlib
 
diff --git a/cg-help b/cg-help
--- a/cg-help
+++ b/cg-help
@@ -25,6 +25,25 @@ if [ "$1" ]; then
 	exit 1
 fi
 
+bin_path="$(dirname $0)"
+
+REGULAR_COMMANDS="$(ls $bin_path/cg-* | grep -v cg-admin- | grep -v cg-X)"
+ADVANCED_COMMANDS="$(ls $bin_path/cg-admin-*)"
+
+print_command_listing()
+{
+	for command in "$@"; do
+		cmdname=$(basename $command)
+
+		usage=$(sed -n '/^USAGE=/,0s/.*\(cg-.*\)"/\1/p' < $command)
+		# Some minimal sanity check that we didn't pick up some
+		# random binary named cg-*
+		[ "$usage" ] || continue
+		usage=$(echo "$usage" | sed 's/cg-[^ ]*//')
+		printf "	%-17s %s\n" "$cmdname" "$usage"
+	done
+}
+
 
 cat <<__END__
 The Cogito version control system  $(cg-version)
@@ -32,34 +51,10 @@ The Cogito version control system  $(cg-
 Usage: cg-COMMAND [ARG]...
 
 Available commands:
-	cg-add		FILE...
-	cg-branch-add	BNAME SOURCE_LOC
-	cg-branch-ls
-	cg-cancel
-	cg-clone	[-s] SOURCE_LOC [DESTDIR]
-	cg-commit	[-m"Commit message"]... [-e | -E] [FILE]... < log message
-	cg-diff		[-c] [-m] [-p] [-r FROM_ID[:TO_ID]] [FILE]...
-	cg-export	DEST [TREE_ID]
-	cg-help		[COMMAND]
-	cg-init
-	cg-log		[-c] [-f] [-m] [-r FROM_ID[:TO_ID]] [FILE]...
-	cg-merge	[-c] [-b BASE_ID] FROM_ID
-	cg-mkpatch	[-m] [-s] [-r FROM_ID[:TO_ID]]
-	cg-patch			< patch on stdin
-	cg-pull		[BNAME]
-	cg-restore	[FILE]...
-	cg-rm		FILE...
-	cg-seek		[COMMIT_ID]
-	cg-status
-	cg-tag		TNAME [COMMIT_ID]
-	cg-tag-ls
-	cg-update	[BNAME]
-	cg-version
+$(print_command_listing $REGULAR_COMMANDS)
 
 Advanced (low-level or dangerous) commands:
-	cg-admin-ls	[-t TREE_ID] [PATH]
-	cg-admin-lsobj	[OBJTYPE]
-	cg-admin-uncommit [-t] [COMMIT_ID]
+$(print_command_listing $ADVANCED_COMMANDS)
 
 These expressions can be used interchangably as "ID"s:
 	empty string, "this" or "HEAD" (current HEAD)
-- 
Jonas Fonseca
Message 1 of 1 in “cg-help: dynamically list commands”
  1. cg-help: dynamically list commandsJonas Fonseca, Jun 11, 2005

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.