{"thread":{"id":"14832","subject":"[PATCH] [TopGit] Make \"tg help cmd\" print cmd help","startedAt":"2008-08-04T14:39:22Z","lastAt":"2008-08-04T14:39:22Z","messageCount":1,"participants":["Russell Steicke"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"86195","messageId":"20080804143922.GE11179@maggie.localnet","threadId":"14832","inReplyTo":null,"subject":"[PATCH] [TopGit] Make \"tg help cmd\" print cmd help","fromName":"Russell Steicke","fromEmail":"russellsteicke@gmail.com","sentAt":"2008-08-04T14:39:22Z","receivedAt":"2008-08-04T14:39:22Z","isPatch":true,"sender":{"key":"russellsteicke@gmail.com","avatar":null},"body":"\"tg help\" looked like it needed help, and stuff it needed to know\nabout was already in README.\n\nUse awk to extract help information from the README file.  Store\nthe help files in $(PREFIX)/share/topgit.  \"tg help foo\" will cat\n$(PREFIX)/share/topgit/tg-foo.txt.\n\nThis is instead of the previous patch.  It fixes a bug where the\nhelp for the last command (update) wasn't terminated properly.\n\nSigned-off-by: Russell Steicke <russellsteicke@gmail.com>\n\n---\n .gitignore     |    6 ++++++\n Makefile       |   11 +++++++++--\n create-help.sh |   17 +++++++++++++++++\n tg.sh          |   16 ++++++++++++++--\n 4 files changed, 46 insertions(+), 4 deletions(-)\n\ndiff --git a/.gitignore b/.gitignore\nindex 53ca141..6f0727f 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -1,8 +1,14 @@\n hooks/pre-commit\n tg-create\n+tg-create.txt\n tg-delete\n+tg-delete.txt\n tg-info\n+tg-info.txt\n tg-patch\n+tg-patch.txt\n tg-summary\n+tg-summary.txt\n tg-update\n+tg-update.txt\n tg\ndiff --git a/Makefile b/Makefile\nindex 3913d66..501df5a 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -2,6 +2,7 @@\n PREFIX = $(HOME)\n bindir = $(PREFIX)/bin\n cmddir = $(PREFIX)/libexec/topgit\n+sharedir = $(PREFIX)/share/topgit\n hooksdir = $(cmddir)/hooks\n \n \n@@ -10,18 +11,22 @@ hooks_in = hooks/pre-commit.sh\n \n commands_out = $(patsubst %.sh,%,$(commands_in))\n hooks_out = $(patsubst %.sh,%,$(hooks_in))\n+help_out = $(patsubst %.sh,%.txt,$(commands_in))\n \n-all::\ttg $(commands_out) $(hooks_out)\n+all::\ttg $(commands_out) $(hooks_out) $(help_out)\n \n tg $(commands_out) $(hooks_out): % : %.sh\n \t@echo \"[SED] $@\"\n \t@sed -e 's#@cmddir@#$(cmddir)#g;' \\\n \t\t-e 's#@hooksdir@#$(hooksdir)#g' \\\n \t\t-e 's#@bindir@#$(bindir)#g' \\\n+\t\t-e 's#@sharedir@#$(sharedir)#g' \\\n \t\t$@.sh >$@+ && \\\n \tchmod +x $@+ && \\\n \tmv $@+ $@\n \n+$(help_out): README create-help.sh\n+\t./create-help.sh `echo $@ | sed -e 's/tg-//' -e 's/\\.txt//'`\n \n install:: all\n \tinstall tg \"$(bindir)\"\n@@ -29,6 +34,8 @@ install:: all\n \tinstall $(commands_out) \"$(cmddir)\"\n \tinstall -d -m 755 \"$(hooksdir)\"\n \tinstall $(hooks_out) \"$(hooksdir)\"\n+\tinstall -d -m 755 \"$(sharedir)\"\n+\tinstall $(help_out) \"$(sharedir)\"\n \n clean::\n-\trm -f tg $(commands_out) $(hooks_out)\n+\trm -f tg $(commands_out) $(hooks_out) $(help_out)\ndiff --git a/create-help.sh b/create-help.sh\nnew file mode 100755\nindex 0000000..502b6c3\n--- /dev/null\n+++ b/create-help.sh\n@@ -0,0 +1,17 @@\n+#!/bin/sh\n+\n+# Create the tg-foo.txt files which contain help for the tg-foo command.\n+\n+if [ $# -ne 1 ] ; then\n+\techo \"Usage: $0 tgcommand\" 1>&2\n+\texit 1\n+fi\n+\n+< README awk '\n+\tBEGIN { incommand = 0; }\n+\t/^tg '\"$1\"'$/ { incommand = 1; next; }\n+\t/^[a-zA-Z]/ { incommand = 0; next; }\n+\t/^~/ { next; } # Ignore the title underlines.\n+\t{ if (incommand) { print $0; } }\n+'  > tg-\"$1\".txt\n+\ndiff --git a/tg.sh b/tg.sh\nindex e7c42cd..03a392b 100644\n--- a/tg.sh\n+++ b/tg.sh\n@@ -148,6 +148,19 @@ switch_to_base()\n \tgit symbolic-ref HEAD \"$_base\"\n }\n \n+# Show the help messages.\n+do_help()\n+{\n+\tif [ -z \"$1\" ] ; then\n+\t\techo \"TopGit v0.1 - A different patch queue manager\"\n+\t\techo \"Usage: tg (create|delete|info|patch|summary|update|help) ...\"\n+\telif [ -f \"@sharedir@/tg-$1.txt\" ] ; then\n+\t\tcat \"@sharedir@/tg-$1.txt\"\n+\telse\n+\t\techo \"`basename $0`: no help for $1\" 1>&2\n+\tfi\n+}\n+\n \n ## Initial setup\n \n@@ -171,8 +184,7 @@ shift\n \n case \"$cmd\" in\n help)\n-\techo \"TopGit v0.1 - A different patch queue manager\"\n-\techo \"Usage: tg (create|delete|info|patch|summary|update|help) ...\"\n+\tdo_help \"$1\"\n \texit 1;;\n create|delete|info|patch|summary|update)\n \t. \"@cmddir@\"/tg-$cmd;;\n-- \ntg: (24367cc..) t/help (depends on: master)\n\n\n\n\n-- \nRussell Steicke\n\n-- Fortune says:\nBOFH excuse #144:\n\nToo few computrons available.\n"}]}