|
| 1 | +#compdef bectl |
| 2 | + |
| 3 | +local cmd curcontext="$curcontext" ret=1 |
| 4 | +local -a state line expl args opts bectl=( $words[1] ) |
| 5 | +local -A opt_args |
| 6 | + |
| 7 | +_arguments -C -s -A '-*' \ |
| 8 | + '-h[display usage information]' \ |
| 9 | + '-r+[specify boot environment root]:root:_zfs_dataset' \ |
| 10 | + '1:action:(( |
| 11 | + activate:"set the default boot environment" |
| 12 | + check:"perform silent sanity check" |
| 13 | + create:"create new boot environment or snapshot" |
| 14 | + destroy:"destroy boot environment or snapshot" |
| 15 | + export:"export boot environment to stdout" |
| 16 | + import:"import boot environment from stdin" |
| 17 | + jail:"create a jail of a boot environment" |
| 18 | + list:"display all boot environments" |
| 19 | + mount:"mount a boot environment" |
| 20 | + rename:"rename a boot environment" |
| 21 | + u{,n}jail:"destroy jail created from a boot environment" |
| 22 | + u{,n}mount:"unmount a boot environment" |
| 23 | + ))' \ |
| 24 | + '*:: :->args' && ret=0 |
| 25 | + |
| 26 | +if [[ $state = args ]]; then |
| 27 | + bectl+=( ${(kv)opt_args[(i)-r]} ) |
| 28 | + cmd="$words[1]" |
| 29 | + curcontext="${curcontext%:*}-$cmd:" |
| 30 | + |
| 31 | + case $cmd in |
| 32 | + activate|create|destroy|(ex|im)port|jail|rename|(|u|un)mount) |
| 33 | + args=( '1: :->boot-environs' ) |
| 34 | + ;| |
| 35 | + |
| 36 | + activate) |
| 37 | + args+=( |
| 38 | + '(-T)-t[apply to the next boot only]' |
| 39 | + '(-t)-T[remove temporary boot once configuration]' |
| 40 | + ) |
| 41 | + ;; |
| 42 | + create) |
| 43 | + args+=( |
| 44 | + '-r[create recursive boot environment]' |
| 45 | + '-e+[clone specified boot environment]: :->boot-environs' |
| 46 | + ) |
| 47 | + ;; |
| 48 | + destroy) |
| 49 | + args+=( |
| 50 | + '-F[unmount without confirmation]' |
| 51 | + '-o[destroy the origin as well]' |
| 52 | + ) |
| 53 | + ;; |
| 54 | + jail) |
| 55 | + args+=( |
| 56 | + '(-U)-b[enable batch mode]' |
| 57 | + '(-b)-U[persistent jail]' |
| 58 | + '*-o+[set a jail parameter]:jail parameter' |
| 59 | + '*-u+[unset a jail parameter]:jail parameter' |
| 60 | + '*::: : _normal -p $service' |
| 61 | + ) |
| 62 | + ;; |
| 63 | + list) |
| 64 | + opts=( name creation origin used{,by{dataset,refreservation,snapshots}} ) |
| 65 | + args+=( |
| 66 | + '(-D)-a[display all datasets]' |
| 67 | + '(-a -s)-D[display full space usage]' |
| 68 | + '-H[suppress printing of headers]' |
| 69 | + '(-D)-s[include snapshots]' |
| 70 | + "(-C)-c+[specify sort key (ascending)]:zfs property:($opts)" |
| 71 | + "(-c)-C+[specify sort key (descending)]:zfs property:($opts)" |
| 72 | + ) |
| 73 | + ;; |
| 74 | + mount) |
| 75 | + args+=( '2:mount point:_directories' ) |
| 76 | + ;; |
| 77 | + rename) |
| 78 | + args+=( '2:new boot environment' ) |
| 79 | + ;; |
| 80 | + u(|n)jail) |
| 81 | + args+=( '(*)1::jail:_jails' '*: :->boot-environs' ) |
| 82 | + ;; |
| 83 | + u(|n)mount) |
| 84 | + args+=( '-f[force unmount]' ) |
| 85 | + ;; |
| 86 | + esac |
| 87 | + |
| 88 | + if (( $#args )); then |
| 89 | + _arguments -C -A '-*' -s $args |
| 90 | + else |
| 91 | + _default |
| 92 | + fi && ret=0 |
| 93 | +fi |
| 94 | + |
| 95 | +if [[ $state = boot-environs ]]; then |
| 96 | + [[ -prefix *@ ]] && opts=( -s ) |
| 97 | + |
| 98 | + _wanted boot-environs expl "boot environment" \ |
| 99 | + compadd -r "@ \t\n\-" ${${${(f)"$(_call_program boot-environs |
| 100 | + $bectl $beopts list $opts -H 2>/dev/null)"}# }%%[[:blank:]]*} && ret=0 |
| 101 | +fi |
| 102 | + |
| 103 | +return ret |
0 commit comments