Update _cargo completion to 0.34.0 version

This commit is contained in:
Marc Cornellà 2019-03-25 22:40:50 +01:00 committed by GitHub
parent cf07fe2c6f
commit a441f64d09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,23 +1,37 @@
#compdef cargo
typeset -A opt_args
autoload -U regexp-replace
_cargo() {
zstyle -T ':completion:*:*:cargo:*' tag-order && \
zstyle ':completion:*:*:cargo:*' tag-order 'common-commands'
_cargo() {
local context state state_descr line
typeset -A opt_args
# leading items in parentheses are an exclusion list for the arguments following that arg
# See: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions
# - => exclude all other options
# 1 => exclude positional arg 1
# * => exclude all other args
# +blah => exclude +blah
_arguments \
'(- 1 *)'{-h,--help}'[show help message]' \
'(- 1 *)--list[list installed commands]' \
'(- 1 *)'{-V,--version}'[show version information]' \
'(- 1 *)'--list'[list installed commands]' \
'(- 1 *)'--explain'[Run `rustc --explain CODE`]' \
'(- 1 *)'{-v,--verbose}'[use verbose output]' \
'(- 1 *)'--color'[colorization option]' \
'(- 1 *)'--frozen'[Require Cargo.lock and cache are up to date]' \
'(- 1 *)'--locked'[Require Cargo.lock is up to date]' \
'1: :_cargo_cmds' \
{-v,--verbose}'[use verbose output]' \
--color'[colorization option]' \
'(+beta +nightly)+stable[use the stable toolchain]' \
'(+stable +nightly)+beta[use the beta toolchain]' \
'(+stable +beta)+nightly[use the nightly toolchain]' \
'1: :->command' \
'*:: :->args'
case $state in
command)
_alternative 'common-commands:common:_cargo_cmds' 'all-commands:all:_cargo_all_cmds'
;;
args)
case $words[1] in
bench)
@ -31,11 +45,10 @@ case $state in
'--no-default-features[do not build the default features]' \
'--no-run[compile but do not run]' \
'(-p,--package)'{-p=,--package=}'[package to run benchmarks for]:packages:_get_package_names' \
'--target=[target triple]: :_get_targets' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--message-format=[error format]:format option:(human json)' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
build)
@ -49,11 +62,27 @@ case $state in
'--no-default-features[do not build the default features]' \
'(-p,--package)'{-p=,--package=}'[package to build]:packages:_get_package_names' \
'--release=[build in release mode]' \
'--target=[target triple]: :_get_targets' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--message-format=[error format]:format option:(human json)' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
check)
_arguments \
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
"${command_scope_spec[@]}" \
'--manifest-path=[path to manifest]: :_files -/' \
'--no-default-features[do not check the default features]' \
'(-p,--package)'{-p=,--package=}'[package to check]:packages:_get_package_names' \
'--release=[check in release mode]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--color=:colorization option:(auto always never)' \
;;
clean)
@ -63,9 +92,9 @@ case $state in
'(-p,--package)'{-p=,--package=}'[package to clean]:packages:_get_package_names' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--release[whether or not to clean release artifacts]' \
'--target=[target triple(default:all)]: :_get_targets' \
'--target=[target triple(default:all)]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
doc)
@ -81,9 +110,9 @@ case $state in
'(-p, --package)'{-p,--package}'=[package to document]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--release[build artifacts in release mode, with optimizations]' \
'--target=[build for the target triple]: :_get_targets' \
'--target=[build for the target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
fetch)
@ -92,7 +121,7 @@ case $state in
'--manifest-path=[path to manifest]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
generate-lockfile)
@ -101,17 +130,17 @@ case $state in
'--manifest-path=[path to manifest]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
git-checkout)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'q(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--reference=[REF]' \
'--url=[URL]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
help)
@ -128,14 +157,14 @@ case $state in
'--name=[set the resulting package name]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
install)
_arguments \
'--bin=[only install the specified binary]' \
'--branch=[branch to use when installing from git]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
'--debug[build in debug mode instead of release mode]' \
'--example[install the specified example instead of binaries]' \
'--features=[space separated feature list]' \
@ -144,10 +173,10 @@ case $state in
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
'--no-default-features[do not build the default features]' \
'--path=[local filesystem path to crate to install]' \
'--path=[local filesystem path to crate to install]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--rev=[specific commit to use when installing from git]' \
'--root=[directory to install packages into]' \
'--root=[directory to install packages into]: :_files -/' \
'--tag=[tag to use when installing from git]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--vers=[version to install from crates.io]' \
@ -165,7 +194,7 @@ case $state in
'--host=[Host to set the token for]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
metadata)
@ -179,7 +208,7 @@ case $state in
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \
'--format-version=[format version(default: 1)]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
new)
@ -190,7 +219,7 @@ case $state in
'--name=[set the resulting package name]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
owner)
@ -203,7 +232,7 @@ case $state in
'(-r, --remove)'{-r,--remove}'[remove owner LOGIN]' \
'--token[API token to use when authenticating]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
package)
@ -215,7 +244,7 @@ case $state in
'--no-verify[do not build to verify contents]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
pkgid)
@ -224,7 +253,7 @@ case $state in
'--manifest-path=[path to manifest]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
publish)
@ -236,7 +265,7 @@ case $state in
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--token[token to use when uploading]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
read-manifest)
@ -244,7 +273,7 @@ case $state in
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]: :_files -/' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
run)
@ -261,52 +290,49 @@ case $state in
'--release=[build in release mode]' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--message-format=[error format]:format option:(human json)' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
'*: :_normal' \
;;
rustc)
_arguments \
'--message-format=[error format]:format option:(human json)' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
'--features=[features to compile for the package]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
'--manifest-path=[path to the manifest to fetch dependencies for]' \
'--manifest-path=[path to the manifest to fetch dependencies for]: :_files -/' \
'--no-default-features[do not compile default features for the package]' \
'(-p, --package)'{-p,--package}'=[profile to compile for]' \
'--profile=[profile to build the selected target for]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--release[build artifacts in release mode, with optimizations]' \
'--target=[target triple which compiles will be for]: :_get_targets' \
'--target=[target triple which compiles will be for]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
"${command_scope_spec[@]}" \
;;
rustdoc)
_arguments \
'--message-format=[error format]:format option:(human json)' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
'--features=[space-separated list of features to also build]' \
'--all-features[enable all available features]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
'--manifest-path=[path to the manifest to document]' \
'--manifest-path=[path to the manifest to document]: :_files -/' \
'--no-default-features[do not build the `default` feature]' \
'--open[open the docs in a browser after the operation]' \
'(-p, --package)'{-p,--package}'=[package to document]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--release[build artifacts in release mode, with optimizations]' \
'--target=[build for the target triple]: :_get_targets' \
'--target=[build for the target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
"${command_scope_spec[@]}" \
;;
search)
_arguments \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
'(-h, --help)'{-h,--help}'[show help message]' \
'--host=[host of a registry to search in]' \
'--limit=[limit the number of results]' \
@ -328,20 +354,28 @@ case $state in
'(-p,--package)'{-p=,--package=}'[package to run tests for]:packages:_get_package_names' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--release[build artifacts in release mode, with optimizations]' \
'--target=[target triple]: :_get_targets' \
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--message-format=[error format]:format option:(human json)' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
'1: :_test_names' \
'(--doc --bin --example --test --bench)--lib[only test library]' \
'(--lib --bin --example --test --bench)--doc[only test documentation]' \
'(--lib --doc --example --test --bench)--bin=[binary name]' \
'(--lib --doc --bin --test --bench)--example=[example name]' \
'(--lib --doc --bin --example --bench)--test=[test name]' \
'(--lib --doc --bin --example --test)--bench=[benchmark name]' \
'--message-format:error format:(human json short)' \
'--frozen[require lock and cache up to date]' \
'--locked[require lock up to date]'
;;
uninstall)
_arguments \
'--bin=[only uninstall the binary NAME]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-q, --quiet)'{-q,--quiet}'[less output printed to stdout]' \
'--root=[directory to uninstall packages from]' \
'--root=[directory to uninstall packages from]: :_files -/' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
;;
@ -354,7 +388,7 @@ case $state in
'--precise=[update single dependency to PRECISE]: :' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
verify-project)
@ -363,14 +397,14 @@ case $state in
'--manifest-path=[path to manifest]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
version)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
;;
yank)
@ -381,7 +415,7 @@ case $state in
'--token[API token to use when authenticating]' \
'--undo[undo a yank, putting a version back into the index]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=[coloring]:colorization option:(auto always never)' \
'--color=:colorization option:(auto always never)' \
'--vers[yank version]' \
;;
esac
@ -390,22 +424,22 @@ esac
}
_cargo_cmds(){
local IFS=$'\n'
local -a commands;commands=(
'bench:execute all benchmarks of a local package'
'build:compile the current project'
'build:compile the current package'
'check:check the current package without compiling'
'clean:remove generated artifacts'
'doc:build package documentation'
'fetch:fetch package dependencies'
'generate-lockfile:create lockfile'
'git-checkout:git checkout'
'help:get help for commands'
'init:create new project in current directory'
'init:create new package in current directory'
'install:install a Rust binary'
'locate-project:print "Cargo.toml" location'
'login:login to remote server'
'metadata:the metadata for a project in json'
'new:create a new project'
'metadata:the metadata for a package in json'
'new:create a new package'
'owner:manage the owners of a crate on the registry'
'package:assemble local package into a distributable tarball'
'pkgid:print a fully qualified package specification'
@ -421,10 +455,13 @@ local -a commands;commands=(
'verify-project:check Cargo.toml'
'version:show version information'
'yank:remove pushed file from index'
$( cargo --list | sed -n '1!p' | tr -s ' ' | cut -d ' ' -f 2 | egrep -v "^bench$|^build$|^clean$|^doc$|^fetch$|^generate-lockfile$|^git-checkout$|^help$|^init$|^install$|^locate-project$|^login$|^metadata$|^new$|^owner$|^package$|^pkgid$|^publish$|^read-manifest$|^run$|^rustc$|^rustdoc$|^search$|^test$|^uninstall$|^update$|^verify-project$|^version$|^yank$" | sed "s/\(.*\)/echo \"\1:$\(cargo help \1 2>\&1 | head -n 1\)\"/" | sh )
)
_describe 'command' commands
_describe -t common-commands 'common commands' commands
}
_cargo_all_cmds(){
local -a commands;commands=($(cargo --list))
_describe -t all-commands 'all commands' commands
}
@ -492,38 +529,7 @@ _benchmark_names()
_get_names_from_array "bench"
}
#Gets the target names from config files
_get_targets()
{
local CURRENT_PATH
if [[ $(uname -o) = "Cygwin" && -f "$PWD"/Cargo.toml ]]; then
CURRENT_PATH=$PWD
else
CURRENT_PATH=$(_locate_manifest)
fi
if [[ -z "$CURRENT_PATH" ]]; then
return 1
fi
local -a TARGETS
local -a FIND_PATHS=( "/" )
local -a FLINES
local FIND_PATH FLINE
while [[ "$CURRENT_PATH" != "/" ]]; do
FIND_PATHS+=( "$CURRENT_PATH" )
CURRENT_PATH=$(dirname $CURRENT_PATH)
done
for FIND_PATH in ${FIND_PATHS[@]}; do
if [[ -f "$FIND_PATH"/.cargo/config ]]; then
FLINES=( `grep "$FIND_PATH"/.cargo/config -e "^\[target\."` )
for FLINE in ${FLINES[@]}; do
TARGETS+=(`sed 's/^\[target\.\(.*\)\]$/\1/' <<< $FLINE`)
done
fi
done
_describe 'target' TARGETS
}
# These flags are mutally exclusive specifiers for the scope of a command; as
# These flags are mutually exclusive specifiers for the scope of a command; as
# they are used in multiple places without change, they are expanded into the
# appropriate command's `_arguments` where appropriate.
set command_scope_spec
@ -535,5 +541,4 @@ command_scope_spec=(
'(--bench --bin --example --lib)--test=[test name]'
)
_cargo