Commit 05dfd0ae authored by Marc Cornellà's avatar Marc Cornellà
Browse files

cargo: update completion to latest version (cdac4a8)

https://github.com/rust-lang/cargo/blob/cdac4a8/src/etc/_cargo
parent aebf333b
...@@ -2,489 +2,367 @@ ...@@ -2,489 +2,367 @@
autoload -U regexp-replace autoload -U regexp-replace
zstyle -T ':completion:*:*:cargo:*' tag-order && \
zstyle ':completion:*:*:cargo:*' tag-order 'common-commands'
_cargo() { _cargo() {
local context state state_descr line local curcontext="$curcontext" ret=1
typeset -A opt_args local -a command_scope_spec common parallel features msgfmt triple target registry
local -a state line state_descr # These are set by _arguments
# leading items in parentheses are an exclusion list for the arguments following that arg typeset -A opt_args
# See: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions
# - => exclude all other options common=(
# 1 => exclude positional arg 1 '(-q --quiet)*'{-v,--verbose}'[use verbose output]'
# * => exclude all other args '(-q --quiet -v --verbose)'{-q,--quiet}'[no output printed to stdout]'
# +blah => exclude +blah '-Z+[pass unstable (nightly-only) flags to cargo]: :_cargo_unstable_flags'
_arguments \ '--frozen[require that Cargo.lock and cache are up-to-date]'
'(- 1 *)'{-h,--help}'[show help message]' \ '--locked[require that Cargo.lock is up-to-date]'
'(- 1 *)--list[list installed commands]' \ '--color=[specify colorization option]:coloring:(auto always never)'
'(- 1 *)'{-V,--version}'[show version information]' \ '(- 1 *)'{-h,--help}'[show help message]'
{-v,--verbose}'[use verbose output]' \ )
--color'[colorization option]' \
'(+beta +nightly)+stable[use the stable toolchain]' \ # leading items in parentheses are an exclusion list for the arguments following that arg
'(+stable +nightly)+beta[use the beta toolchain]' \ # See: http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions
'(+stable +beta)+nightly[use the nightly toolchain]' \ # - => exclude all other options
'1: :->command' \ # 1 => exclude positional arg 1
'*:: :->args' # * => exclude all other args
# +blah => exclude +blah
case $state in _arguments -s -S -C $common \
command) '(- 1 *)--list[list installed commands]' \
_alternative 'common-commands:common:_cargo_cmds' 'all-commands:all:_cargo_all_cmds' '(- 1 *)--explain=[provide a detailed explanation of an error message]:error code' \
;; '(- 1 *)'{-V,--version}'[show version information]' \
'(+beta +nightly)+stable[use the stable toolchain]' \
args) '(+stable +nightly)+beta[use the beta toolchain]' \
case $words[1] in '(+stable +beta)+nightly[use the nightly toolchain]' \
bench) '1: :_cargo_cmds' \
_arguments \ '*:: :->args'
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \ # These flags are mutually exclusive specifiers for the scope of a command; as
'(-h, --help)'{-h,--help}'[show help message]' \ # they are used in multiple places without change, they are expanded into the
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ # appropriate command's `_arguments` where appropriate.
"${command_scope_spec[@]}" \ command_scope_spec=(
'--manifest-path=[path to manifest]: :_files -/' \ '(--bin --example --test --lib)--bench=[specify benchmark name]: :_cargo_benchmark_names'
'--no-default-features[do not build the default features]' \ '(--bench --bin --test --lib)--example=[specify example name]:example name'
'--no-run[compile but do not run]' \ '(--bench --example --test --lib)--bin=[specify binary name]:binary name'
'(-p,--package)'{-p=,--package=}'[package to run benchmarks for]:packages:_get_package_names' \ '(--bench --bin --example --test)--lib=[specify library name]:library name'
'--target=[target triple]' \ '(--bench --bin --example --lib)--test=[specify test name]:test name'
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ )
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--color=:colorization option:(auto always never)' \ parallel=(
;; '(-j --jobs)'{-j+,--jobs=}'[specify number of parallel jobs]:jobs [# of CPUs]'
)
build)
_arguments \ features=(
'--features=[space separated feature list]' \ '(--all-features)--features=[specify features to activate]:feature'
'--all-features[enable all available features]' \ '(--features)--all-features[activate all available features]'
'(-h, --help)'{-h,--help}'[show help message]' \ "--no-default-features[don't build the default features]"
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ )
"${command_scope_spec[@]}" \
'--manifest-path=[path to manifest]: :_files -/' \ msgfmt='--message-format=[specify error format]:error format [human]:(human json short)'
'--no-default-features[do not build the default features]' \ triple='--target=[specify target triple]:target triple'
'(-p,--package)'{-p=,--package=}'[package to build]:packages:_get_package_names' \ target='--target-dir=[specify directory for all generated artifacts]:directory:_directories'
'--release=[build in release mode]' \ manifest='--manifest-path=[specify path to manifest]:path:_directories'
'--target=[target triple]' \ registry='--registry=[specify registry to use]:registry'
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ case $state in
'--color=:colorization option:(auto always never)' \ args)
;; curcontext="${curcontext%:*}-${words[1]}:"
case ${words[1]} in
check) bench)
_arguments \ _arguments -s -A "^--" $common $parallel $features $msgfmt $triple $target $manifest \
'--features=[space separated feature list]' \ "${command_scope_spec[@]}" \
'--all-features[enable all available features]' \ '--all-targets[benchmark all targets]' \
'(-h, --help)'{-h,--help}'[show help message]' \ "--no-run[compile but don't run]" \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ '(-p --package)'{-p+,--package=}'[specify package to run benchmarks for]:package:_cargo_package_names' \
"${command_scope_spec[@]}" \ '--exclude=[exclude packages from the benchmark]:spec' \
'--manifest-path=[path to manifest]: :_files -/' \ '--no-fail-fast[run all benchmarks regardless of failure]' \
'--no-default-features[do not check the default features]' \ '1: :_guard "^-*" "bench name"' \
'(-p,--package)'{-p=,--package=}'[package to check]:packages:_get_package_names' \ '*:args:_default'
'--release=[check in release mode]' \ ;;
'--target=[target triple]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ build)
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--color=:colorization option:(auto always never)' \ '--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
;; "${command_scope_spec[@]}" \
'(-p --package)'{-p+,--package=}'[specify package to build]:package:_cargo_package_names' \
clean) '--release[build in release mode]' \
_arguments \ '--build-plan[output the build plan in JSON]' \
'(-h, --help)'{-h,--help}'[show help message]' \ ;;
'--manifest-path=[path to manifest]: :_files -/' \
'(-p,--package)'{-p=,--package=}'[package to clean]:packages:_get_package_names' \ check)
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--release[whether or not to clean release artifacts]' \ '--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
'--target=[target triple(default:all)]' \ "${command_scope_spec[@]}" \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(-p --package)'{-p+,--package=}'[specify package to check]:package:_cargo_package_names' \
'--color=:colorization option:(auto always never)' \ '--release[check in release mode]' \
;; ;;
doc) clean)
_arguments \ _arguments -s -S $common $triple $target $manifest \
'--features=[space separated feature list]' \ '(-p --package)'{-p+,--package=}'[specify package to clean]:package:_cargo_package_names' \
'--all-features[enable all available features]' \ '--release[clean release artifacts]' \
'(-h, --help)'{-h,--help}'[show help message]' \ '--doc[clean just the documentation directory]'
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ ;;
'--manifest-path=[path to manifest]: :_files -/' \
'--no-deps[do not build docs for dependencies]' \ doc)
'--no-default-features[do not build the default features]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'--open[open docs in browser after the build]' \ '--no-deps[do not build docs for dependencies]' \
'(-p, --package)'{-p,--package}'=[package to document]' \ '--document-private-items[include non-public items in the documentation]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '--open[open docs in browser after the build]' \
'--release[build artifacts in release mode, with optimizations]' \ '(-p --package)'{-p+,--package=}'[specify package to document]:package:_cargo_package_names' \
'--target=[build for the target triple]' \ '--release[build artifacts in release mode, with optimizations]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ ;;
'--color=:colorization option:(auto always never)' \
;; fetch)
_arguments -s -S $common $triple $manifest
fetch) ;;
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \ fix)
'--manifest-path=[path to manifest]: :_files -/' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ "${command_scope_spec[@]}" \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--broken-code[fix code even if it already has compiler errors]' \
'--color=:colorization option:(auto always never)' \ '--edition[fix in preparation for the next edition]' \
;; '--edition-idioms[fix warnings to migrate to the idioms of an edition]' \
'--allow-no-vcs[fix code even if a VCS was not detected]' \
generate-lockfile) '--allow-dirty[fix code even if the working directory is dirty]' \
_arguments \ '--allow-staged[fix code even if the working directory has staged changes]'
'(-h, --help)'{-h,--help}'[show help message]' \ ;;
'--manifest-path=[path to manifest]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ generate-lockfile)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _arguments -s -S $common $manifest
'--color=:colorization option:(auto always never)' \ ;;
;;
git-checkout)
git-checkout) _arguments -s -S $common \
_arguments \ '--reference=:reference' \
'(-h, --help)'{-h,--help}'[show help message]' \ '--url=:url:_urls'
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ ;;
'--reference=[REF]' \
'--url=[URL]' \ help)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _cargo_cmds
'--color=:colorization option:(auto always never)' \ ;;
;;
init)
help) _arguments -s -S $common $registry \
_arguments \ '--lib[use library template]' \
'(-h, --help)'{-h,--help}'[show help message]' \ '--edition=[specify edition to set for the crate generated]:edition:(2015 2018)' \
'*: :_cargo_cmds' \ '--vcs=[initialize a new repo with a given VCS]:vcs:(git hg pijul fossil none)' \
;; '--name=[set the resulting package name]:name' \
'1:path:_directories'
init) ;;
_arguments \
'--bin[use binary template]' \ install)
'--vcs:initialize a new repo with a given VCS:(git hg none)' \ _arguments -s -S $common $parallel $features $triple $registry \
'(-h, --help)'{-h,--help}'[show help message]' \ '(-f --force)'{-f,--force}'[force overwriting of existing crates or binaries]' \
'--name=[set the resulting package name]' \ '--bin=[only install the specified binary]:binary' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '--branch=[branch to use when installing from git]:branch' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--debug[build in debug mode instead of release mode]' \
'--color=:colorization option:(auto always never)' \ '--example=[install the specified example instead of binaries]:example' \
;; '--git=[specify URL from which to install the crate]:url:_urls' \
'--path=[local filesystem path to crate to install]: :_directories' \
install) '--rev=[specific commit to use when installing from git]:commit' \
_arguments \ '--root=[directory to install packages into]: :_directories' \
'--bin=[only install the specified binary]' \ '--tag=[tag to use when installing from git]:tag' \
'--branch=[branch to use when installing from git]' \ '--vers=[version to install from crates.io]:version' \
'--color=:colorization option:(auto always never)' \ '--list[list all installed packages and their versions]' \
'--debug[build in debug mode instead of release mode]' \ '*: :_guard "^-*" "crate"'
'--example[install the specified example instead of binaries]' \ ;;
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \ locate-project)
'--git=[URL from which to install the crate]' \ _arguments -s -S $common $manifest
'(-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]' \ login)
'--path=[local filesystem path to crate to install]: :_files -/' \ _arguments -s -S $common $registry \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '*: :_guard "^-*" "token"'
'--rev=[specific commit to use when installing from git]' \ ;;
'--root=[directory to install packages into]: :_files -/' \
'--tag=[tag to use when installing from git]' \ metadata)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _arguments -s -S $common $features $manifest \
'--vers=[version to install from crates.io]' \ "--no-deps[output information only about the root package and don't fetch dependencies]" \
;; '--format-version=[specify format version]:version [1]:(1)'
;;
locate-project)
_arguments \ new)
'(-h, --help)'{-h,--help}'[show help message]' \ _arguments -s -S $common $registry \
'--manifest-path=[path to manifest]: :_files -/' \ '--lib[use library template]' \
;; '--vcs:initialize a new repo with a given VCS:(git hg none)' \
'--name=[set the resulting package name]'
login) ;;
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \ owner)
'--host=[Host to set the token for]' \ _arguments -s -S $common $registry \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '(-a --add)'{-a,--add}'[specify name of a user or team to invite as an owner]:name' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--index=[specify registry index]:index' \
'--color=:colorization option:(auto always never)' \ '(-l --list)'{-l,--list}'[list owners of a crate]' \
;; '(-r --remove)'{-r,--remove}'[specify name of a user or team to remove as an owner]:name' \
'--token=[specify API token to use when authenticating]:token' \
metadata) '*: :_guard "^-*" "crate"'
_arguments \ ;;
'(-h, --help)'{-h,--help}'[show help message]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ package)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _arguments -s -S $common $parallel $features $triple $target $manifest \
"--no-deps[output information only about the root package and don't fetch dependencies]" \ '(-l --list)'{-l,--list}'[print files included in a package without making one]' \
'--no-default-features[do not include the default feature]' \ '--no-metadata[ignore warnings about a lack of human-usable metadata]' \
'--manifest-path=[path to manifest]: :_files -/' \ '--allow-dirty[allow dirty working directories to be packaged]' \
'--features=[space separated feature list]' \ "--no-verify[don't build to verify contents]"
'--all-features[enable all available features]' \ ;;
'--format-version=[format version(default: 1)]' \
'--color=:colorization option:(auto always never)' \ pkgid)
;; _arguments -s -S $common $manifest \
'(-p --package)'{-p+,--package=}'[specify package to get ID specifier for]:package:_cargo_package_names' \
new) '*: :_guard "^-*" "spec"'
_arguments \ ;;
'--bin[use binary template]' \
'--vcs:initialize a new repo with a given VCS:(git hg none)' \ publish)
'(-h, --help)'{-h,--help}'[show help message]' \ _arguments -s -S $common $parallel $features $triple $target $manifest $registry \
'--name=[set the resulting package name]' \ '--index=[specify registry index]:index' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '--allow-dirty[allow dirty working directories to be packaged]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ "--no-verify[don't verify the contents by building them]" \
'--color=:colorization option:(auto always never)' \ '--token=[specify token to use when uploading]:token' \
;; '--dry-run[perform all checks without uploading]'
;;
owner)
_arguments \ read-manifest)
'(-a, --add)'{-a,--add}'[add owner LOGIN]' \ _arguments -s -S $common $manifest
'(-h, --help)'{-h,--help}'[show help message]' \ ;;
'--index[registry index]' \
'(-l, --list)'{-l,--list}'[list owners of a crate]' \ run)
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'(-r, --remove)'{-r,--remove}'[remove owner LOGIN]' \ '--example=[name of the bin target]:name' \
'--token[API token to use when authenticating]' \ '--bin=[name of the bin target]:name' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(-p --package)'{-p+,--package=}'[specify package with the target to run]:package:_cargo_package_names' \
'--color=:colorization option:(auto always never)' \ '--release[build in release mode]' \
;; '*: :_default'
;;
package)
_arguments \ rustc)
'(-h, --help)'{-h,--help}'[show help message]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'(-l, --list)'{-l,--list}'[print files included in a package without making one]' \ '(-p --package)'{-p+,--package=}'[specify package to build]:package:_cargo_package_names' \
'--manifest-path=[path to manifest]: :_files -/' \ '--profile=[specify profile to build the selected target for]:profile' \
'--no-metadata[ignore warnings about a lack of human-usable metadata]' \ '--release[build artifacts in release mode, with optimizations]' \
'--no-verify[do not build to verify contents]' \ "${command_scope_spec[@]}" \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '*: : _dispatch rustc rustc -default-'
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ ;;
'--color=:colorization option:(auto always never)' \
;; rustdoc)
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
pkgid) '--document-private-items[include non-public items in the documentation]' \
_arguments \ '--open[open the docs in a browser after the operation]' \
'(-h, --help)'{-h,--help}'[show help message]' \ '(-p --package)'{-p+,--package=}'[specify package to document]:package:_cargo_package_names' \
'--manifest-path=[path to manifest]: :_files -/' \ '--release[build artifacts in release mode, with optimizations]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ "${command_scope_spec[@]}" \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '*: : _dispatch rustdoc rustdoc -default-'
'--color=:colorization option:(auto always never)' \ ;;
;;
search)
publish) _arguments -s -S $common $registry \
_arguments \ '--index=[specify registry index]:index' \
'(-h, --help)'{-h,--help}'[show help message]' \ '--limit=[limit the number of results]:results [10]' \
'--host=[Host to set the token for]' \ '*: :_guard "^-*" "query"'
'--manifest-path=[path to manifest]: :_files -/' \ ;;
'--no-verify[Do not verify tarball until before publish]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ test)
'--token[token to use when uploading]' \ _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--test=[test name]: :_cargo_test_names' \
'--color=:colorization option:(auto always never)' \ '--no-fail-fast[run all tests regardless of failure]' \
;; '--no-run[compile but do not run]' \
'(-p --package)'{-p+,--package=}'[package to run tests for]:package:_cargo_package_names' \
read-manifest) '--all[test all packages in the workspace]' \
_arguments \ '--release[build artifacts in release mode, with optimizations]' \
'(-h, --help)'{-h,--help}'[show help message]' \ '1: :_cargo_test_names' \
'--manifest-path=[path to manifest]: :_files -/' \ '(--doc --bin --example --test --bench)--lib[only test library]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(--lib --bin --example --test --bench)--doc[only test documentation]' \
'--color=:colorization option:(auto always never)' \ '(--lib --doc --example --test --bench)--bin=[binary name]' \
;; '(--lib --doc --bin --test --bench)--example=[example name]' \
'(--lib --doc --bin --example --bench)--test=[test name]' \
run) '(--lib --doc --bin --example --test)--bench=[benchmark name]' \
_arguments \ '*: :_default'
'--example=[name of the bin target]' \ ;;
'--features=[space separated feature list]' \
'--all-features[enable all available features]' \ uninstall)
'(-h, --help)'{-h,--help}'[show help message]' \ _arguments -s -S $common \
'(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \ '(-p --package)'{-p+,--package=}'[specify package to uninstall]:package:_cargo_package_names' \
'--manifest-path=[path to manifest]: :_files -/' \ '--bin=[only uninstall the specified binary]:name' \
'--bin=[name of the bin target]' \ '--root=[directory to uninstall packages from]: :_files -/' \
'--no-default-features[do not build the default features]' \ '*:crate:_cargo_installed_crates -F line'
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ ;;
'--release=[build in release mode]' \
'--target=[target triple]' \ update)
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ _arguments -s -S $common $manifest \
'--color=:colorization option:(auto always never)' \ '--aggressive=[force dependency update]' \
'*: :_normal' \ "--dry-run[don't actually write the lockfile]" \
;; '(-p --package)'{-p+,--package=}'[specify package to update]:package:_cargo_package_names' \
'--precise=[update single dependency to precise release]:release'
rustc) ;;
_arguments \
'--color=:colorization option:(auto always never)' \ verify-project)
'--features=[features to compile for the package]' \ _arguments -s -S $common $manifest
'--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]' \ version)
'--manifest-path=[path to the manifest to fetch dependencies for]: :_files -/' \ _arguments -s -S $common
'--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]' \ yank)
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ _arguments -s -S $common $registry \
'--release[build artifacts in release mode, with optimizations]' \ '--vers=[specify yank version]:version' \
'--target=[target triple which compiles will be for]' \ '--undo[undo a yank, putting a version back into the index]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--index=[specify registry index to yank from]:registry index' \
"${command_scope_spec[@]}" \ '--token=[specify API token to use when authenticating]:token' \
;; '*: :_guard "^-*" "crate"'
;;
rustdoc) *)
_arguments \ # allow plugins to define their own functions
'--color=:colorization option:(auto always never)' \ if ! _call_function ret _cargo-${words[1]}; then
'--features=[space-separated list of features to also build]' \ # fallback on default completion for unknown commands
'--all-features[enable all available features]' \ _default && ret=0
'(-h, --help)'{-h,--help}'[show help message]' \ fi
'(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \ (( ! ret ))
'--manifest-path=[path to the manifest to document]: :_files -/' \ ;;
'--no-default-features[do not build the `default` feature]' \ esac
'--open[open the docs in a browser after the operation]' \ ;;
'(-p, --package)'{-p,--package}'=[package to document]' \ esac
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ }
'--release[build artifacts in release mode, with optimizations]' \
'--target=[build for the target triple]' \ _cargo_unstable_flags() {
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ local flags
"${command_scope_spec[@]}" \ flags=( help ${${${(M)${(f)"$(_call_program flags cargo -Z help)"}:#*--*}/ #-- #/:}##*-Z } )
;; _describe -t flags 'unstable flag' flags
search)
_arguments \
'--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]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
;;
test)
_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]' \
'--manifest-path=[path to manifest]: :_files -/' \
'--test=[test name]: :_test_names' \
'--no-default-features[do not build the default features]' \
'--no-fail-fast[run all tests regardless of failure]' \
'--no-run[compile but do not run]' \
'(-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]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--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=: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]: :_files -/' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
;;
update)
_arguments \
'--aggressive=[force dependency update]' \
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]: :_files -/' \
'(-p,--package)'{-p=,--package=}'[package to update]:packages:__get_package_names' \
'--precise=[update single dependency to PRECISE]: :' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
;;
verify-project)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--manifest-path=[path to manifest]: :_files -/' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
;;
version)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
'--color=:colorization option:(auto always never)' \
;;
yank)
_arguments \
'(-h, --help)'{-h,--help}'[show help message]' \
'--index[registry index]' \
'(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
'--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=:colorization option:(auto always never)' \
'--vers[yank version]' \
;;
esac
;;
esac
} }
_cargo_cmds(){ _cargo_installed_crates() {
local -a commands;commands=( local expl
'bench:execute all benchmarks of a local package' _description crates expl 'crate'
'build:compile the current package' compadd "$@" "$expl[@]" - ${${${(f)"$(cargo install --list)"}:# *}%% *}
'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 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 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'
'publish:upload package to the registry'
'read-manifest:print manifest in JSON format'
'run:run the main binary of the local package'
'rustc:compile a package and all of its dependencies'
'rustdoc:build documentation for a package'
'search:search packages on crates.io'
'test:execute all unit and tests of a local package'
'uninstall:remove a Rust binary'
'update:update dependencies'
'verify-project:check Cargo.toml'
'version:show version information'
'yank:remove pushed file from index'
)
_describe -t common-commands 'common commands' commands
} }
_cargo_all_cmds(){ _cargo_cmds() {
local -a commands;commands=($(cargo --list)) local -a commands
_describe -t all-commands 'all commands' commands # This uses Parameter Expansion Flags, which are a built-in Zsh feature.
# See more: http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
# and http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion
#
# # How this work?
#
# First it splits the result of `cargo --list` at newline, then it removes the first line.
# Then it removes indentation (4 whitespaces) before each items. (Note the x## pattern [1]).
# Then it replaces those spaces between item and description with a `:`
#
# [1]: https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#patterns
commands=( ${${${(M)"${(f)$(_call_program commands cargo --list)}":# *}/ ##/}/ ##/:} )
_describe -t commands 'command' commands
} }
#FIXME: Disabled until fixed #FIXME: Disabled until fixed
#gets package names from the manifest file #gets package names from the manifest file
_get_package_names() _cargo_package_names() {
{ _message -e packages package
}
#TODO:see if it makes sense to have 'locate-project' to have non-json output.
#strips package name from json stuff
_locate_manifest(){
local manifest=`cargo locate-project 2>/dev/null`
regexp-replace manifest '\{"root":"|"\}' ''
echo $manifest
} }
# Extracts the values of "name" from the array given in $1 and shows them as # Extracts the values of "name" from the array given in $1 and shows them as
# command line options for completion # command line options for completion
_get_names_from_array() _cargo_names_from_array() {
{ # strip json from the path
local -a filelist; local manifest=${${${"$(cargo locate-project)"}%\"\}}##*\"}
local manifest=$(_locate_manifest)
if [[ -z $manifest ]]; then if [[ -z $manifest ]]; then
return 0 return 0
fi fi
...@@ -494,51 +372,36 @@ _get_names_from_array() ...@@ -494,51 +372,36 @@ _get_names_from_array()
local in_block=false local in_block=false
local block_name=$1 local block_name=$1
names=() names=()
while read line while read -r line; do
do
if [[ $last_line == "[[$block_name]]" ]]; then if [[ $last_line == "[[$block_name]]" ]]; then
in_block=true in_block=true
else else
if [[ $last_line =~ '.*\[\[.*' ]]; then if [[ $last_line =~ '\s*\[\[.*' ]]; then
in_block=false in_block=false
fi fi
fi fi
if [[ $in_block == true ]]; then if [[ $in_block == true ]]; then
if [[ $line =~ '.*name.*=' ]]; then if [[ $line =~ '\s*name\s*=' ]]; then
regexp-replace line '^.*name *= *|"' "" regexp-replace line '^\s*name\s*=\s*|"' ''
names+=$line names+=( "$line" )
fi fi
fi fi
last_line=$line last_line=$line
done < $manifest done < "$manifest"
_describe $block_name names _describe "$block_name" names
} }
#Gets the test names from the manifest file #Gets the test names from the manifest file
_test_names() _cargo_test_names() {
{ _cargo_names_from_array "test"
_get_names_from_array "test"
} }
#Gets the bench names from the manifest file #Gets the bench names from the manifest file
_benchmark_names() _cargo_benchmark_names() {
{ _cargo_names_from_array "bench"
_get_names_from_array "bench"
} }
# 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
command_scope_spec=(
'(--bin --example --test --lib)--bench=[benchmark name]: :_benchmark_names'
'(--bench --bin --test --lib)--example=[example name]'
'(--bench --example --test --lib)--bin=[binary name]'
'(--bench --bin --example --test)--lib=[library name]'
'(--bench --bin --example --lib)--test=[test name]'
)
_cargo _cargo
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment