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

Re: [PATCH 1/2] parse-options: support --git-completion-helper

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 16, 2018, 23:46 UTC
Message-ID
<xmqq4lnltlia.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20180116103700.4505-2-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 18 quoted lines
> This option is designed to be used by git-completion.bash. For many
> simple cases, what we do in there is usually
>
>     __gitcomp "lots of completion options"
>
> which has to be manually updated when a new user-visible option is
> added. With support from parse-options, we can write
>
>     __gitcomp "$(git command --git-completion-helper)"
>
> and get that list directly from the parser for free. Dangerous/Unpopular
> options could be hidden with the new "NO_GITCOMP" flag.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  parse-options.c | 37 +++++++++++++++++++++++++++++++++++++
>  parse-options.h |  6 ++++--
>  2 files changed, 41 insertions(+), 2 deletions(-)

I do not know if you need PARSE_OPT_NO_INTERNAL_GITCOMP. The only way to trigger this is by passing a rather long option (intended to be used only by scripts), so unlike PARSE_OPT_NO_INTERNAL_HELP which was an escape hatch to free a short-and-sweet "-h" to be retargetted by a selected few commands, there may not be need for it.

Some day when everybody uses parse-options, it would be trivially correct to declare that this is the right approach ;-) I am not sure how much of the current completion script's hardcoded option list can be reduced with this approach with today's code, given that the bigger ones (diff and log family) are not using parse-options API at all, but for the ones that already do use parse-options, I think this makes sense.

Thanks for a fun read ;-)
Previous: Duy NguyenNext: Duy Nguyen
Message 5 of 14 in “Automate updating git-completion.bash a bit”
  1. 0/2 Automate updating git-completion.bash a bitNguyễn Thái Ngọc Duy, Jan 16, 2018
  2. 1/2 parse-options: support --git-completion-helperNguyễn Thái Ngọc Duy, Jan 16, 2018
  3. Jacob KellerJan 16, 2018
  4. Duy NguyenJan 17, 2018
  5. Junio C HamanoJan 16, 2018
  6. Duy NguyenJan 17, 2018
  7. 2/2 git-completion: use --git-completion-helperNguyễn Thái Ngọc Duy, Jan 16, 2018
  8. SZEDER GáborJan 17, 2018
  9. Duy NguyenJan 17, 2018
  10. Duy NguyenJan 17, 2018
  11. SZEDER GáborJan 22, 2018
  12. Duy NguyenJan 23, 2018
  13. Duy NguyenApr 11, 2019
  14. Duy NguyenApr 11, 2019

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.