zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: _os_arguments
Date: Tue, 13 Dec 2016 01:54:05 +0100	[thread overview]
Message-ID: <68784.1481590445@hydra.kiddle.eu> (raw)
In-Reply-To: <20161212052803.GA53519@CptOrmolo.darkstar>

Matthew Martin wrote:
> When updating completions for the BSDs, it can be a bit of a pain to
> check each case or if block especially since the alphabetization of the
> options is disrupted. This is an attempt to ease that pain. First an
> example usage converting _rm to _os_arguments then the patch itself.

Have you seen the approach taken in _chown, _cp, _du and _last which
also does not disrupt the order of options? There could be ways to
compress the patterns down.

Having only a single letter and wrapping _arguments directly means that
this wouldn't work for a number of functions. We have quite a few cases
where we do:
  _pick_variant -r variant gnu=GNU $OSTYPE --version
and then use $variant with the case statement.

Also, there are quite a few cases where we include the version number,
particularly with Solaris because Solaris 10 still gets a fair amount of
use (is still the primary platform where I work). I was planning to do
this somewhat more in future for BSDs (at least at major version level)
now that we've got more of the functions in a good state: it's easier
when adding them incrementally.

Rather than wrap _arguments directly, it might be more flexible to have
some sort of filter_args helper. That could also be applied around
_values too for, e.g. dd or ifconfig. It could allow for custom
letter mappings and have the option of making other transformations on
the args list before going on to _arguments. It might also be easier to
mix with _arguments' sets feature.

Long options can pose a bigger challenge when trying to handle different
systems. There are a few GNU utilities such as grep where FreeBSD and
Darwin have forked at the final GPL2 release. So I can see there being
more cases where we need to handle these with associated issues such as
sharing the latter part of the _arguments spec (description etc) between
the long and short option. I'd regard alphabetization of options to be
a lesser concern. For single implementation commands, I try to follow
the ordering from -h / --help output which is usually a mix of logical,
alphabetical and some randomness. And sometimes it'd be more helpful to
have them ordered with options that have similar mutual exclusions.

> +case $OSTYPE in
> +  aix*) os=A;;
> +  cygwin*) os=C;;

Note that this case statement could be done as an associative array. I
mention this mainly because an associative array is easier to extend if
we were to support that:
  typeset -A osabbrev
  osabbrev=( 'linux*' L 'openbsd*' O ..... )
  os=${a[(k)$OSTYPE]}

Oliver


      parent reply	other threads:[~2016-12-13  1:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-12  5:28 _os_arguments Matthew Martin
2016-12-12  8:52 ` _os_arguments Daniel Shahaf
2016-12-13  0:54 ` Oliver Kiddle [this message]

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=68784.1481590445@hydra.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --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).