| 1 | # labgrid-client(1) completion -*- shell-script -*- |
| 2 | |
| 3 | # options top level and subcommands support |
| 4 | _labgrid_shared_options="--help" |
| 5 | _labgrid_main_opts_with_value="@(-x|--coordinator|-c|--config|-p|--place|-s|--state|-i|--initial-state|-P|--proxy)" |
| 6 | |
| 7 | # Parses labgrid-client arguments |
| 8 | # Sets arg to subcommand, excluding options and their values. |
| 9 | # Sets last_arg_opt_with_value to true if the last argument is an option requiring a value, else |
| 10 | # false. |
| 11 | # Sets base_cmd to the labgrid-client base command up to subcommand and removes trailing |
| 12 | # option requiring a value - useful to call 'labgrid-client complete' with place/coordinator/proxy set |
| 13 | # Before calling this function, make sure arg, base_cmd and last_arg_opt_with_value are local |
| 14 | _labgrid_parse_args() |
| 15 | { |
| 16 | local i cmd_type |
| 17 | arg= |
| 18 | base_cmd=("${COMP_WORDS[0]}") |
| 19 | last_arg_opt_with_value=false |
| 20 | |
| 21 | for ((i = 1; i < COMP_CWORD; i++)); do |
| 22 | base_cmd+=( "$(dequote "${COMP_WORDS[i]}")" ) |
| 23 | |
| 24 | # skip options |
| 25 | if [[ ${COMP_WORDS[i]} == -* ]]; then |
| 26 | # shellcheck disable=SC2053 |
| 27 | if [[ ${COMP_WORDS[i]} == $_labgrid_main_opts_with_value ]]; then |
| 28 | if [[ "$((i+1))" == "$COMP_CWORD" ]]; then |
| 29 | last_arg_opt_with_value=true |
| 30 | fi |
| 31 | fi |
| 32 | continue |
| 33 | fi |
| 34 | |
| 35 | # skip option values |
| 36 | # shellcheck disable=SC2053 |
| 37 | if [[ ${COMP_WORDS[i-1]} == $_labgrid_main_opts_with_value ]]; then |
| 38 | continue |
| 39 | fi |
| 40 | |
| 41 | # drop last command component, as we reached the subcommand |
| 42 | unset 'base_cmd[-1]' |
| 43 | |
| 44 | arg="${COMP_WORDS[i]}" |
| 45 | break |
| 46 | done |
| 47 | |
| 48 | # drop incomplete option expecting a value |
| 49 | if $last_arg_opt_with_value; then |
| 50 | unset 'base_cmd[-1]' |
| 51 | fi |
| 52 | |
| 53 | # resolve base command aliases |
| 54 | if cmd_type=$(type -t -f "${base_cmd[0]}" 2>/dev/null); then |
| 55 | if [[ "$cmd_type" == "alias" ]]; then |
| 56 | base_cmd[0]="${BASH_ALIASES["${base_cmd[0]}"]}" |
| 57 | fi |
| 58 | fi |
| 59 | } |
| 60 | |
| 61 | # Counts the number of arguments, excluding options and top level option values |
| 62 | # @param $1 glob additional options expecting a value |
| 63 | # Before calling this function, make sure args is local |
| 64 | _labgrid_count_args() |
| 65 | { |
| 66 | local pattern |
| 67 | |
| 68 | if [ -n "$1" ]; then |
| 69 | pattern="${_labgrid_main_opts_with_value::-1}|${1:2}" |
| 70 | else |
| 71 | pattern="$_labgrid_main_opts_with_value" |
| 72 | fi |
| 73 | |
| 74 | _count_args "" "$pattern" || return |
| 75 | } |
| 76 | |
| 77 | # Completes using 'labgrid-client complete' |
| 78 | # @param $1 type for 'labgrid-client complete' |
| 79 | # @param $2 cur as set by _init_completion |
| 80 | _labgrid_complete() |
| 81 | { |
| 82 | local completion_type cur choices arg last_arg_opt_with_value base_cmd |
| 83 | completion_type="$1" |
| 84 | cur="$2" |
| 85 | |
| 86 | _labgrid_parse_args |
| 87 | |
| 88 | # TODO: handle completions including spaces |
| 89 | if ! choices=$("${base_cmd[@]}" complete "$completion_type" 2>/dev/null); then |
| 90 | return |
| 91 | fi |
| 92 | |
| 93 | COMPREPLY=( $(compgen -W "$choices" -- "$cur") ) |
| 94 | } |
| 95 | |
| 96 | # Completes exporters exporting available resources |
| 97 | # @param $1 cur as set by _init_completion |
| 98 | _labgrid_complete_exporters() |
| 99 | { |
| 100 | local cur resources exporters arg last_arg_opt_with_value base_cmd |
| 101 | cur="$1" |
| 102 | |
| 103 | _labgrid_parse_args |
| 104 | |
| 105 | if ! resources=$("${base_cmd[@]}" complete resources 2>/dev/null); then |
| 106 | return |
| 107 | fi |
| 108 | |
| 109 | exporters=$(cut -d/ -f1 <<< "$resources" | uniq) |
| 110 | COMPREPLY=( $(compgen -W "$exporters" -- "$cur") ) |
| 111 | } |
| 112 | |
| 113 | # Completes subcommand options |
| 114 | # @param $1 array with additional options |
| 115 | _labgrid_client_generic_subcommand() { |
| 116 | local cur prev words cword |
| 117 | _init_completion || return |
| 118 | |
| 119 | case "$cur" in |
| 120 | -*) |
| 121 | local options="$1 $_labgrid_shared_options" |
| 122 | COMPREPLY=( $(compgen -W "$options" -- "$cur") ) |
| 123 | ;; |
| 124 | esac |
| 125 | } |
| 126 | |
| 127 | ############################## |
| 128 | # subcommand functions below # |
| 129 | ############################## |
| 130 | |
| 131 | _labgrid_client_resources() |
| 132 | { |
| 133 | local cur prev words cword |
| 134 | _init_completion || return |
| 135 | |
| 136 | case "$prev" in |
| 137 | -e|--exporter) |
| 138 | _labgrid_complete_exporters "$cur" |
| 139 | return |
| 140 | ;; |
| 141 | esac |
| 142 | |
| 143 | case "${cur}" in |
| 144 | -*) |
| 145 | local options="--acquired \ |
| 146 | --exporter \ |
| 147 | --sort-by-matched-place-change \ |
| 148 | $_labgrid_shared_options" |
| 149 | COMPREPLY=( $(compgen -W "$options" -- "$cur") ) |
| 150 | ;; |
| 151 | *) |
| 152 | _labgrid_complete resources "$cur" |
| 153 | ;; |
| 154 | esac |
| 155 | } |
| 156 | |
| 157 | _labgrid_client_r() |
| 158 | { |
| 159 | _labgrid_client_resources |
| 160 | } |
| 161 | |
| 162 | _labgrid_client_places() |
| 163 | { |
| 164 | _labgrid_client_generic_subcommand "--acquired --released --sort-last-changed" |
| 165 | } |
| 166 | |
| 167 | _labgrid_client_p() |
| 168 | { |
| 169 | _labgrid_client_places |
| 170 | } |
| 171 | |
| 172 | _labgrid_client_who() |
| 173 | { |
| 174 | _labgrid_client_generic_subcommand "--show-exporters" |
| 175 | } |
| 176 | |
| 177 | _labgrid_client_add_match() |
| 178 | { |
| 179 | local cur prev words cword |
| 180 | _init_completion || return |
| 181 | |
| 182 | case "${cur}" in |
| 183 | -*) |
| 184 | COMPREPLY=( $(compgen -W "$_labgrid_shared_options" -- "$cur") ) |
| 185 | ;; |
| 186 | *) |
| 187 | _labgrid_complete resources "$cur" |
| 188 | ;; |
| 189 | esac |
| 190 | } |
| 191 | |
| 192 | _labgrid_client_del_match() |
| 193 | { |
| 194 | local cur prev words cword |
| 195 | _init_completion || return |
| 196 | |
| 197 | case "${cur}" in |
| 198 | -*) |
| 199 | COMPREPLY=( $(compgen -W "$_labgrid_shared_options" -- "$cur") ) |
| 200 | ;; |
| 201 | *) |
| 202 | _labgrid_complete matches "$cur" |
| 203 | ;; |
| 204 | esac |
| 205 | } |
| 206 | |
| 207 | _labgrid_client_add_named_match() |
| 208 | { |
| 209 | local cur prev words cword |
| 210 | _init_completion || return |
| 211 | |
| 212 | case "$cur" in |
| 213 | -*) |
| 214 | COMPREPLY=( $(compgen -W "$_labgrid_shared_options" -- "$cur") ) |
| 215 | ;; |
| 216 | *) |
| 217 | local args |
| 218 | _labgrid_count_args || return |
| 219 | # only complete second argument |
| 220 | [ "$args" -ne 2 ] && return |
| 221 | |
| 222 | _labgrid_complete resources |
| 223 | return |
| 224 | ;; |
| 225 | esac |
| 226 | } |
| 227 | |
| 228 | _labgrid_client_acquire() |
| 229 | { |
| 230 | _labgrid_client_generic_subcommand "--allow-unmatched" |
| 231 | } |
| 232 | |
| 233 | _labgrid_client_lock() |
| 234 | { |
| 235 | _labgrid_client_acquire |
| 236 | } |
| 237 | |
| 238 | _labgrid_client_release() |
| 239 | { |
| 240 | _labgrid_client_generic_subcommand "--kick" |
| 241 | } |
| 242 | |
| 243 | _labgrid_client_unlock() |
| 244 | { |
| 245 | _labgrid_client_release |
| 246 | } |
| 247 | |
| 248 | _labgrid_client_release_from() |
| 249 | { |
| 250 | local args cur prev words cword |
| 251 | _init_completion || return |
| 252 | |
| 253 | case "$cur" in |
| 254 | -*) |
| 255 | COMPREPLY=( $(compgen -W "$_labgrid_shared_options" -- "$cur") ) |
| 256 | ;; |
| 257 | */*) |
| 258 | _labgrid_count_args || return |
| 259 | # only complete second argument |
| 260 | [ "$args" -ne 2 ] && return |
| 261 | |
| 262 | COMPREPLY=( $(compgen -A user -P "${cur%%/*}/" -- "${cur##*/}") ) |
| 263 | ;; |
| 264 | *) |
| 265 | _labgrid_count_args || return |
| 266 | # only complete second argument |
| 267 | [ "$args" -ne 2 ] && return |
| 268 | |
| 269 | compopt -o nospace |
| 270 | # -c for colon suffix |
| 271 | _known_hosts_real -c -- "$cur" || return |
| 272 | # replace colon suffix with "/" suffix |
| 273 | COMPREPLY=( $(sed -E 's#:( |$)#/\1#g' <<< "${COMPREPLY[@]}") ) |
| 274 | # drop hosts containing dots or colons |
| 275 | COMPREPLY=( ${COMPREPLY[@]//*[.:]*/} ) |
| 276 | ;; |
| 277 | esac |
| 278 | } |
| 279 | |
| 280 | _labgrid_client_allow() |
| 281 | { |
| 282 | _labgrid_client_release_from |
| 283 | } |
| 284 | |
| 285 | _labgrid_client_power() |
| 286 | { |
| 287 | local cur prev words cword |
| 288 | _init_completion || return |
| 289 | |
| 290 | case "$prev" in |
| 291 | -t|--delay) |
| 292 | return |
| 293 | ;; |
| 294 | -n|--name) |
| 295 | _labgrid_complete match-names "$cur" |
| 296 | return |
| 297 | ;; |
| 298 | esac |
| 299 | |
| 300 | case "$cur" in |
| 301 | -*) |
| 302 | COMPREPLY=( $(compgen -W "--delay --name $_labgrid_shared_options" -- "$cur") ) |
| 303 | ;; |
| 304 | *) |
| 305 | local args |
| 306 | _labgrid_count_args "@(-t|--delay)" || return |
| 307 | # only complete second argument |
| 308 | [ "$args" -ne 2 ] && return |
| 309 | |
| 310 | COMPREPLY=( $(compgen -W "on off cycle get" -- "$cur") ) |
| 311 | ;; |
| 312 | esac |
| 313 | } |
| 314 | |
| 315 | _labgrid_client_pw() |
| 316 | { |
| 317 | _labgrid_client_power |
| 318 | } |
| 319 | |
| 320 | _labgrid_client_io() |
| 321 | { |
| 322 | local cur prev words cword |
| 323 | _init_completion || return |
| 324 | |
| 325 | case "$cur" in |
| 326 | -*) |
| 327 | COMPREPLY=( $(compgen -W "$_labgrid_shared_options" -- "$cur") ) |
| 328 | ;; |
| 329 | *) |
| 330 | local args |
| 331 | _labgrid_count_args || return |
| 332 | # only complete second argument |
| 333 | case "$args" in |
| 334 | 2) |
| 335 | COMPREPLY=( $(compgen -W "high low get" -- "$cur") ) |
| 336 | ;; |
| 337 | 3) |
| 338 | _labgrid_complete match-names "$cur" |
| 339 | ;; |
| 340 | esac |
| 341 | ;; |
| 342 | esac |
| 343 | } |
| 344 | |
| 345 | _labgrid_client_console() |
| 346 | { |
| 347 | local cur prev words cword |
| 348 | _init_completion || return |
| 349 | |
| 350 | case "$prev" in |
| 351 | --logfile) |
| 352 | _filedir |
| 353 | return |
| 354 | ;; |
| 355 | esac |
| 356 | |
| 357 | case "$cur" in |
| 358 | -*) |
| 359 | COMPREPLY=( $(compgen -W "--listenonly --loop --logfile $_labgrid_shared_options" -- "$cur") ) |
| 360 | ;; |
| 361 | *) |
| 362 | local args |
| 363 | _labgrid_count_args || return |
| 364 | # only complete second argument |
| 365 | [ "$args" -ne 2 ] && return |
| 366 | |
| 367 | _labgrid_complete match-names "$cur" |
| 368 | esac |
| 369 | } |
| 370 | |
| 371 | _labgrid_client_con() |
| 372 | { |
| 373 | _labgrid_client_console |
| 374 | } |
| 375 | |
| 376 | _labgrid_client_dfu() |
| 377 | { |
| 378 | local cur prev words cword |
| 379 | _init_completion || return |
| 380 | |
| 381 | case "$prev" in |
| 382 | --wait) |
| 383 | return |
| 384 | ;; |
| 385 | -n|--name) |
| 386 | _labgrid_complete match-names "$cur" |
| 387 | return |
| 388 | ;; |
| 389 | esac |
| 390 | |
| 391 | case "$cur" in |
| 392 | -*) |
| 393 | COMPREPLY=( $(compgen -W "--wait --name $_labgrid_shared_options" -- "$cur") ) |
| 394 | ;; |
| 395 | *) |
| 396 | local args |
| 397 | _labgrid_count_args "@(--wait|-n|--name)" || return |
| 398 | |
| 399 | # complete second argument |
| 400 | if [ "$args" -eq 2 ]; then |
| 401 | COMPREPLY=( $(compgen -W "download detach list" -- "$cur") ) |
| 402 | return |
| 403 | fi |
| 404 | |
| 405 | _filedir |
| 406 | ;; |
| 407 | esac |
| 408 | } |
| 409 | |
| 410 | _labgrid_client_fastboot() |
| 411 | { |
| 412 | local cur prev words cword |
| 413 | _init_completion || return |
| 414 | |
| 415 | case "$prev" in |
| 416 | --wait) |
| 417 | return |
| 418 | ;; |
| 419 | -n|--name) |
| 420 | _labgrid_complete match-names "$cur" |
| 421 | return |
| 422 | ;; |
| 423 | esac |
| 424 | |
| 425 | case "$cur" in |
| 426 | -*) |
| 427 | COMPREPLY=( $(compgen -W "--wait --name $_labgrid_shared_options" -- "$cur") ) |
| 428 | ;; |
| 429 | *) |
| 430 | _filedir |
| 431 | ;; |
| 432 | esac |
| 433 | } |
| 434 | |
| 435 | _labgrid_client_flashscript() |
| 436 | { |
| 437 | local cur prev words cword |
| 438 | _init_completion || return |
| 439 | |
| 440 | case "$prev" in |
| 441 | -n|--name) |
| 442 | _labgrid_complete match-names "$cur" |
| 443 | return |
| 444 | ;; |
| 445 | esac |
| 446 | |
| 447 | case "$cur" in |
| 448 | -*) |
| 449 | COMPREPLY=( $(compgen -W "--name $_labgrid_shared_options" -- "$cur") ) |
| 450 | ;; |
| 451 | *) |
| 452 | local args |
| 453 | _labgrid_count_args "@(-n|--name)" || return |
| 454 | # only complete second argument |
| 455 | [ "$args" -ne 2 ] && return |
| 456 | |
| 457 | _filedir |
| 458 | ;; |
| 459 | esac |
| 460 | } |
| 461 | |
| 462 | _labgrid_client_bootstrap() |
| 463 | { |
| 464 | local cur prev words cword |
| 465 | _init_completion || return |
| 466 | |
| 467 | case "$prev" in |
| 468 | -w|--wait) |
| 469 | return |
| 470 | ;; |
| 471 | -n|--name) |
| 472 | _labgrid_complete match-names "$cur" |
| 473 | return |
| 474 | ;; |
| 475 | esac |
| 476 | |
| 477 | case "$cur" in |
| 478 | -*) |
| 479 | COMPREPLY=( $(compgen -W "--wait --name $_labgrid_shared_options" -- "$cur") ) |
| 480 | ;; |
| 481 | *) |
| 482 | local args |
| 483 | _labgrid_count_args "@(-w|--wait|-n|--name)" || return |
| 484 | # only complete second argument |
| 485 | [ "$args" -ne 2 ] && return |
| 486 | |
| 487 | _filedir |
| 488 | ;; |
| 489 | esac |
| 490 | } |
| 491 | |
| 492 | _labgrid_client_sd_mux() |
| 493 | { |
| 494 | local cur prev words cword |
| 495 | _init_completion || return |
| 496 | |
| 497 | case "$prev" in |
| 498 | -n|--name) |
| 499 | _labgrid_complete match-names "$cur" |
| 500 | return |
| 501 | ;; |
| 502 | esac |
| 503 | |
| 504 | case "$cur" in |
| 505 | -*) |
| 506 | COMPREPLY=( $(compgen -W "--name $_labgrid_shared_options" -- "$cur") ) |
| 507 | ;; |
| 508 | *) |
| 509 | local args |
| 510 | _labgrid_count_args "@(-n|--name)" || return |
| 511 | # only complete second argument |
| 512 | [ "$args" -ne 2 ] && return |
| 513 | |
| 514 | COMPREPLY=( $(compgen -W "dut host off client get" -- "$cur") ) |
| 515 | ;; |
| 516 | esac |
| 517 | } |
| 518 | |
| 519 | _labgrid_client_usb_mux() |
| 520 | { |
| 521 | local cur prev words cword |
| 522 | _init_completion || return |
| 523 | |
| 524 | case "$prev" in |
| 525 | -n|--name) |
| 526 | _labgrid_complete match-names "$cur" |
| 527 | return |
| 528 | ;; |
| 529 | esac |
| 530 | |
| 531 | case "$cur" in |
| 532 | -*) |
| 533 | COMPREPLY=( $(compgen -W "--name $_labgrid_shared_options" -- "$cur") ) |
| 534 | ;; |
| 535 | *) |
| 536 | local args actions |
| 537 | _labgrid_count_args "@(-n|--name)" || return |
| 538 | # only complete second argument |
| 539 | [ "$args" -ne 2 ] && return |
| 540 | |
| 541 | actions="off \ |
| 542 | dut-device \ |
| 543 | host-dut \ |
| 544 | host-device \ |
| 545 | host-dut+host-device" |
| 546 | COMPREPLY=( $(compgen -W "$actions") ) |
| 547 | ;; |
| 548 | esac |
| 549 | } |
| 550 | |
| 551 | _labgrid_client_ssh() |
| 552 | { |
| 553 | local cur prev words cword |
| 554 | _init_completion || return |
| 555 | |
| 556 | case "$prev" in |
| 557 | -n|--name) |
| 558 | _labgrid_complete match-names "$cur" |
| 559 | return |
| 560 | ;; |
| 561 | esac |
| 562 | |
| 563 | case "$cur" in |
| 564 | -*) |
| 565 | COMPREPLY=( $(compgen -W "--name $_labgrid_shared_options" -- "$cur") ) |
| 566 | ;; |
| 567 | esac |
| 568 | } |
| 569 | |
| 570 | _labgrid_client_scp() |
| 571 | { |
| 572 | local cur prev words cword |
| 573 | _init_completion || return |
| 574 | |
| 575 | case "$prev" in |
| 576 | -n|--name) |
| 577 | _labgrid_complete match-names "$cur" |
| 578 | return |
| 579 | ;; |
| 580 | esac |
| 581 | |
| 582 | case "$cur" in |
| 583 | -*) |
| 584 | COMPREPLY=( $(compgen -W "--name $_labgrid_shared_options" -- "$cur") ) |
| 585 | ;; |
| 586 | *) |
| 587 | local args |
| 588 | _labgrid_count_args "@(-n|--name)" || return |
| 589 | # only complete second and third argument |
| 590 | if [ "$args" -lt 2 ] || [ "$args" -gt 3 ]; then |
| 591 | return |
| 592 | fi |
| 593 | |
| 594 | _filedir |
| 595 | ;; |
| 596 | esac |
| 597 | } |
| 598 | |
| 599 | _labgrid_client_rsync() |
| 600 | { |
| 601 | _labgrid_client_scp |
| 602 | } |
| 603 | |
| 604 | _labgrid_client_sshfs() |
| 605 | { |
| 606 | local cur prev words cword |
| 607 | _init_completion || return |
| 608 | |
| 609 | case "$prev" in |
| 610 | -n|--name) |
| 611 | _labgrid_complete match-names "$cur" |
| 612 | return |
| 613 | ;; |
| 614 | esac |
| 615 | |
| 616 | case "$cur" in |
| 617 | -*) |
| 618 | COMPREPLY=( $(compgen -W "--name $_labgrid_shared_options" -- "$cur") ) |
| 619 | ;; |
| 620 | *) |
| 621 | local args |
| 622 | _labgrid_count_args "@(-n|--name)" || return |
| 623 | # only complete third argument |
| 624 | [ "$args" -ne 3 ] && return |
| 625 | |
| 626 | _filedir -d |
| 627 | ;; |
| 628 | esac |
| 629 | } |
| 630 | |
| 631 | _labgrid_client_forward() |
| 632 | { |
| 633 | local cur prev words cword |
| 634 | _init_completion || return |
| 635 | |
| 636 | case "$prev" in |
| 637 | -n|--name) |
| 638 | _labgrid_complete match-names "$cur" |
| 639 | return |
| 640 | ;; |
| 641 | esac |
| 642 | |
| 643 | case "$cur" in |
| 644 | -*) |
| 645 | COMPREPLY=( $(compgen -W "--name --local --remote $_labgrid_shared_options" -- "$cur") ) |
| 646 | ;; |
| 647 | esac |
| 648 | } |
| 649 | |
| 650 | _labgrid_client_video() |
| 651 | { |
| 652 | local cur prev words cword |
| 653 | _init_completion || return |
| 654 | |
| 655 | case "$prev" in |
| 656 | -n|--name) |
| 657 | _labgrid_complete match-names "$cur" |
| 658 | return |
| 659 | ;; |
| 660 | esac |
| 661 | |
| 662 | case "$cur" in |
| 663 | -*) |
| 664 | COMPREPLY=( $(compgen -W "--quality --controls --name $_labgrid_shared_options" -- "$cur") ) |
| 665 | ;; |
| 666 | esac |
| 667 | } |
| 668 | |
| 669 | _labgrid_client_audio() |
| 670 | { |
| 671 | local cur prev words cword |
| 672 | _init_completion || return |
| 673 | |
| 674 | case "$prev" in |
| 675 | -n|--name) |
| 676 | _labgrid_complete match-names "$cur" |
| 677 | return |
| 678 | ;; |
| 679 | esac |
| 680 | |
| 681 | case "$cur" in |
| 682 | -*) |
| 683 | COMPREPLY=( $(compgen -W "--name $_labgrid_shared_options" -- "$cur") ) |
| 684 | ;; |
| 685 | esac |
| 686 | } |
| 687 | |
| 688 | _labgrid_client_tmc() |
| 689 | { |
| 690 | local args cur prev words cword |
| 691 | _init_completion || return |
| 692 | |
| 693 | case "$prev" in |
| 694 | -n|--name) |
| 695 | _labgrid_complete match-names "$cur" |
| 696 | return |
| 697 | ;; |
| 698 | esac |
| 699 | |
| 700 | case "$cur" in |
| 701 | -*) |
| 702 | COMPREPLY=( $(compgen -W "--name $_labgrid_shared_options" -- "$cur") ) |
| 703 | return |
| 704 | ;; |
| 705 | *) |
| 706 | local args |
| 707 | _labgrid_count_args "@(-n|--name)" || return |
| 708 | # only complete second argument |
| 709 | if [ "$args" -eq 2 ]; then |
| 710 | COMPREPLY=( $(compgen -W "cmd query screen channel" -- "$cur") ) |
| 711 | return |
| 712 | fi |
| 713 | ;; |
| 714 | esac |
| 715 | |
| 716 | _labgrid_count_args || return |
| 717 | [ "$args" -lt 3 ] && return |
| 718 | |
| 719 | case "$prev" in |
| 720 | screen) |
| 721 | COMPREPLY=( $(compgen -W "show save" -- "$cur") ) |
| 722 | return |
| 723 | ;; |
| 724 | esac |
| 725 | |
| 726 | if [[ "${COMP_WORDS[COMP_CWORD-2]}" == "channel" ]]; then |
| 727 | COMPREPLY=( $(compgen -W "info values" -- "$cur") ) |
| 728 | return |
| 729 | fi |
| 730 | } |
| 731 | |
| 732 | _labgrid_client_write_image() |
| 733 | { |
| 734 | local cur prev words cword |
| 735 | _init_completion || return |
| 736 | |
| 737 | case "$prev" in |
| 738 | -w|--wait) |
| 739 | ;& |
| 740 | -p|--partition) |
| 741 | ;& |
| 742 | --skip) |
| 743 | ;& |
| 744 | --seek) |
| 745 | return |
| 746 | ;; |
| 747 | --mode) |
| 748 | COMPREPLY=( $( compgen -W "dd bmaptool" -- "$cur") ) |
| 749 | return |
| 750 | ;; |
| 751 | -n|--name) |
| 752 | _labgrid_complete match-names "$cur" |
| 753 | return |
| 754 | ;; |
| 755 | esac |
| 756 | |
| 757 | case "$cur" in |
| 758 | -*) |
| 759 | local options="--wait --partition --skip --seek --mode --name $_labgrid_shared_options" |
| 760 | COMPREPLY=( $(compgen -W "$options" -- "$cur") ) |
| 761 | ;; |
| 762 | *) |
| 763 | local args |
| 764 | _labgrid_count_args "@(-w|--wait|-p|--partition|--skip|--seek|--mode|-n|--name)" || return |
| 765 | # only complete second argument |
| 766 | [ "$args" -ne 2 ] && return |
| 767 | |
| 768 | _filedir |
| 769 | ;; |
| 770 | esac |
| 771 | } |
| 772 | |
| 773 | _labgrid_client_write_files() |
| 774 | { |
| 775 | local cur prev words cword |
| 776 | _init_completion || return |
| 777 | |
| 778 | case "$prev" in |
| 779 | -w|--wait) |
| 780 | ;& |
| 781 | -p|--partition) |
| 782 | ;& |
| 783 | -t|--target-directory) |
| 784 | ;& |
| 785 | -T) |
| 786 | ;& |
| 787 | -n|--name) |
| 788 | _labgrid_complete match-names "$cur" |
| 789 | return |
| 790 | ;; |
| 791 | esac |
| 792 | |
| 793 | case "$cur" in |
| 794 | -*) |
| 795 | local options="--wait --partition --target-directory --name $_labgrid_shared_options" |
| 796 | COMPREPLY=( $(compgen -W "$options" -- "$cur") ) |
| 797 | ;; |
| 798 | *) |
| 799 | local args |
| 800 | _labgrid_count_args "@(-w|--wait|-p|--partition|-t|--target-directory|-T|-n|--name)" || return |
| 801 | |
| 802 | _filedir |
| 803 | ;; |
| 804 | esac |
| 805 | } |
| 806 | |
| 807 | _labgrid_client_reserve() |
| 808 | { |
| 809 | _labgrid_client_generic_subcommand "--wait --shell --prio" |
| 810 | } |
| 811 | |
| 812 | _labgrid_client_export() |
| 813 | { |
| 814 | local cur prev words cword |
| 815 | _init_completion || return |
| 816 | |
| 817 | case "$prev" in |
| 818 | --format) |
| 819 | COMPREPLY=( $( compgen -W "shell shell-export json" -- "$cur" ) ) |
| 820 | return |
| 821 | ;; |
| 822 | esac |
| 823 | |
| 824 | case "$cur" in |
| 825 | -*) |
| 826 | local options="--format $_labgrid_shared_options" |
| 827 | COMPREPLY=( $(compgen -W "$options" -- "$cur") ) |
| 828 | ;; |
| 829 | *) |
| 830 | local args |
| 831 | _labgrid_count_args "@(--format)" || return |
| 832 | # only complete second argument |
| 833 | [ "$args" -ne 2 ] && return |
| 834 | |
| 835 | _filedir |
| 836 | ;; |
| 837 | esac |
| 838 | } |
| 839 | |
| 840 | # main entry point |
| 841 | _labgrid_client() |
| 842 | { |
| 843 | local arg cur prev words cword base_cmd last_arg_opt_with_value |
| 844 | |
| 845 | # require bash-completion with _init_completion |
| 846 | type -t _init_completion >/dev/null 2>&1 || return |
| 847 | |
| 848 | _init_completion || return |
| 849 | _labgrid_parse_args |
| 850 | |
| 851 | COMPREPLY=() |
| 852 | |
| 853 | # no top level subcommand found |
| 854 | if [ -z "$arg" ]; then |
| 855 | # complete top level option values |
| 856 | if $last_arg_opt_with_value; then |
| 857 | case "$prev" in |
| 858 | -c|--config) |
| 859 | _filedir |
| 860 | ;; |
| 861 | -p|--place) |
| 862 | _labgrid_complete places "$cur" |
| 863 | ;; |
| 864 | esac |
| 865 | return |
| 866 | fi |
| 867 | |
| 868 | case "$cur" in |
| 869 | --*) |
| 870 | # top level args completion |
| 871 | local options="--coordinator \ |
| 872 | --config \ |
| 873 | --place \ |
| 874 | --state \ |
| 875 | --initial-state \ |
| 876 | --debug \ |
| 877 | --verbose \ |
| 878 | --proxy \ |
| 879 | $_labgrid_shared_options" |
| 880 | |
| 881 | COMPREPLY=( $(compgen -W "$options" -- "$cur" ) ) |
| 882 | return |
| 883 | ;; |
| 884 | *) |
| 885 | # top level subcommand completion |
| 886 | local subcommands="monitor \ |
| 887 | resources \ |
| 888 | places \ |
| 889 | who \ |
| 890 | show \ |
| 891 | create \ |
| 892 | delete \ |
| 893 | add-alias \ |
| 894 | del-alias \ |
| 895 | set-comment \ |
| 896 | set-tags \ |
| 897 | add-match \ |
| 898 | del-match \ |
| 899 | add-named-match \ |
| 900 | acquire \ |
| 901 | lock \ |
| 902 | release \ |
| 903 | unlock \ |
| 904 | release-from \ |
| 905 | allow \ |
| 906 | env \ |
| 907 | power \ |
| 908 | io \ |
| 909 | console \ |
| 910 | dfu \ |
| 911 | fastboot \ |
| 912 | flashscript \ |
| 913 | bootstrap \ |
| 914 | sd-mux \ |
| 915 | usb-mux \ |
| 916 | ssh \ |
| 917 | scp \ |
| 918 | rsync \ |
| 919 | sshfs \ |
| 920 | forward \ |
| 921 | telnet \ |
| 922 | video \ |
| 923 | audio \ |
| 924 | tmc \ |
| 925 | write-image \ |
| 926 | write-files \ |
| 927 | reserve \ |
| 928 | cancel-reservation \ |
| 929 | wait \ |
| 930 | reservations \ |
| 931 | version \ |
| 932 | export" |
| 933 | COMPREPLY=( $(compgen -W "$subcommands" -- "$cur") ) |
| 934 | return |
| 935 | ;; |
| 936 | esac |
| 937 | fi |
| 938 | |
| 939 | # top level subcommand found, try to complete using _labgrid_client_subcommand |
| 940 | # otherwise use _labgrid_client_generic_subcommand |
| 941 | local completion_func="_labgrid_client_${arg//-/_}" |
| 942 | declare -f "$completion_func" >/dev/null && $completion_func || _labgrid_client_generic_subcommand |
| 943 | } && |
| 944 | complete -F _labgrid_client labgrid-client |