zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: "Jun. T" <takimoto-j@kba.biglobe.ne.jp>
Cc: zsh-workers@zsh.org
Subject: Re: How about separating "_arguments --" into a new function?
Date: Tue, 12 Oct 2021 16:04:28 +0000	[thread overview]
Message-ID: <20211012160428.GD17948@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <4B74EF96-AE73-4D40-ACDD-9999DFFDA1A8@kba.biglobe.ne.jp>

Jun. T wrote on Sat, Oct 09, 2021 at 01:12:42 +0900:
> _gnu_generic works rather well for basenc, and '_arguments --'
> caches the option specs generated from the --help text in a variable
> _args_cache_basenc. So I created _basenc by
> 
> % compdef _gnu_generic basenc
> % basenc <TAB>
> % echo ${(F)${(qqq)_args_cache_basenc}} > _basenc
> and edited _basenc (to add option groups etc.).
> 

Nice :)

> If we separate the part of _arguments that generates the option specs
> (around lines 36 - 323) into an auto-loadable function, say help2specs,
> then we will be able to do something like
> 
> % help2specs cmd > _cmd
> (and edit _cmd to improve it)
> 
> If this seems useful I'll work on it.

A tool that takes some command's --help output and produces a skeleton
completion function would certainly be nice for people writing
completion functions.  However, creating a new completion function isn't
a common task; I suspect it's more common to update an existing
completion function with more custom logic or with new options.  So,
perhaps the tool could be designed with an eye towards updating existing
completion functions?  For instance, perhaps the tool could inspect the
existing _cmd file and omit from the output any lines where the
--foo[lorem ipsum] part already appears in the file?

Perhaps make the tool a filter, in order to support, say, «ssh foo
'lorem --help' | help2specs»?

The docs of _arguments say one should declare «local context state
state_descr line; typeset -A opt_args» whenever one uses -> actions.
Some tool (not necessarily the same tool as the proposed help2specs
tool) that prefills those lines would be nice to have: that would
prevent people from forgetting or overlooking those declarations, and
having them prefilled would be easier than copying them from the manual.

> Or just using $_args_cache_cmd is enough?

If it is enough, then it should be made more discoverable.

> If _arguments is separated into two, tracing the history by 'git blame'
> etc. would be a little bit tedious.

Well, yes, but on the other hand, _arguments would then be "doing one
thing and doing it well", and its documentation would be clearer.  And
_arguments' own source code might be clearer too.  (I don't have
a strong opinion; I'm just playing Devil's advocate.)

Of course, if _arguments does get splitted, it may then be needed to
update __arguments.

Cheers,

Daniel


  reply	other threads:[~2021-10-12 16:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-08 16:12 Jun. T
2021-10-12 16:04 ` Daniel Shahaf [this message]
2021-10-14 10:58   ` Jun T
2021-10-17 16:49     ` Daniel Shahaf
2021-10-18  4:40       ` Jun T
2021-10-21 14:15         ` Daniel Shahaf
2021-10-24  9:53           ` Jun. T
2021-10-25 19:46             ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211012160428.GD17948@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).