|
| 1 | +#compdef rustup |
| 2 | + |
| 3 | +typeset -A opt_args |
| 4 | + |
| 5 | +_rustup() { |
| 6 | + |
| 7 | +_arguments \ |
| 8 | + '(- 1 *)'{-h,--help}'[show help message]' \ |
| 9 | + '(- 1 *)'{-v,--verbose}'[use verbose output]' \ |
| 10 | + '(- 1 *)'{-V,--version}'[show version information]' \ |
| 11 | + '1: :_rustup_cmds' \ |
| 12 | + '*:: :->args' |
| 13 | + |
| 14 | +case $state in |
| 15 | + args) |
| 16 | + case $words[1] in |
| 17 | + component) |
| 18 | + local -a subcommands=( |
| 19 | + 'list:list installed and available components' |
| 20 | + 'add:add a component to a toolchain' |
| 21 | + 'remove:remove a component from a toolchain' |
| 22 | + 'help:prints this message or the help of the given subcommand(s)' |
| 23 | + ) |
| 24 | + _arguments \ |
| 25 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 26 | + '1: :{_describe 'subcommands' subcommands}' \ |
| 27 | + ;; |
| 28 | + |
| 29 | + default) |
| 30 | + _arguments \ |
| 31 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 32 | + ': :_get_local_toolchains' |
| 33 | + ;; |
| 34 | + |
| 35 | + doc) |
| 36 | + _arguments \ |
| 37 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 38 | + '--book:the Rust Programming Language book' \ |
| 39 | + '--std:standard library API documentation' \ |
| 40 | + ;; |
| 41 | + |
| 42 | + help) |
| 43 | + _arguments \ |
| 44 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 45 | + ': :_rustup_cmds' \ |
| 46 | + ;; |
| 47 | + |
| 48 | + man) |
| 49 | + _arguments \ |
| 50 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 51 | + '--toolchain: :_get_local_toolchains' \ |
| 52 | + ;; |
| 53 | + |
| 54 | + override) |
| 55 | + local -a subcommands=( |
| 56 | + 'list:list directory toolchain overrides' |
| 57 | + 'set:set the override toolchain for a directory' |
| 58 | + 'unset:remove the override toolchain for a directory' |
| 59 | + 'help:prints this message or the help of the given subcommand(s)' |
| 60 | + ) |
| 61 | + _arguments \ |
| 62 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 63 | + '1: :{_describe 'subcommands' subcommands}' \ |
| 64 | + ;; |
| 65 | + |
| 66 | + run) |
| 67 | + _arguments \ |
| 68 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 69 | + '1: :_get_local_toolchains' \ |
| 70 | + '2:command' \ |
| 71 | + ;; |
| 72 | + |
| 73 | + |
| 74 | + self) |
| 75 | + local -a subcommands=( |
| 76 | + 'update:download and install updates to rustup' |
| 77 | + 'uninstall:uninstall rustup' |
| 78 | + 'upgrade-data:upgrade the internal data format' |
| 79 | + 'help:prints this message or the help of the given subcommand(s)' |
| 80 | + ) |
| 81 | + _arguments \ |
| 82 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 83 | + '1: :{_describe 'subcommands' subcommands}' \ |
| 84 | + ;; |
| 85 | + |
| 86 | + set) |
| 87 | + local -a subcommands=( |
| 88 | + 'default-host:The triple used to identify toolchains' \ |
| 89 | + 'help:prints this message or the help of the given subcommand(s)' |
| 90 | + ) |
| 91 | + _arguments \ |
| 92 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 93 | + '1: :{_describe 'subcommands' subcommands}' \ |
| 94 | + ;; |
| 95 | + show) |
| 96 | + _arguments \ |
| 97 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 98 | + ;; |
| 99 | + |
| 100 | + target) |
| 101 | + local -a subcommands=( |
| 102 | + 'list:list installed and available targets' |
| 103 | + 'add:add a target to a toolchain' |
| 104 | + 'remove:remove a target from a toolchain' |
| 105 | + 'help:prints this message or the help of the given subcommand(s)' |
| 106 | + ) |
| 107 | + _arguments \ |
| 108 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 109 | + '1: :{_describe 'subcommands' subcommands}' \ |
| 110 | + ;; |
| 111 | + |
| 112 | + toolchain) |
| 113 | + local -a subcommands=( |
| 114 | + 'list:list installed toolchains' |
| 115 | + 'install:install or update a toolchain' |
| 116 | + 'uninstall:uninstall a toolchain' |
| 117 | + 'link:symlink a custom toolchain to a directory' |
| 118 | + 'help:prints this message or the help of the given subcommand(s)' |
| 119 | + ) |
| 120 | + _arguments \ |
| 121 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 122 | + '1: :{_describe 'subcommands' subcommands}' \ |
| 123 | + ;; |
| 124 | + |
| 125 | + update) |
| 126 | + _arguments \ |
| 127 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 128 | + '*: :_get_local_toolchains' |
| 129 | + ;; |
| 130 | + |
| 131 | + which) |
| 132 | + _arguments \ |
| 133 | + '(-h, --help)'{-h,--help}'[show help message]' \ |
| 134 | + ':command' |
| 135 | + ;; |
| 136 | + esac |
| 137 | + ;; |
| 138 | +esac |
| 139 | +} |
| 140 | + |
| 141 | +_get_local_toolchains() { |
| 142 | + local -a toolchains=() |
| 143 | + rustup toolchain list 2>/dev/null | while read line |
| 144 | + do |
| 145 | + toolchains+="${line%%-*}" |
| 146 | + done |
| 147 | + _describe 'toolchains' toolchains |
| 148 | +} |
| 149 | + |
| 150 | +_rustup_cmds(){ |
| 151 | +local -a commands=( |
| 152 | +'show:show the active and installed toolchains' |
| 153 | +'update:update Rust toolchains' |
| 154 | +'default:set the default toolchain' |
| 155 | +'toolchain:modify or query the installed toolchains' |
| 156 | +'target:modify a toolchains supported targets' |
| 157 | +'component:modify a toolchains installed components' |
| 158 | +'override:modify directory toolchain overrides' |
| 159 | +'run:run a command with an environment configured for a given toolchain' |
| 160 | +'which:display which binary will be run for a given command' |
| 161 | +'doc:open the documentation for the current toolchain' |
| 162 | +'man:view the man page for a given command' |
| 163 | +'self:modify the rustup installation' |
| 164 | +'set:alter rustup settings' |
| 165 | +'help:prints this message or the help of the given subcommand(s)' |
| 166 | +) |
| 167 | + |
| 168 | +_describe 'command' commands |
| 169 | + |
| 170 | +} |
| 171 | + |
| 172 | +_rustup |
0 commit comments