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

Re: Custom subcommand help handlers

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 23, 2021, 00:11 UTC
Message-ID
<xmqq35mkdvsu.fsf@gitster.g>
In-Reply-To
<CA+JQ7M-8LydHMCgMYGP9LNMJMWk_-7LLYa5WEMMb_QMpeF-+Ag@mail.gmail.com>
Erik Cervin Edin <erik@cervined.in> writes:
Show 7 quoted lines
> Another observation.
>
> This also applies to external aliases
>   git -c alias.fr='!git-filter-repo' fr --help
> returns
>   'fr' is aliased to '!git-filter-repo'
>  w exit code 0
I do not know what your 'w' is.  To me I get
    $ git -c alias.fr='!git-filter-repo' fr --help
    'fr' is aliased to '!git-filter-repo'
which is consistent with what I get for other aliases, e.g.
    $ git -c alias.lg='log --oneline' lg --help
    'lg' is aliased to 'log --oneline'
folowed by whatever "log --help" would give us.

So hopefully when your 'w' learns to show the documentation for 'git-filter-repo' command, such an alias would also work as expected, no?

Anyway, unlike "man" and "info" where there is a standard way to tell the command that "I have documentation pages in these places" so that additional documentation can be installed to locations the user chooses (and has access to), the "web" format viewers are invoked without such customizability, i.e. in builtin/help.c, we see this code snippet:

static void get_html_page_path(struct strbuf *page_path, const char *page)
{
	struct stat st;
	char *to_free = NULL;
	if (!html_path)
		html_path = to_free = system_path(GIT_HTML_PATH);
	/*
	 * Check that the page we're looking for exists.
	 */
	if (!strstr(html_path, "://")) {
		if (stat(mkpath("%s/%s.html", html_path, page), &st)
		    || !S_ISREG(st.st_mode))
			die("'%s/%s.html': documentation file not found.",
				html_path, page);
	}
	strbuf_init(page_path, 0);
	strbuf_addf(page_path, "%s/%s.html", html_path, page);
	free(to_free);
}

It may not be a bad idea to extand the function to understand a new GIT_HTML_PATH environment variable, which can be a colon-separated list of directories just like MANPATH and INFOPATH are. It would be rather trivial to update the block with a call to stat() above to a loop over these directories.

Previous: Erik Cervin EdinNext: Erik Cervin Edin
Message 10 of 20 in “Custom subcommand help handlers”
  1. Sean AllredDec 18, 2021
  2. Ævar Arnfjörð BjarmasonDec 20, 2021
  3. Erik Cervin EdinDec 20, 2021
  4. brian m. carlsonDec 20, 2021
  5. Junio C HamanoDec 20, 2021
  6. Erik Cervin EdinDec 21, 2021
  7. Johannes SchindelinDec 22, 2021
  8. Junio C HamanoDec 22, 2021
  9. Erik Cervin EdinDec 22, 2021
  10. Junio C HamanoDec 23, 2021
  11. Erik Cervin EdinDec 23, 2021
  12. Philip OakleyDec 23, 2021
  13. Junio C HamanoDec 24, 2021
  14. Philip OakleyDec 24, 2021
  15. Sean AllredFeb 12, 2022
  16. Johannes SchindelinDec 20, 2021
  17. Ævar Arnfjörð BjarmasonDec 21, 2021
  18. Johannes SchindelinDec 22, 2021
  19. Ævar Arnfjörð BjarmasonDec 22, 2021
  20. Sean AllredFeb 12, 2022

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.