Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: _os_arguments



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



Messages sorted by: Reverse Date, Date, Thread, Author