{"thread":{"id":"16406","subject":"[PATCH] Allow help/--help/-h to be run outside of a TopGit repo","startedAt":"2008-11-20T11:46:34Z","lastAt":"2008-11-20T15:11:00Z","messageCount":5,"participants":["martin f. krafft","Petr Baudis","martin f krafft"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"96219","messageId":"1227181594-15123-1-git-send-email-madduck@debian.org","threadId":"16406","inReplyTo":null,"subject":"[PATCH] Allow help/--help/-h to be run outside of a TopGit repo","fromName":"martin f. krafft","fromEmail":"madduck@debian.org","sentAt":"2008-11-20T11:46:34Z","receivedAt":"2008-11-20T11:46:34Z","isPatch":true,"sender":{"key":"madduck@debian.org","avatar":null},"body":"The user ought to be able to call `tg help` from anywhere in the filesystem,\nnot just Git repositories, so the help parsing has to happen before the calls\nto git git binary.\n\nDebian bug: #501982\n\nSigned-off-by: martin f. krafft <madduck@debian.org>\n\n---\n tg.sh |   28 +++++++++++++++++++++++++---\n 1 files changed, 25 insertions(+), 3 deletions(-)\n\ndiff --git a/tg.sh b/tg.sh\nindex 4dcc15e..258f8ce 100644\n--- a/tg.sh\n+++ b/tg.sh\n@@ -235,12 +235,37 @@ do_help()\n \tfi\n }\n \n+# Check whether we are supposed to output the help message\n+should_do_help()\n+{\n+\t# we are being sourced for utility functions, never run help\n+\t[ -z \"$tg__include\" ] || return 1\n+\n+\tlocal prev\n+\twhile [ -n \"$1\" ]; do\n+\t\tcase \"$1\" in\n+\t\thelp|--help|-h)\n+\t\t\tshift\n+\t\t\techo \"${1:-$prev}\"\n+\t\t\treturn 0\n+\t\tesac\n+\t\tprev=\"$1\"\n+\t\tshift\n+\tdone\n+\n+\t# run help when there was no previous topic, meaning that there where\n+\t# no arguments at all\n+\ttest -z \"$prev\"\n+}\n \n ## Startup\n \n [ -d \"@cmddir@\" ] ||\n \tdie \"No command directory: '@cmddir@'\"\n \n+# check if we should run help and get the topic while we're at it\n+help_topic=\"$(should_do_help \"$@\")\" && { do_help \"$help_topic\"; exit 0; }\n+\n ## Initial setup\n \n set -e\n@@ -270,9 +295,6 @@ cmd=\"$1\"\n shift\n \n case \"$cmd\" in\n-help|--help|-h)\n-\tdo_help \"$1\"\n-\texit 0;;\n --hooks-path)\n \t# Internal command\n \techo \"@hooksdir@\";;\n-- \ntg: (f17218e..) fixes/independent-help (depends on: upstream)\n"},{"id":"96253","messageId":"20081120142702.GG10491@machine.or.cz","threadId":"16406","inReplyTo":"1227181594-15123-1-git-send-email-madduck@debian.org","subject":"Re: [PATCH] Allow help/--help/-h to be run outside of a TopGit repo","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2008-11-20T14:27:03Z","receivedAt":"2008-11-20T14:27:03Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"On Thu, Nov 20, 2008 at 12:46:34PM +0100, martin f. krafft wrote:\n> The user ought to be able to call `tg help` from anywhere in the filesystem,\n> not just Git repositories, so the help parsing has to happen before the calls\n> to git git binary.\n> \n> Debian bug: #501982\n> \n> Signed-off-by: martin f. krafft <madduck@debian.org>\n> \n> ---\n>  tg.sh |   28 +++++++++++++++++++++++++---\n>  1 files changed, 25 insertions(+), 3 deletions(-)\n> \n> diff --git a/tg.sh b/tg.sh\n> index 4dcc15e..258f8ce 100644\n> --- a/tg.sh\n> +++ b/tg.sh\n> @@ -235,12 +235,37 @@ do_help()\n>  \tfi\n>  }\n>  \n> +# Check whether we are supposed to output the help message\n> +should_do_help()\n> +{\n> +\t# we are being sourced for utility functions, never run help\n> +\t[ -z \"$tg__include\" ] || return 1\n> +\n> +\tlocal prev\n> +\twhile [ -n \"$1\" ]; do\n> +\t\tcase \"$1\" in\n> +\t\thelp|--help|-h)\n> +\t\t\tshift\n> +\t\t\techo \"${1:-$prev}\"\n> +\t\t\treturn 0\n> +\t\tesac\n> +\t\tprev=\"$1\"\n> +\t\tshift\n> +\tdone\n> +\n> +\t# run help when there was no previous topic, meaning that there where\n> +\t# no arguments at all\n> +\ttest -z \"$prev\"\n> +}\n>  \n>  ## Startup\n>  \n>  [ -d \"@cmddir@\" ] ||\n>  \tdie \"No command directory: '@cmddir@'\"\n>  \n> +# check if we should run help and get the topic while we're at it\n> +help_topic=\"$(should_do_help \"$@\")\" && { do_help \"$help_topic\"; exit 0; }\n> +\n\nWhy is this so complicated? Can't you just do_help from\nshould_do_help()? The overall semantics seems strange anyway, though -\nit seems that 'tg mail --help -r' will try to show help for '-r' instead\nof 'mail'.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nPeople who take cold baths never have rheumatism, but they have\ncold baths.\n"},{"id":"96257","messageId":"20081120145511.GD29789@piper.oerlikon.madduck.net","threadId":"16406","inReplyTo":"20081120142702.GG10491@machine.or.cz","subject":"Re: [PATCH] Allow help/--help/-h to be run outside of a TopGit repo","fromName":"martin f krafft","fromEmail":"madduck@debian.org","sentAt":"2008-11-20T14:55:11Z","receivedAt":"2008-11-20T14:55:11Z","isPatch":true,"sender":{"key":"madduck@debian.org","avatar":null},"body":"also sprach Petr Baudis <pasky@suse.cz> [2008.11.20.1527 +0100]:\n> Why is this so complicated? Can't you just do_help from\n> should_do_help()?\n\nYes, I could, but that would be in conflict with my understanding of\nthe Law of Demeter.\n\n> The overall semantics seems strange anyway, though - it seems that\n> 'tg mail --help -r' will try to show help for '-r' instead of\n> 'mail'.\n\nTrue, but then we are parsing command lines. Would you be opposed to\na getopt (POSIX) approach to normalising/parsing the command line?\n\nCheers,\n\n-- \n .''`.   martin f. krafft <madduck@debian.org>\n: :'  :  proud Debian developer, author, administrator, and user\n`. `'`   http://people.debian.org/~madduck - http://debiansystem.info\n  `-  Debian - when you have better things to do than fixing systems\n \nthis space intentionally left occupied.\n"},{"id":"96260","messageId":"20081120150832.GI10491@machine.or.cz","threadId":"16406","inReplyTo":"20081120145511.GD29789@piper.oerlikon.madduck.net","subject":"Re: [PATCH] Allow help/--help/-h to be run outside of a TopGit repo","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2008-11-20T15:08:32Z","receivedAt":"2008-11-20T15:08:32Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"On Thu, Nov 20, 2008 at 03:55:11PM +0100, martin f krafft wrote:\n> also sprach Petr Baudis <pasky@suse.cz> [2008.11.20.1527 +0100]:\n> > Why is this so complicated? Can't you just do_help from\n> > should_do_help()?\n> \n> Yes, I could, but that would be in conflict with my understanding of\n> the Law of Demeter.\n\nWhat is that?\n\n> > The overall semantics seems strange anyway, though - it seems that\n> > 'tg mail --help -r' will try to show help for '-r' instead of\n> > 'mail'.\n> \n> True, but then we are parsing command lines. Would you be opposed to\n> a getopt (POSIX) approach to normalising/parsing the command line?\n\nNo. :-)\n\n\t\t\t\tPetr \"Pasky\" Baudis\n"},{"id":"96261","messageId":"20081120151100.GA2354@piper.oerlikon.madduck.net","threadId":"16406","inReplyTo":"20081120150832.GI10491@machine.or.cz","subject":"Re: [PATCH] Allow help/--help/-h to be run outside of a TopGit repo","fromName":"martin f krafft","fromEmail":"madduck@debian.org","sentAt":"2008-11-20T15:11:00Z","receivedAt":"2008-11-20T15:11:00Z","isPatch":true,"sender":{"key":"madduck@debian.org","avatar":null},"body":"also sprach Petr Baudis <pasky@suse.cz> [2008.11.20.1608 +0100]:\n> What is that?\n\nhttp://en.wikipedia.org/wiki/Law_of_Demeter\n\nIn the context of our discussion, it basically means that if\nshould_do_help calls do_help, then we cannot test should_do_help\nindependently (without mocking out do_help, which is plain ugly).\nNot that we have a testing infrastructure (yet) anyway, but...\n\n> > True, but then we are parsing command lines. Would you be opposed to\n> > a getopt (POSIX) approach to normalising/parsing the command line?\n> \n> No. :-)\n\nGood. I will see what I can do about this. In the mean time, I will\njust leave things as they are.\n\n-- \n .''`.   martin f. krafft <madduck@debian.org>\n: :'  :  proud Debian developer, author, administrator, and user\n`. `'`   http://people.debian.org/~madduck - http://debiansystem.info\n  `-  Debian - when you have better things to do than fixing systems\n \nwindoze nt crashed.\ni am the blue screen of death.\nno one hears your screams.\n"}]}