github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/contrib/completions/bash/runc (about) 1 #!/bin/bash 2 # 3 # bash completion file for runc command 4 # 5 # This script provides completion of: 6 # - commands and their options 7 # - filepaths 8 # 9 # To enable the completions either: 10 # - place this file in /usr/share/bash-completion/completions 11 # or 12 # - copy this file to e.g. ~/.runc-completion.sh and add the line 13 # below to your .bashrc after bash completion features are loaded 14 # . ~/.runc-completion.sh 15 # 16 # Configuration: 17 # 18 19 # Note for developers: 20 # Please arrange options sorted alphabetically by long name with the short 21 # options immediately following their corresponding long form. 22 # This order should be applied to lists, alternatives and code blocks. 23 24 __runc_previous_extglob_setting=$(shopt -p extglob) 25 shopt -s extglob 26 27 __runc_list_all() { 28 COMPREPLY=($(compgen -W "$(runc list -q)" -- $cur)) 29 } 30 31 __runc_pos_first_nonflag() { 32 local argument_flags=$1 33 34 local counter=$((${subcommand_pos:-${command_pos}} + 1)) 35 while [ $counter -le $cword ]; do 36 if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then 37 ((counter++)) 38 else 39 case "${words[$counter]}" in 40 -*) ;; 41 *) 42 break 43 ;; 44 esac 45 fi 46 ((counter++)) 47 done 48 49 echo $counter 50 } 51 52 # Transforms a multiline list of strings into a single line string 53 # with the words separated by "|". 54 # This is used to prepare arguments to __runc_pos_first_nonflag(). 55 __runc_to_alternatives() { 56 local parts=($1) 57 local IFS='|' 58 echo "${parts[*]}" 59 } 60 61 # Transforms a multiline list of options into an extglob pattern 62 # suitable for use in case statements. 63 __runc_to_extglob() { 64 local extglob=$(__runc_to_alternatives "$1") 65 echo "@($extglob)" 66 } 67 68 # Subcommand processing. 69 # Locates the first occurrence of any of the subcommands contained in the 70 # first argument. In case of a match, calls the corresponding completion 71 # function and returns 0. 72 # If no match is found, 1 is returned. The calling function can then 73 # continue processing its completion. 74 # 75 # TODO if the preceding command has options that accept arguments and an 76 # argument is equal to one of the subcommands, this is falsely detected as 77 # a match. 78 __runc_subcommands() { 79 local subcommands="$1" 80 81 local counter=$(($command_pos + 1)) 82 while [ $counter -lt $cword ]; do 83 case "${words[$counter]}" in 84 $(__runc_to_extglob "$subcommands")) 85 subcommand_pos=$counter 86 local subcommand=${words[$counter]} 87 local completions_func=_runc_${command}_${subcommand} 88 declare -F $completions_func >/dev/null && $completions_func 89 return 0 90 ;; 91 esac 92 ((counter++)) 93 done 94 return 1 95 } 96 97 # List all Signals 98 __runc_list_signals() { 99 COMPREPLY=($(compgen -W "$(for i in $(kill -l | xargs); do echo $i; done | grep SIG)")) 100 } 101 102 # suppress trailing whitespace 103 __runc_nospace() { 104 # compopt is not available in ancient bash versions 105 type compopt &>/dev/null && compopt -o nospace 106 } 107 108 # The list of capabilities is defined in types.go, ALL was added manually. 109 __runc_complete_capabilities() { 110 COMPREPLY=($(compgen -W " 111 ALL 112 AUDIT_CONTROL 113 AUDIT_WRITE 114 AUDIT_READ 115 BLOCK_SUSPEND 116 BPF 117 CHECKPOINT_RESTORE 118 CHOWN 119 DAC_OVERRIDE 120 DAC_READ_SEARCH 121 FOWNER 122 FSETID 123 IPC_LOCK 124 IPC_OWNER 125 KILL 126 LEASE 127 LINUX_IMMUTABLE 128 MAC_ADMIN 129 MAC_OVERRIDE 130 MKNOD 131 NET_ADMIN 132 NET_BIND_SERVICE 133 NET_BROADCAST 134 NET_RAW 135 PERFMON 136 SETFCAP 137 SETGID 138 SETPCAP 139 SETUID 140 SYS_ADMIN 141 SYS_BOOT 142 SYS_CHROOT 143 SYSLOG 144 SYS_MODULE 145 SYS_NICE 146 SYS_PACCT 147 SYS_PTRACE 148 SYS_RAWIO 149 SYS_RESOURCE 150 SYS_TIME 151 SYS_TTY_CONFIG 152 WAKE_ALARM 153 " -- "$cur")) 154 } 155 156 _runc_exec() { 157 local boolean_options=" 158 --help 159 --no-new-privs 160 --tty, -t 161 --detach, -d 162 " 163 164 local options_with_args=" 165 --console-socket 166 --cwd 167 --env, -e 168 --user, -u 169 --additional-gids, -g 170 --process, -p 171 --pid-file 172 --process-label 173 --apparmor 174 --cap, -c 175 --preserve-fds 176 --ignore-paused 177 " 178 179 local all_options="$options_with_args $boolean_options" 180 181 case "$prev" in 182 --cap | -c) 183 __runc_complete_capabilities 184 return 185 ;; 186 187 --console-socket | --cwd | --process | --apparmor) 188 case "$cur" in 189 *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 190 '') 191 COMPREPLY=($(compgen -W '/' -- "$cur")) 192 __runc_nospace 193 ;; 194 /*) 195 _filedir 196 __runc_nospace 197 ;; 198 esac 199 return 200 ;; 201 --env | -e) 202 COMPREPLY=($(compgen -e -- "$cur")) 203 __runc_nospace 204 return 205 ;; 206 $(__runc_to_extglob "$options_with_args")) 207 return 208 ;; 209 esac 210 211 case "$cur" in 212 -*) 213 COMPREPLY=($(compgen -W "$all_options" -- "$cur")) 214 ;; 215 *) 216 __runc_list_all 217 ;; 218 esac 219 } 220 221 # global options that may appear after the runc command 222 _runc_runc() { 223 local boolean_options=" 224 $global_boolean_options 225 --help 226 --version -v 227 --debug 228 --systemd-cgroup 229 " 230 local options_with_args=" 231 --log 232 --log-format 233 --root 234 --rootless 235 " 236 237 case "$prev" in 238 --log | --root) 239 case "$cur" in 240 *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 241 '') 242 COMPREPLY=($(compgen -W '/' -- "$cur")) 243 __runc_nospace 244 ;; 245 *) 246 _filedir 247 __runc_nospace 248 ;; 249 esac 250 return 251 ;; 252 253 --log-format) 254 COMPREPLY=($(compgen -W 'text json' -- "$cur")) 255 return 256 ;; 257 258 $(__runc_to_extglob "$options_with_args")) 259 return 260 ;; 261 esac 262 263 case "$cur" in 264 -*) 265 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 266 ;; 267 *) 268 local counter=$(__runc_pos_first_nonflag $(__runc_to_extglob "$options_with_args")) 269 if [ $cword -eq $counter ]; then 270 COMPREPLY=($(compgen -W "${commands[*]} help" -- "$cur")) 271 fi 272 ;; 273 esac 274 } 275 276 _runc_pause() { 277 local boolean_options=" 278 --help 279 -h 280 " 281 282 case "$cur" in 283 -*) 284 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 285 ;; 286 *) 287 __runc_list_all 288 ;; 289 esac 290 } 291 292 _runc_ps() { 293 local boolean_options=" 294 --help 295 -h 296 " 297 local options_with_args=" 298 --format, -f 299 " 300 301 case "$cur" in 302 -*) 303 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 304 ;; 305 *) 306 __runc_list_all 307 ;; 308 esac 309 } 310 311 _runc_delete() { 312 local boolean_options=" 313 --help 314 -h 315 --format, -f 316 " 317 318 case "$cur" in 319 -*) 320 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 321 ;; 322 *) 323 __runc_list_all 324 ;; 325 esac 326 } 327 328 _runc_kill() { 329 local boolean_options=" 330 --help 331 -h 332 --all 333 -a 334 " 335 336 case "$prev" in 337 "kill") 338 __runc_list_all 339 return 340 ;; 341 *) 342 __runc_list_signals 343 return 344 ;; 345 esac 346 case "$cur" in 347 -*) 348 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 349 ;; 350 *) 351 __runc_list_all 352 ;; 353 esac 354 } 355 356 _runc_events() { 357 local boolean_options=" 358 --help 359 --stats 360 " 361 362 local options_with_args=" 363 --interval 364 " 365 366 case "$prev" in 367 $(__runc_to_extglob "$options_with_args")) 368 return 369 ;; 370 esac 371 372 case "$cur" in 373 -*) 374 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 375 ;; 376 *) 377 __runc_list_all 378 ;; 379 esac 380 } 381 382 _runc_list() { 383 local boolean_options=" 384 --help 385 --quiet 386 -q 387 " 388 389 local options_with_args=" 390 --format 391 -f 392 " 393 394 case "$prev" in 395 --format | -f) 396 COMPREPLY=($(compgen -W 'text json' -- "$cur")) 397 return 398 ;; 399 400 $(__runc_to_extglob "$options_with_args")) 401 return 402 ;; 403 esac 404 405 case "$cur" in 406 -*) 407 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 408 ;; 409 *) 410 local counter=$(__runc_pos_first_nonflag $(__runc_to_extglob "$options_with_args")) 411 ;; 412 esac 413 } 414 415 _runc_spec() { 416 local boolean_options=" 417 --help 418 --rootless 419 " 420 421 local options_with_args=" 422 --bundle 423 -b 424 " 425 426 case "$prev" in 427 --bundle | -b) 428 case "$cur" in 429 '') 430 COMPREPLY=($(compgen -W '/' -- "$cur")) 431 __runc_nospace 432 ;; 433 /*) 434 _filedir 435 __runc_nospace 436 ;; 437 esac 438 return 439 ;; 440 441 $(__runc_to_extglob "$options_with_args")) 442 return 443 ;; 444 esac 445 446 case "$cur" in 447 -*) 448 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 449 ;; 450 *) 451 local counter=$(__runc_pos_first_nonflag $(__runc_to_extglob "$options_with_args")) 452 ;; 453 esac 454 } 455 456 _runc_run() { 457 local boolean_options=" 458 --help 459 --detatch 460 -d 461 --no-subreaper 462 --no-pivot 463 --no-new-keyring 464 " 465 466 local options_with_args=" 467 --bundle 468 -b 469 --console-socket 470 --pid-file 471 --preserve-fds 472 " 473 474 case "$prev" in 475 --bundle | -b | --console-socket | --pid-file) 476 case "$cur" in 477 '') 478 COMPREPLY=($(compgen -W '/' -- "$cur")) 479 __runc_nospace 480 ;; 481 /*) 482 _filedir 483 __runc_nospace 484 ;; 485 esac 486 return 487 ;; 488 489 $(__runc_to_extglob "$options_with_args")) 490 return 491 ;; 492 esac 493 494 case "$cur" in 495 -*) 496 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 497 ;; 498 *) 499 __runc_list_all 500 ;; 501 esac 502 } 503 504 _runc_checkpoint() { 505 local boolean_options=" 506 --help 507 -h 508 --leave-running 509 --tcp-established 510 --ext-unix-sk 511 --shell-job 512 --lazy-pages 513 --file-locks 514 --pre-dump 515 --auto-dedup 516 " 517 518 local options_with_args=" 519 --image-path 520 --work-path 521 --parent-path 522 --status-fd 523 --page-server 524 --manage-cgroups-mode 525 --empty-ns 526 " 527 528 case "$prev" in 529 --page-server) ;; 530 531 --manage-cgroups-mode) 532 COMPREPLY=($(compgen -W "soft full strict" -- "$cur")) 533 return 534 ;; 535 536 --image-path | --work-path | --parent-path) 537 case "$cur" in 538 *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 539 '') 540 COMPREPLY=($(compgen -W '/' -- "$cur")) 541 __runc_nospace 542 ;; 543 *) 544 _filedir 545 __runc_nospace 546 ;; 547 esac 548 return 549 ;; 550 551 $(__runc_to_extglob "$options_with_args")) 552 return 553 ;; 554 esac 555 556 case "$cur" in 557 -*) 558 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 559 ;; 560 *) 561 __runc_list_all 562 ;; 563 esac 564 } 565 _runc_create() { 566 local boolean_options=" 567 --help 568 --no-pivot 569 --no-new-keyring 570 " 571 572 local options_with_args=" 573 --bundle 574 -b 575 --console-socket 576 --pid-file 577 --preserve-fds 578 " 579 case "$prev" in 580 --bundle | -b | --console-socket | --pid-file) 581 case "$cur" in 582 '') 583 COMPREPLY=($(compgen -W '/' -- "$cur")) 584 __runc_nospace 585 ;; 586 /*) 587 _filedir 588 __runc_nospace 589 ;; 590 esac 591 return 592 ;; 593 594 $(__runc_to_extglob "$options_with_args")) 595 return 596 ;; 597 esac 598 599 case "$cur" in 600 -*) 601 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 602 ;; 603 *) 604 __runc_list_all 605 ;; 606 esac 607 608 } 609 610 _runc_help() { 611 local counter=$(__runc_pos_first_nonflag) 612 if [ $cword -eq $counter ]; then 613 COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur")) 614 fi 615 } 616 617 _runc_restore() { 618 local boolean_options=" 619 --help 620 --tcp-established 621 --ext-unix-sk 622 --shell-job 623 --file-locks 624 --detach 625 -d 626 --no-subreaper 627 --no-pivot 628 --auto-dedup 629 --lazy-pages 630 " 631 632 local options_with_args=" 633 -b 634 --bundle 635 --image-path 636 --work-path 637 --manage-cgroups-mode 638 --pid-file 639 --empty-ns 640 " 641 642 local all_options="$options_with_args $boolean_options" 643 644 case "$prev" in 645 --manage-cgroups-mode) 646 COMPREPLY=($(compgen -W "soft full strict" -- "$cur")) 647 return 648 ;; 649 650 --pid-file | --image-path | --work-path | --bundle | -b) 651 case "$cur" in 652 *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) 653 '') 654 COMPREPLY=($(compgen -W '/' -- "$cur")) 655 __runc_nospace 656 ;; 657 /*) 658 _filedir 659 __runc_nospace 660 ;; 661 esac 662 return 663 ;; 664 665 $(__runc_to_extglob "$options_with_args")) 666 return 667 ;; 668 esac 669 670 case "$cur" in 671 -*) 672 COMPREPLY=($(compgen -W "$all_options" -- "$cur")) 673 ;; 674 *) 675 __runc_list_all 676 ;; 677 esac 678 } 679 680 _runc_resume() { 681 local boolean_options=" 682 --help 683 -h 684 " 685 686 case "$cur" in 687 -*) 688 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 689 ;; 690 *) 691 __runc_list_all 692 ;; 693 esac 694 } 695 696 _runc_state() { 697 local boolean_options=" 698 --help 699 -h 700 " 701 702 case "$cur" in 703 -*) 704 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 705 ;; 706 *) 707 __runc_list_all 708 ;; 709 esac 710 } 711 _runc_start() { 712 local boolean_options=" 713 --help 714 -h 715 " 716 717 case "$cur" in 718 -*) 719 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 720 ;; 721 *) 722 __runc_list_all 723 ;; 724 esac 725 } 726 _runc_update() { 727 local boolean_options=" 728 --help 729 " 730 731 local options_with_args=" 732 --blkio-weight 733 --cpu-period 734 --cpu-quota 735 --cpu-burst 736 --cpu-rt-period 737 --cpu-rt-runtime 738 --cpu-share 739 --cpuset-cpus 740 --cpuset-mems 741 --memory 742 --memory-reservation 743 --memory-swap 744 --pids-limit 745 --l3-cache-schema 746 --mem-bw-schema 747 --cpu-idle 748 " 749 750 case "$prev" in 751 $(__runc_to_extglob "$options_with_args")) 752 return 753 ;; 754 esac 755 756 case "$cur" in 757 -*) 758 COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) 759 ;; 760 *) 761 __runc_list_all 762 ;; 763 esac 764 } 765 766 _runc() { 767 local previous_extglob_setting=$(shopt -p extglob) 768 shopt -s extglob 769 770 local commands=( 771 checkpoint 772 create 773 delete 774 events 775 exec 776 kill 777 list 778 pause 779 ps 780 restore 781 resume 782 run 783 spec 784 start 785 state 786 update 787 help 788 h 789 ) 790 791 # These options are valid as global options for all client commands 792 # and valid as command options for `runc daemon` 793 local global_boolean_options=" 794 --help -h 795 --version -v 796 " 797 798 COMPREPLY=() 799 local cur prev words cword 800 _get_comp_words_by_ref -n : cur prev words cword 801 802 local command='runc' command_pos=0 subcommand_pos 803 local counter=1 804 while [ $counter -lt $cword ]; do 805 case "${words[$counter]}" in 806 -*) ;; 807 =) 808 ((counter++)) 809 ;; 810 *) 811 command="${words[$counter]}" 812 command_pos=$counter 813 break 814 ;; 815 esac 816 ((counter++)) 817 done 818 819 local completions_func=_runc_${command} 820 declare -F $completions_func >/dev/null && $completions_func 821 822 eval "$previous_extglob_setting" 823 return 0 824 } 825 826 eval "$__runc_previous_extglob_setting" 827 unset __runc_previous_extglob_setting 828 829 complete -F _runc runc