about summary refs log tree commit diff
path: root/Completion/Darwin/Command/_plutil
blob: 8138a5c5eabfc580ec932fceb3ae2ed1d0fa1ccd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#compdef plutil

local ret=1 k v
local -a context line state state_descr tmp fmts=( xml1 binary1 json )
local -A opt_args val_args types=(
  -bool    'boolean'
  -data    'base64-encoded data'
  -date    'date (XML property-list format)'
  -float   '64-bit float'
  -integer '64-bit integer'
  -json    'JSON fragment'
  -xml     'XML property list'
)

_arguments -s -S : \
  '(: -)-help[display help information]' \
  '(-p -r)-s[suppress normal output]' \
  '*:input file:_files' \
  - set1 \
  '-lint[check input for syntax errors]' \
  - set2 \
  "(-extract -insert -replace -remove)-convert[convert to specified format]:output format:(${(j< >)fmts})" \
  "(-convert -insert -replace -remove)-extract[extract value at specified key path from property list]: :->k:output format:(${(j< >)fmts})" \
  '(-convert -extract -replace -remove)-insert[insert value at specified key path into property list]: :->k: :->t: :->v' \
  '(-convert -extract -insert -remove)-replace[replace value at specified key path in property list]: :->k: :->t: :->v' \
  '(-convert -extract -insert -replace)-remove[remove value at specified key path from property list]: :->k' \
  '(-o -extract -insert -replace -remove)-e[specify output file extension]:output file extension' \
  '(-e -extract -insert -replace -remove)-o[specify output file]:output file:_files' \
  '(-r -s)-p[pretty-print property list]' \
  '(-p -s)-r[pretty-print JSON]' \
&& ret=0

case $state in
  k) _message 'key path' && ret=0 ;;
  t)
    tmp=()
    for k v in ${(kv)types}; do
      tmp+=( "${k}[${v}]" )
    done
    _values 'value type' $tmp && ret=0
    ;;
  v)
    if [[ $words[(CURRENT - 1)] == -bool ]]; then
      _values $types[-bool] YES NO true false && ret=0
    elif (( $+types[$words[(CURRENT - 1)]] )); then
      _message $types[$words[(CURRENT - 1)]] && ret=0
    else
      _message value && ret=0
    fi
    ;;
esac

return ret