From d326cc5c411ac17f1a2befa1e717d221b2bbbf35 Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Sat, 7 Jan 2017 20:32:56 +1100 Subject: [PATCH 1/9] target name completion --- plugins/cargo/_cargo | 45 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index 54e709ca0..3eb3acb96 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -31,7 +31,7 @@ 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]' \ + '--target=[target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '--color=:colorization option:(auto always never)' \ @@ -48,7 +48,7 @@ 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]' \ + '--target=[target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ '--color=:colorization option:(auto always never)' \ @@ -61,7 +61,7 @@ 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)]' \ + '--target=[target triple(default:all)]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--color=:colorization option:(auto always never)' \ ;; @@ -79,7 +79,7 @@ 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]' \ + '--target=[build for the target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--color=:colorization option:(auto always never)' \ ;; @@ -276,7 +276,7 @@ case $state in '--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]' \ + '--target=[target triple which compiles will be for]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ "${command_scope_spec[@]}" \ ;; @@ -294,7 +294,7 @@ 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]' \ + '--target=[build for the target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ "${command_scope_spec[@]}" \ ;; @@ -323,7 +323,7 @@ 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]' \ + '--target=[target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '--color=:colorization option:(auto always never)' \ '1: :_test_names' \ @@ -484,6 +484,37 @@ _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 # they are used in multiple places without change, they are expanded into the # appropriate command's `_arguments` where appropriate. From da30a1d6d2709d768c68de122d6d0ab96c5a9a90 Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Sat, 7 Jan 2017 20:48:11 +1100 Subject: [PATCH 2/9] add description for --color --- plugins/cargo/_cargo | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index 3eb3acb96..99eac2bdb 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -34,7 +34,7 @@ case $state in '--target=[target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; build) @@ -51,7 +51,7 @@ case $state in '--target=[target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; clean) @@ -63,7 +63,7 @@ case $state in '--release[whether or not to clean release artifacts]' \ '--target=[target triple(default:all)]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; doc) @@ -81,7 +81,7 @@ case $state in '--release[build artifacts in release mode, with optimizations]' \ '--target=[build for the target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; fetch) @@ -90,7 +90,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; generate-lockfile) @@ -99,7 +99,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; git-checkout) @@ -109,7 +109,7 @@ case $state in '--reference=[REF]' \ '--url=[URL]' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; help) @@ -126,14 +126,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; install) _arguments \ '--bin=[only install the specified binary]' \ '--branch=[branch to use when installing from git]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]: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]' \ @@ -163,7 +163,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; metadata) @@ -177,7 +177,7 @@ case $state in '--features=[space separated feature list]' \ '--all-features[enable all available features]' \ '--format-version=[format version(default: 1)]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; new) @@ -188,7 +188,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; owner) @@ -201,7 +201,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; package) @@ -213,7 +213,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; pkgid) @@ -222,7 +222,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; publish) @@ -234,7 +234,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; read-manifest) @@ -242,7 +242,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; run) @@ -259,13 +259,13 @@ case $state in '--release=[build in release mode]' \ '--target=[target triple]' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ '*: :_normal' \ ;; rustc) _arguments \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]: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]' \ @@ -283,7 +283,7 @@ case $state in rustdoc) _arguments \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]: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]' \ @@ -301,7 +301,7 @@ case $state in search) _arguments \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]: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]' \ @@ -325,14 +325,14 @@ case $state in '--release[build artifacts in release mode, with optimizations]' \ '--target=[target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ '1: :_test_names' \ ;; uninstall) _arguments \ '--bin=[only uninstall the binary NAME]' \ - '--color=:colorization option:(auto always never)' \ + '--color=[coloring]: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]' \ @@ -348,7 +348,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; verify-project) @@ -357,14 +357,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=:colorization option:(auto always never)' \ + '--color=[coloring]: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)' \ + '--color=[coloring]:colorization option:(auto always never)' \ ;; yank) @@ -375,7 +375,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=:colorization option:(auto always never)' \ + '--color=[coloring]:colorization option:(auto always never)' \ '--vers[yank version]' \ ;; esac From b9533ccac2846d74693158eef1759d198231a79b Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Sat, 7 Jan 2017 20:54:48 +1100 Subject: [PATCH 3/9] complete --message-format --- plugins/cargo/_cargo | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index 99eac2bdb..7ed95c0ce 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -34,6 +34,7 @@ case $state in '--target=[target triple]: :_get_targets' \ '(-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)' \ ;; @@ -51,6 +52,7 @@ case $state in '--target=[target triple]: :_get_targets' \ '(-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)' \ ;; @@ -259,12 +261,14 @@ 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)' \ '*: :_normal' \ ;; rustc) _arguments \ + '--message-format=[error format]:format option:(human json)' \ '--color=[coloring]:colorization option:(auto always never)' \ '--features=[features to compile for the package]' \ '--all-features[enable all available features]' \ @@ -283,6 +287,7 @@ case $state in rustdoc) _arguments \ + '--message-format=[error format]:format option:(human json)' \ '--color=[coloring]:colorization option:(auto always never)' \ '--features=[space-separated list of features to also build]' \ '--all-features[enable all available features]' \ @@ -325,6 +330,7 @@ case $state in '--release[build artifacts in release mode, with optimizations]' \ '--target=[target triple]: :_get_targets' \ '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \ + '--message-format=[error format]:format option:(human json)' \ '--color=[coloring]:colorization option:(auto always never)' \ '1: :_test_names' \ ;; From 5423f7fa2ad255ec417fc3aea0c69077f0530ccb Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Tue, 24 Jan 2017 03:48:57 +1100 Subject: [PATCH 4/9] complete installed sub-commands --- plugins/cargo/_cargo | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index 7ed95c0ce..e26fbfeba 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -390,6 +390,7 @@ esac } _cargo_cmds(){ +local IFS=$'\n' local -a commands;commands=( 'bench:execute all benchmarks of a local package' 'build:compile the current project' @@ -420,6 +421,7 @@ 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 -d ' ' | 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 -r "s/(.*)/echo \"\1:$\(cargo help \1 | head -n 1\)\"/" | sh ) ) _describe 'command' commands From 5d0b90a7ef8fde6d8c53a5d88b5599af6b5da75e Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Mon, 26 Jun 2017 12:47:27 +1000 Subject: [PATCH 5/9] redir debug output to std --- plugins/cargo/_cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index e26fbfeba..7d6ca9fc5 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -421,7 +421,7 @@ 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 -d ' ' | 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 -r "s/(.*)/echo \"\1:$\(cargo help \1 | head -n 1\)\"/" | sh ) +$( cargo --list | sed -n '1!p' | tr -d ' ' | 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 -r "s/(.*)/echo \"\1:$\(cargo help \1 2>&1 | head -n 1\)\"/" | sh ) ) _describe 'command' commands From 440d8ef344686b699c918edc7c878a362b3a5038 Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Mon, 26 Jun 2017 12:56:16 +1000 Subject: [PATCH 6/9] fix escaping --- plugins/cargo/_cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index 7d6ca9fc5..01089dff4 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -421,7 +421,7 @@ 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 -d ' ' | 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 -r "s/(.*)/echo \"\1:$\(cargo help \1 2>&1 | head -n 1\)\"/" | sh ) +$( cargo --list | sed -n '1!p' | tr -d ' ' | 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 -r "s/(.*)/echo \"\1:$\(cargo help \1 2>\&1 | head -n 1\)\"/" | sh ) ) _describe 'command' commands From 1e161e839f5b544955096b30b01841307b4e4d2f Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Mon, 24 Sep 2018 18:02:03 +1000 Subject: [PATCH 7/9] fix subcommands completion --- plugins/cargo/_cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index 01089dff4..7d7d9b2d8 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -421,7 +421,7 @@ 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 -d ' ' | 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 -r "s/(.*)/echo \"\1:$\(cargo help \1 2>\&1 | head -n 1\)\"/" | sh ) +$( 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 -r "s/(.*)/echo \"\1:$\(cargo help \1 2>\&1 | head -n 1\)\"/" | sh ) ) _describe 'command' commands From cf07fe2c6f0ea1561e21189feb12592a21d10306 Mon Sep 17 00:00:00 2001 From: Frederick Zhang Date: Wed, 28 Nov 2018 14:50:45 +1100 Subject: [PATCH 8/9] -r is not available for bsd sed --- plugins/cargo/_cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index 7d7d9b2d8..a8c58ecc5 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -421,7 +421,7 @@ 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 -r "s/(.*)/echo \"\1:$\(cargo help \1 2>\&1 | head -n 1\)\"/" | sh ) +$( 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 From a441f64d090d30856a1f56a10820b219ffc10e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 25 Mar 2019 22:40:50 +0100 Subject: [PATCH 9/9] Update _cargo completion to 0.34.0 version --- plugins/cargo/_cargo | 195 ++++++++++++++++++++++--------------------- 1 file changed, 100 insertions(+), 95 deletions(-) diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo index a8c58ecc5..395c517cd 100644 --- a/plugins/cargo/_cargo +++ b/plugins/cargo/_cargo @@ -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