mirror of
https://github.com/rust-lang/cargo
synced 2024-10-13 11:12:25 +00:00
Auto merge of #1586 - gentoo90:bash-comp, r=wycats
Fix inability to complete more than one option of a command. Add missing options.
This commit is contained in:
commit
ece2a9235f
|
@ -12,25 +12,26 @@ _cargo()
|
|||
opt_pkg='-p --package'
|
||||
opt_feat='--features --no-default-features'
|
||||
opt_mani='--manifest-path'
|
||||
opt_jobs='-j --jobs'
|
||||
|
||||
declare -A opts
|
||||
opts[_nocmd]="$opt_common -V --version --list"
|
||||
opts[bench]="$opt_common $opt_pkg $opt_feat $opt_mani --target --bench --no-run -j --jobs"
|
||||
opts[build]="$opt_common $opt_pkg $opt_feat $opt_mani --target -j --jobs --lib --release"
|
||||
opts[bench]="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --lib --bin --test --bench --example --no-run"
|
||||
opts[build]="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --lib --bin --test --bench --example --release"
|
||||
opts[clean]="$opt_common $opt_pkg $opt_mani --target"
|
||||
opts[doc]="$opt_common $opt_pkg $opt_feat $opt_mani --target --open --no-deps -j --jobs"
|
||||
opts[doc]="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --open --no-deps"
|
||||
opts[fetch]="$opt_common $opt_mani"
|
||||
opts[generate-lockfile]="${opts[fetch]}"
|
||||
opts[git-checkout]="$opt_common --reference= --url="
|
||||
opts[locate-project]="${opts[fetch]}"
|
||||
opts[locate-project]="$opt_mani -h --help"
|
||||
opts[login]="$opt_common --host"
|
||||
opts[new]="$opt_common --vcs --bin"
|
||||
opts[new]="$opt_common --vcs --bin --name"
|
||||
opts[owner]="$opt_common -a --add -r --remove -l --list --index --token"
|
||||
opts[pkgid]="${opts[fetch]}"
|
||||
opts[publish]="$opt_common $opt_mani --host --token --no-verify"
|
||||
opts[read-manifest]="${opts[fetch]}"
|
||||
opts[run]="$opt_common $opt_feat $opt_mani --target --bin --example -j --jobs --release"
|
||||
opts[test]="$opt_common $opt_pkg $opt_feat $opt_mani --target --test --bin --no-run -j --jobs"
|
||||
opts[run]="$opt_common $opt_feat $opt_mani $opt_jobs --target --bin --example --release"
|
||||
opts[test]="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --lib --bin --test --bench --example --no-run --release"
|
||||
opts[update]="$opt_common $opt_pkg $opt_mani --aggressive --precise"
|
||||
opts[package]="$opt_common $opt_mani -l --list --no-verify --no-metadata"
|
||||
opts[verify-project]="${opts[fetch]}"
|
||||
|
@ -43,17 +44,18 @@ _cargo()
|
|||
else
|
||||
COMPREPLY=( $( compgen -W "$(cargo --list | tail -n +2)" -- "$cur" ) )
|
||||
fi
|
||||
elif [[ $cword -gt 2 ]]; then
|
||||
elif [[ $cword -ge 2 ]]; then
|
||||
case "${prev}" in
|
||||
"$opt_mani")
|
||||
--manifest-path)
|
||||
_filedir toml
|
||||
;;
|
||||
--example)
|
||||
COMPREPLY=( $( compgen -W "$(_get_examples)" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $( compgen -W "${opts[$cmd]}" -- "$cur" ) )
|
||||
;;
|
||||
esac
|
||||
elif [[ "$cur" == -* ]]; then
|
||||
COMPREPLY=( $( compgen -W "${opts[$cmd]}" -- "$cur" ) )
|
||||
fi
|
||||
|
||||
if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != "--"*"=" ]] ; then
|
||||
|
@ -73,6 +75,9 @@ _get_examples(){
|
|||
local files=($(dirname $(_locate_manifest))/examples/*.rs)
|
||||
local names=("${files[@]##*/}")
|
||||
local names=("${names[@]%.*}")
|
||||
echo "${names[@]}"
|
||||
# "*" means no examples found
|
||||
if [[ "${names[@]}" != "*" ]]; then
|
||||
echo "${names[@]}"
|
||||
fi
|
||||
}
|
||||
# vim:ft=sh
|
||||
|
|
Loading…
Reference in a new issue