|
| 1 | +#compdef multirust |
| 2 | +# ------------------------------------------------------------------------------ |
| 3 | +# Copyright (C) 2016 by Hideo Hattori <[email protected]> |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in |
| 13 | +# all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | +# THE SOFTWARE. |
| 22 | +# ------------------------------------------------------------------------------ |
| 23 | +# Description |
| 24 | +# ----------- |
| 25 | +# |
| 26 | +# Completion script for multirust (https://github.com/brson/multirust). |
| 27 | +# |
| 28 | +# ------------------------------------------------------------------------------ |
| 29 | +# Authors |
| 30 | +# ------- |
| 31 | +# |
| 32 | +# * Hideo Hattori (https://github.com/hhatto) |
| 33 | +# |
| 34 | +# ------------------------------------------------------------------------------ |
| 35 | + |
| 36 | +_multirust() { |
| 37 | + typeset -A opt_args |
| 38 | + local context state line |
| 39 | + |
| 40 | + _arguments -s -S \ |
| 41 | + "--verbose[run verbosely]" \ |
| 42 | + "--version[print version info]" \ |
| 43 | + "*::multirust commands:_multirust_command" |
| 44 | +} |
| 45 | + |
| 46 | +(( $+functions[_multirust_command] )) || |
| 47 | +_multirust_command() { |
| 48 | + local cmd ret=1 |
| 49 | + |
| 50 | + (( $+multirust_cmds )) || _multirust_cmds=( |
| 51 | + "default:Set the default toolchain" \ |
| 52 | + "override:Set the toolchain override for the current directory tree" \ |
| 53 | + "update:Install or update a given toolchain" \ |
| 54 | + "show-override:Show information about the current override" \ |
| 55 | + "show-default:Show information about the current default" \ |
| 56 | + "list-overrides:List all overrides" \ |
| 57 | + "list-toolchains:List all installed toolchains" \ |
| 58 | + "remove-override:Remove an override, for current directory unless specified" \ |
| 59 | + "remove-toolchain:Uninstall a toolchain" \ |
| 60 | + "run:Run a command in an environment configured for a toolchain" \ |
| 61 | + "delete-data:Delete all user metadata, including installed toolchains" \ |
| 62 | + "upgrade-data:Upgrade the ~/.multirust directory from previous versions" \ |
| 63 | + "doc:Open the documentation for the currently active toolchain" \ |
| 64 | + "which:Report location of the currently active Rust tool." \ |
| 65 | + "help:Show help for this command or subcommands" \ |
| 66 | + ) |
| 67 | + |
| 68 | + if (( CURRENT == 1 )); then |
| 69 | + _describe -t commands 'multirust subcommand' _multirust_cmds || compadd "$@" - ${(s.:.)${(j.:.)_multirust_syns}} |
| 70 | + else |
| 71 | + local curcontext="$curcontext" |
| 72 | + |
| 73 | + cmd="${${_multirust_cmds[(r)$words[1]:*]%%:*}:-${(k)_multirust_syns[(r)(*:|)$words[1](:*|)]}}" |
| 74 | + if (( $#cmd )); then |
| 75 | + curcontext="${curcontext%:*:*}:multirust-${cmd}:" |
| 76 | + _call_function ret _multirust_$cmd || _message 'no more arguments' |
| 77 | + else |
| 78 | + _message "unknown multirust command: $words[1]" |
| 79 | + fi |
| 80 | + return ret |
| 81 | + fi |
| 82 | +} |
| 83 | + |
| 84 | +(( $+functions[_multirust_default] )) || |
| 85 | +_multirust_default() { |
| 86 | + _arguments -s \ |
| 87 | + "--copy-local[install by copying a local toolchain]:PATH:_gnu_generic::" \ |
| 88 | + "--link-local[install by linking a local toolchain]:PATH:_gnu_generic::" \ |
| 89 | + "--installer[allows arbitrary builds of rust to be installed from a custom-built installer]:PATH:_gnu_generic::" \ |
| 90 | + "*::multirust commands:_multirust" |
| 91 | +} |
| 92 | + |
| 93 | +(( $+functions[_multirust_override] )) || |
| 94 | +_multirust_override() { |
| 95 | + _multirust_default |
| 96 | +} |
| 97 | + |
| 98 | +(( $+functions[_multirust_update] )) || |
| 99 | +_multirust_update() { |
| 100 | + _multirust_default |
| 101 | +} |
| 102 | + |
| 103 | +__overrides() { |
| 104 | + declare -a overrides |
| 105 | + overrides=($(multirust list-overrides|awk -F";" '{print $1":"$2}')) |
| 106 | + _describe 'override' overrides |
| 107 | +} |
| 108 | + |
| 109 | +__toolchains() { |
| 110 | + declare -a toolchains |
| 111 | + toolchains=($(multirust list-toolchains)) |
| 112 | + _describe "toolchain" toolchains |
| 113 | +} |
| 114 | + |
| 115 | +__subcommands() { |
| 116 | + declare -a cmds |
| 117 | + cmds=($(multirust|grep "# "|awk '{print $2}')) |
| 118 | + _describe "command" cmds |
| 119 | +} |
| 120 | + |
| 121 | +(( $+functions[_multirust_remove-override] )) || |
| 122 | +_multirust_remove-override() { |
| 123 | + __overrides |
| 124 | +} |
| 125 | + |
| 126 | +(( $+functions[_multirust_remove-toolchain] )) || |
| 127 | +_multirust_remove-toolchain() { |
| 128 | + __toolchains |
| 129 | +} |
| 130 | + |
| 131 | +(( $+functions[_multirust_run] )) || |
| 132 | +_multirust_run() { |
| 133 | + __toolchains |
| 134 | +} |
| 135 | + |
| 136 | +(( $+functions[_multirust_delete-data] )) || |
| 137 | +_multirust_delete-data() { |
| 138 | + _arguments -s \ |
| 139 | + "-y[Disable prompt]" \ |
| 140 | + "*::multirust commands:_multirust" |
| 141 | +} |
| 142 | + |
| 143 | +(( $+functions[_multirust_doc] )) || |
| 144 | +_multirust_doc() { |
| 145 | + _arguments -s \ |
| 146 | + "--all[open the documentation overview page, which gives access to all the installed documentation]:" \ |
| 147 | + "*::multirust commands:_multirust" |
| 148 | +} |
| 149 | + |
| 150 | +(( $+functions[_multirust_help] )) || |
| 151 | +_multirust_help() { |
| 152 | + __subcommands |
| 153 | +} |
| 154 | + |
| 155 | +_multirust "$@" |
| 156 | + |
| 157 | +# Local Variables: |
| 158 | +# mode: Shell-Script |
| 159 | +# sh-indentation: 2 |
| 160 | +# indent-tabs-mode: nil |
| 161 | +# sh-basic-offset: 2 |
| 162 | +# End: |
| 163 | +# vim: ft=zsh sw=2 ts=2 et |
0 commit comments