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

Re: [PATCH] Allow help/--help/-h to be run outside of a TopGit repo

From
Petr Baudis <pasky@suse.cz>
Date
Nov 20, 2008, 14:27 UTC
Message-ID
<20081120142702.GG10491@machine.or.cz>
In-Reply-To
<1227181594-15123-1-git-send-email-madduck@debian.org>
On Thu, Nov 20, 2008 at 12:46:34PM +0100, martin f. krafft wrote:
Show 51 quoted lines
> The user ought to be able to call `tg help` from anywhere in the filesystem,
> not just Git repositories, so the help parsing has to happen before the calls
> to git git binary.
> 
> Debian bug: #501982
> 
> Signed-off-by: martin f. krafft <madduck@debian.org>
> 
> ---
>  tg.sh |   28 +++++++++++++++++++++++++---
>  1 files changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/tg.sh b/tg.sh
> index 4dcc15e..258f8ce 100644
> --- a/tg.sh
> +++ b/tg.sh
> @@ -235,12 +235,37 @@ do_help()
>  	fi
>  }
>  
> +# Check whether we are supposed to output the help message
> +should_do_help()
> +{
> +	# we are being sourced for utility functions, never run help
> +	[ -z "$tg__include" ] || return 1
> +
> +	local prev
> +	while [ -n "$1" ]; do
> +		case "$1" in
> +		help|--help|-h)
> +			shift
> +			echo "${1:-$prev}"
> +			return 0
> +		esac
> +		prev="$1"
> +		shift
> +	done
> +
> +	# run help when there was no previous topic, meaning that there where
> +	# no arguments at all
> +	test -z "$prev"
> +}
>  
>  ## Startup
>  
>  [ -d "@cmddir@" ] ||
>  	die "No command directory: '@cmddir@'"
>  
> +# check if we should run help and get the topic while we're at it
> +help_topic="$(should_do_help "$@")" && { do_help "$help_topic"; exit 0; }
> +

Why is this so complicated? Can't you just do_help from should_do_help()? The overall semantics seems strange anyway, though - it seems that 'tg mail --help -r' will try to show help for '-r' instead of 'mail'.

-- 
				Petr "Pasky" Baudis
People who take cold baths never have rheumatism, but they have
cold baths.
Previous: martin f. krafftNext: martin f krafft
Message 2 of 5 in “Allow help/--help/-h to be run outside of a TopGit repo”
  1. Allow help/--help/-h to be run outside of a TopGit repomartin f. krafft, Nov 20, 2008
  2. Petr BaudisNov 20, 2008
  3. martin f krafftNov 20, 2008
  4. Petr BaudisNov 20, 2008
  5. martin f krafftNov 20, 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.