|
| 1 | +# pyang(1) completion -*- shell-script -*- |
| 2 | + |
| 3 | +have pyang && |
| 4 | +_pyang() |
| 5 | +{ |
| 6 | + local cur prev words cword plugin hello pl_opts wind=1 |
| 7 | + |
| 8 | + local formats="hypertree dsdl depend sample-xml-skeleton omni yin |
| 9 | + tree jstree capability yang xsd uml jtox jsonxsl xmi" |
| 10 | + |
| 11 | + local opts_global=" |
| 12 | + -h --help |
| 13 | + -v --version |
| 14 | + -V --verbose |
| 15 | + -e --list-errors |
| 16 | + --print-error-code |
| 17 | + -W -E |
| 18 | + --ignore-errors |
| 19 | + --canonical |
| 20 | + --max-line-length |
| 21 | + --max-identifier-length |
| 22 | + -f --format |
| 23 | + -o --output |
| 24 | + -F --features |
| 25 | + --deviation-module |
| 26 | + -p --path |
| 27 | + --plugindir |
| 28 | + --strict |
| 29 | + --lax-xpath-checks |
| 30 | + --trim-yin |
| 31 | + -L --hello |
| 32 | + --keep-comments |
| 33 | + --check-update-from |
| 34 | + -P --check-update-from-path |
| 35 | + --ietf" |
| 36 | + |
| 37 | + local opts_capability="--capability-entity" |
| 38 | + |
| 39 | + local opts_depend=" |
| 40 | + --depend-target |
| 41 | + --depend-no-submodules |
| 42 | + --depend-from-submodules |
| 43 | + --depend-extension |
| 44 | + --depend-include-path |
| 45 | + --depend-ignore-module" |
| 46 | + |
| 47 | + local opts_dsdl=" |
| 48 | + --dsdl-no-documentation |
| 49 | + --dsdl-no-dublin-core |
| 50 | + --dsdl-record-defs" |
| 51 | + |
| 52 | + local opts_hypertree=" |
| 53 | + --hypertree-help |
| 54 | + --hypertree-path" |
| 55 | + |
| 56 | + local opts_jstree="--jstree-no-path" |
| 57 | + |
| 58 | + local opts_omni="--omni-path" |
| 59 | + |
| 60 | + local opts_sample_xml_skeleton=" |
| 61 | + --sample-xml-skeleton-doctype |
| 62 | + --sample-xml-skeleton-defaults |
| 63 | + --sample-xml-skeleton-annotations" |
| 64 | + |
| 65 | + local opts_tree=" |
| 66 | + --tree-help |
| 67 | + --tree-depth |
| 68 | + --tree-path" |
| 69 | + |
| 70 | + local opts_uml=" |
| 71 | + --uml-classes-only |
| 72 | + --uml-split-pages |
| 73 | + --uml-output-directory |
| 74 | + --uml-title |
| 75 | + --uml-header |
| 76 | + --uml-footer |
| 77 | + --uml-long-identifiers |
| 78 | + --uml-inline-groupings |
| 79 | + --uml-inline-augments |
| 80 | + --uml-description |
| 81 | + --uml-no |
| 82 | + --uml-truncate |
| 83 | + --uml-max-enums |
| 84 | + --uml-filter |
| 85 | + --uml-filter-file" |
| 86 | + |
| 87 | + local opts_xmi="--xmi-path --xmi-no-assoc-name" |
| 88 | + |
| 89 | + local opts_yang=" |
| 90 | + --yang-canonical |
| 91 | + --yang-remove-unused-imports" |
| 92 | + |
| 93 | + local opts_yin=" |
| 94 | + --yin-canonical |
| 95 | + --yin-pretty-strings" |
| 96 | + |
| 97 | + COMPREPLY=() |
| 98 | + _get_comp_words_by_ref cur prev cword words |
| 99 | + |
| 100 | + while [[ $wind -lt $cword ]]; do |
| 101 | + case ${words[$wind]} in |
| 102 | + -f|--format) |
| 103 | + plugin=${words[$wind+1]} |
| 104 | + ;; |
| 105 | + -L|--hello) |
| 106 | + hello=yes |
| 107 | + ;; |
| 108 | + esac |
| 109 | + ((wind++)) |
| 110 | + done |
| 111 | + |
| 112 | + case $prev in |
| 113 | + -o|--output) |
| 114 | + case $plugin in |
| 115 | + dsdl) |
| 116 | + _filedir 'dsdl' |
| 117 | + ;; |
| 118 | + jsonxsl) |
| 119 | + _filedir '@(xsl|xslt)' |
| 120 | + ;; |
| 121 | + jstree) |
| 122 | + _filedir 'js' |
| 123 | + ;; |
| 124 | + jtox) |
| 125 | + _filedir 'jtox' |
| 126 | + ;; |
| 127 | + sample-xml-skeleton|hypertree) |
| 128 | + _filedir 'xml' |
| 129 | + ;; |
| 130 | + omni) |
| 131 | + _filedir 'graffle' |
| 132 | + ;; |
| 133 | + uml) |
| 134 | + _filedir 'uml' |
| 135 | + ;; |
| 136 | + xmi) |
| 137 | + _filedir 'xmi' |
| 138 | + ;; |
| 139 | + yang) |
| 140 | + _filedir 'yang' |
| 141 | + ;; |
| 142 | + yin) |
| 143 | + _filedir 'yin' |
| 144 | + ;; |
| 145 | + *) |
| 146 | + _filedir |
| 147 | + ;; |
| 148 | + esac |
| 149 | + return 0 |
| 150 | + ;; |
| 151 | + -W) |
| 152 | + COMPREPLY=($(compgen -W '$(pyang --list-errors 2>&1 | sed -nEe \ |
| 153 | + "s/^(Warning|Minor Error):[[:space:]]*([A-Za-z0-9_]*).*/\2/p") \ |
| 154 | + error none' -- "$cur")) |
| 155 | + return 0 |
| 156 | + ;; |
| 157 | + -E) |
| 158 | + COMPREPLY=($(compgen -W '$(pyang --list-errors 2>&1 | \ |
| 159 | + sed -nEe "s/^Warning:[[:space:]]*([A-Za-z0-9_]*).*/\1/p")' \ |
| 160 | + -- "$cur")) |
| 161 | + return 0 |
| 162 | + ;; |
| 163 | + -f|--format) |
| 164 | + COMPREPLY=($(compgen -W '$formats' -- "$cur")) |
| 165 | + return 0 |
| 166 | + ;; |
| 167 | + esac |
| 168 | + |
| 169 | + if [[ $cur == -* ]]; then |
| 170 | + pl_opts="opts_${plugin//-/_}" |
| 171 | + COMPREPLY=($(compgen -W '$opts_global ${!pl_opts}' -- "$cur")) |
| 172 | + return 0 |
| 173 | + fi |
| 174 | + |
| 175 | + if [[ -z $hello ]]; then |
| 176 | + _filedir '@(yang|yin)' |
| 177 | + else |
| 178 | + _filedir 'xml' |
| 179 | + fi |
| 180 | +} && |
| 181 | +complete -F _pyang pyang |
| 182 | + |
| 183 | +have yang2dsdl && |
| 184 | +_yang2dsdl() |
| 185 | +{ |
| 186 | + local cur prev words cword mode opts wind=1 |
| 187 | + |
| 188 | + local targets=" |
| 189 | + data config get-reply get-config-reply edit-config |
| 190 | + rpc rpc-reply notification" |
| 191 | + |
| 192 | + COMPREPLY=() |
| 193 | + _get_comp_words_by_ref cur prev cword words |
| 194 | + |
| 195 | + case $prev in |
| 196 | + -t) |
| 197 | + COMPREPLY=($(compgen -W '$targets' -- "$cur")) |
| 198 | + return 0 |
| 199 | + ;; |
| 200 | + -v) |
| 201 | + _filedir 'xml' |
| 202 | + return 0 |
| 203 | + ;; |
| 204 | + -d) |
| 205 | + _filedir -d |
| 206 | + return 0 |
| 207 | + ;; |
| 208 | + esac |
| 209 | + |
| 210 | + while [[ $wind -lt $cword ]]; do |
| 211 | + case ${words[$wind]} in |
| 212 | + -s) |
| 213 | + mode=schemas # use pre-generated schemas |
| 214 | + break |
| 215 | + ;; |
| 216 | + -L) |
| 217 | + mode=hello |
| 218 | + ;; |
| 219 | + esac |
| 220 | + ((wind++)) |
| 221 | + done |
| 222 | + |
| 223 | + if [[ $cur == -* ]]; then |
| 224 | + opts=(-t -d -b -j -v) |
| 225 | + [[ -z $mode ]] && opts+=(-L) |
| 226 | + [[ $prev == "yang2dsdl" ]] && opts+=(-h) |
| 227 | + COMPREPLY=($(compgen -W '${opts[*]}' -- "$cur")) |
| 228 | + return 0 |
| 229 | + fi |
| 230 | + |
| 231 | + case $mode in |
| 232 | + hello) |
| 233 | + _filedir 'xml' |
| 234 | + ;; |
| 235 | + schemas) |
| 236 | + ;; |
| 237 | + *) |
| 238 | + _filedir '@(yang|yin)' |
| 239 | + ;; |
| 240 | + esac |
| 241 | +} && |
| 242 | +complete -F _yang2dsdl yang2dsdl |
| 243 | + |
| 244 | +have json2xml && |
| 245 | +_json2xml() |
| 246 | +{ |
| 247 | + local cur prev words cword opts jtox wind=1 |
| 248 | + |
| 249 | + local targets="data config" |
| 250 | + |
| 251 | + COMPREPLY=() |
| 252 | + _get_comp_words_by_ref cur prev cword words |
| 253 | + |
| 254 | + case $prev in |
| 255 | + -t|--target) |
| 256 | + COMPREPLY=($(compgen -W '$targets' -- "$cur")) |
| 257 | + return 0 |
| 258 | + ;; |
| 259 | + -o|--output) |
| 260 | + _filedir 'xml' |
| 261 | + return 0 |
| 262 | + ;; |
| 263 | + esac |
| 264 | + |
| 265 | + while [[ $wind -lt $cword ]]; do |
| 266 | + if [[ ${words[$wind]} =~ .*\.jtox$ ]]; then |
| 267 | + jtox=yes |
| 268 | + break |
| 269 | + fi |
| 270 | + ((wind++)) |
| 271 | + done |
| 272 | + |
| 273 | + if [[ $cur == -* ]]; then |
| 274 | + opts=(-t --target -o --output) |
| 275 | + [[ $prev == "json2xml" ]] && opts+=(-h --help) |
| 276 | + COMPREPLY=($(compgen -W '${opts[*]}' -- "$cur")) |
| 277 | + return 0 |
| 278 | + fi |
| 279 | + |
| 280 | + if [[ -z $jtox ]]; then |
| 281 | + _filedir 'jtox' |
| 282 | + else |
| 283 | + _filedir 'json' |
| 284 | + fi |
| 285 | +} && |
| 286 | +complete -F _json2xml json2xml |
0 commit comments