diff options
author | dana <dana@dana.is> | 2019-03-12 19:01:18 -0500 |
---|---|---|
committer | dana <dana@dana.is> | 2019-03-12 19:03:56 -0500 |
commit | 632023acc2feed519659926bf320d303562a5713 (patch) | |
tree | 69d05e6a9c778ed99f11f1a119bb71fc5a306535 /Completion/Zsh | |
parent | 36290f3e8e8cf3c69856bc9c5c08ddeccd1aebf2 (diff) | |
download | zsh-632023acc2feed519659926bf320d303562a5713.tar.gz zsh-632023acc2feed519659926bf320d303562a5713.tar.xz zsh-632023acc2feed519659926bf320d303562a5713.zip |
44100: zparseopts: Add -F option, completion, tests; improve documentation
* Enable zparseopts to perform basic usage validation (aborting on an unrecognised option-like parameter) * Officially document the resolution of ambiguous option specs
Diffstat (limited to 'Completion/Zsh')
-rw-r--r-- | Completion/Zsh/Command/_zparseopts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Completion/Zsh/Command/_zparseopts b/Completion/Zsh/Command/_zparseopts new file mode 100644 index 000000000..e13a91081 --- /dev/null +++ b/Completion/Zsh/Command/_zparseopts @@ -0,0 +1,37 @@ +#compdef zparseopts + +local ret=1 +local -a context line state state_descr alts opts +local -A opt_args + +_arguments -A '-*' : \ + '-a+[specify array in which to store parsed options]:array:_parameters -g "*array*~*readonly*"' \ + '-A+[specify association in which to store parsed options]:association:_parameters -g "*association*~*readonly*"' \ + '-D[remove parsed options from positional parameters]' \ + "-E[don't stop parsing at first parameter not described by specs]" \ + '-F[abort parsing and print error at first option-like parameter not described by specs]' \ + '-K[preserve contents of arrays/associations when specs are not matched]' \ + '-M[enable mapping among equivalent options with opt1=opt2 spec form]' \ + '(-)-[end zparseopts options; specs follow]' \ + '*: :->spec' \ +&& ret=0 + +[[ $state == spec ]] && +if compset -P '*='; then + alts=() + (( $+opt_args[-M] )) && { + opts=( $line ) + [[ $opts[1] == (-|--) ]] && shift opts + opts=( ${(@)opts%%(+|)(:|:-|::|)(=*|)} ) + opts=( ${(@)opts:#${words[CURRENT]%%=*}} ) + alts+=( "spec-opt-names:spec option name:(${(j< >)${(@q+)opts}})" ) + } + alts+=( 'parameters:array:_parameters -g "*array*~*readonly*"' ) + _alternative $alts && ret=0 +else + # Not great, but close enough for now + compset -S '=*' + _message -e spec-opts 'spec option (name[+][:|:-|::])' && ret=0 +fi + +return ret |