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

Fwd: Completion confusion around the _arguments -A flag



I have a binary (call it foo) with two, mutually exclusive, optional flags
(that must come first) and a required arg. The problem I'm having is that
when omitting both flags and using just the arg the completion tries to add
one of the flags after it. Reading the docs lead me to the -A flag, however
it doesn't seem to be preventing the flag completion despite being after
the first arg. I'm hoping I've just overlooked something but for the life
of me I can't see it.

Command structure:

foo [--name|--software] <node>

Current completion code:

#compdef foo

_nodes() {
  compadd $(get_node_list)
}

local curcontext="$curcontext" state state_descr line
typeset -A opt_args

local rc=1

_arguments -A '-*' \
  '(--name --software)'{--name,--software} \
  '1: :_nodes' \
  && rc=0

return rc

Examples:

foo <TAB>              #=> GOOD: nodelist
foo -<TAB>             #=> GOOD: --name --software
foo --name <TAB>       #=> GOOD: nodelist
foo --name -<TAB>      #=> GOOD: nothing
foo --software <TAB>   #=> GOOD: nodelist
foo --software -<TAB>  #=> GOOD: nothing
foo node <TAB>         #=> BAD: --name --software, expect nothing
foo node -<TAB>        #=> BAD: --name --software, expect nothing

Any assistance to solve this issue would be massively appreciated!

Many thanks,
Mal


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