{"thread":{"id":"14858","subject":"[TopGit PATCH] tg.sh: Runtime tg-* command check","startedAt":"2008-08-06T07:49:24Z","lastAt":"2008-08-06T07:49:24Z","messageCount":1,"participants":["Bert Wesarg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"86321","messageId":"1218008964-27286-1-git-send-email-bert.wesarg@googlemail.com","threadId":"14858","inReplyTo":null,"subject":"[TopGit PATCH] tg.sh: Runtime tg-* command check","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2008-08-06T07:49:24Z","receivedAt":"2008-08-06T07:49:24Z","isPatch":true,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"Check for tg commands at runtime, not the hard coded list inside tg.sh.\n\nSigned-off-by: Bert Wesarg <bert.wesarg@googlemail.com>\n\n---\n tg.sh |   26 +++++++++++++++++++++-----\n 1 files changed, 21 insertions(+), 5 deletions(-)\n\ndiff --git a/tg.sh b/tg.sh\nindex 03a392b..179f0de 100644\n--- a/tg.sh\n+++ b/tg.sh\n@@ -152,8 +152,21 @@ switch_to_base()\n do_help()\n {\n \tif [ -z \"$1\" ] ; then\n+\t\t## Build available commands list for help output\n+\n+\t\tcmds=\n+\t\tsep=\n+\t\tfor cmd in \"@cmddir@\"/tg-*; do\n+\t\t\t! [ -r \"$cmd\" ] && continue\n+\t\t\t# strip directory part and \"tg-\" prefix\n+\t\t\tcmd=\"$(basename \"$cmd\")\"\n+\t\t\tcmd=\"${cmd#tg-}\"\n+\t\t\tcmds=\"$cmds$sep$cmd\"\n+\t\t\tsep=\"|\"\n+\t\tdone\n+\n \t\techo \"TopGit v0.1 - A different patch queue manager\"\n-\t\techo \"Usage: tg (create|delete|info|patch|summary|update|help) ...\"\n+\t\techo \"Usage: tg ($cmds|help) ...\"\n \telif [ -f \"@sharedir@/tg-$1.txt\" ] ; then\n \t\tcat \"@sharedir@/tg-$1.txt\"\n \telse\n@@ -171,6 +184,8 @@ root_dir=\"$(git rev-parse --show-cdup)\"; root_dir=\"${root_dir:-.}\"\n setup_ours\n setup_hook \"pre-commit\"\n \n+[ -d \"@cmddir@\" ] ||\n+\tdie \"No command directory: '@cmddir@'\"\n \n ## Dispatch\n \n@@ -186,12 +201,13 @@ case \"$cmd\" in\n help)\n \tdo_help \"$1\"\n \texit 1;;\n-create|delete|info|patch|summary|update)\n-\t. \"@cmddir@\"/tg-$cmd;;\n --hooks-path)\n \t# Internal command\n \techo \"@hooksdir@\";;\n *)\n-\techo \"Unknown subcommand: $cmd\" >&2\n-\texit 1;;\n+\t[ -r \"@cmddir@\"/tg-$cmd ] || {\n+\t\techo \"Unknown subcommand: $cmd\" >&2\n+\t\texit 1\n+\t}\n+\t. \"@cmddir@\"/tg-$cmd;;\n esac\n-- \ntg: (e311d15..) t/auto-generate-command-list-for-tg.sh (depends on: master)\n"}]}