Skip to content

Commit 09a362a

Browse files
committed
Auto merge of #3439 - gentoo90:bashcomp, r=alexcrichton
Bashcomp Update bash completion
2 parents 836c22d + aa3f1d0 commit 09a362a

File tree

1 file changed

+71
-64
lines changed

1 file changed

+71
-64
lines changed

src/etc/cargo.bashcomp.sh

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ _cargo()
1010

1111
local vcs='git hg none'
1212
local color='auto always never'
13+
local msg_format='human json'
1314

1415
local opt_help='-h --help'
1516
local opt_verbose='-v --verbose'
@@ -20,38 +21,41 @@ _cargo()
2021
local opt_feat='--features --all-features --no-default-features'
2122
local opt_mani='--manifest-path'
2223
local opt_jobs='-j --jobs'
24+
local opt_force='-f --force'
25+
local opt_test='--test --bench'
26+
local opt_lock='--frozen --locked'
2327

2428
local opt___nocmd="$opt_common -V --version --list"
25-
local opt__bench="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --lib --bin --test --bench --example --no-run"
26-
local opt__build="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --lib --bin --test --bench --example --release"
27-
local opt__check="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --lib --bin --example"
28-
local opt__clean="$opt_common $opt_pkg $opt_mani --target --release"
29-
local opt__doc="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --open --no-deps --release"
30-
local opt__fetch="$opt_common $opt_mani"
29+
local opt__bench="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --target --lib --bin --example --no-run"
30+
local opt__build="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --target --lib --bin --example --release"
31+
local opt__check="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --target --lib --bin --example --release"
32+
local opt__clean="$opt_common $opt_pkg $opt_mani $opt_lock --target --release"
33+
local opt__doc="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs --message-format --bin --lib --target --open --no-deps --release"
34+
local opt__fetch="$opt_common $opt_mani $opt_lock"
3135
local opt__generate_lockfile="${opt__fetch}"
32-
local opt__git_checkout="$opt_common --reference --url"
36+
local opt__git_checkout="$opt_common $opt_lock --reference --url"
3337
local opt__help="$opt_help"
34-
local opt__init="$opt_common --bin --name --vcs"
35-
local opt__install="$opt_common $opt_feat $opt_jobs --bin --branch --debug --example --git --list --path --rev --root --tag --vers"
38+
local opt__init="$opt_common $opt_lock --bin --lib --name --vcs"
39+
local opt__install="$opt_common $opt_feat $opt_jobs $opt_lock $opt_force --bin --branch --debug --example --git --list --path --rev --root --tag --vers"
3640
local opt__locate_project="$opt_mani -h --help"
37-
local opt__login="$opt_common --host"
38-
local opt__metadata="$opt_common $opt_feat $opt_mani --format-version"
39-
local opt__new="$opt_common --vcs --bin --name"
40-
local opt__owner="$opt_common -a --add -r --remove -l --list --index --token"
41-
local opt__package="$opt_common $opt_mani -l --list --no-verify --no-metadata"
42-
local opt__pkgid="${opt__fetch}"
43-
local opt__publish="$opt_common $opt_mani --host --token --no-verify"
44-
local opt__read_manifest="$opt_help $opt_verbose $opt_mani $opt_color"
45-
local opt__run="$opt_common $opt_feat $opt_mani $opt_jobs --target --bin --example --release"
46-
local opt__rustc="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --lib --bin --test --bench --example --release"
47-
local opt__rustdoc="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --lib --bin --test --bench --example --release --open"
48-
local opt__search="$opt_common --host"
49-
local opt__test="$opt_common $opt_pkg $opt_feat $opt_mani $opt_jobs --target --lib --bin --test --bench --example --no-run --release --no-fail-fast"
50-
local opt__uninstall="$opt_common --bin --root"
51-
local opt__update="$opt_common $opt_pkg $opt_mani --aggressive --precise"
41+
local opt__login="$opt_common $opt_lock --host"
42+
local opt__metadata="$opt_common $opt_feat $opt_mani $opt_lock --format-version --no-deps"
43+
local opt__new="$opt_common $opt_lock --vcs --bin --lib --name"
44+
local opt__owner="$opt_common $opt_lock -a --add -r --remove -l --list --index --token"
45+
local opt__package="$opt_common $opt_mani $opt_lock $opt_jobs --allow-dirty -l --list --no-verify --no-metadata"
46+
local opt__pkgid="${opt__fetch} $opt_pkg"
47+
local opt__publish="$opt_common $opt_mani $opt_lock $opt_jobs --allow-dirty --dry-run --host --token --no-verify"
48+
local opt__read_manifest="$opt_help $opt_verbose $opt_mani $opt_color --no-deps"
49+
local opt__run="$opt_common $opt_feat $opt_mani $opt_lock $opt_jobs --message-format --target --bin --example --release"
50+
local opt__rustc="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --profile --target --lib --bin --example --release"
51+
local opt__rustdoc="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --target --lib --bin --example --release --open"
52+
local opt__search="$opt_common $opt_lock --host --limit"
53+
local opt__test="$opt_common $opt_pkg $opt_feat $opt_mani $opt_lock $opt_jobs $opt_test --message-format --all --doc --target --lib --bin --example --no-run --release --no-fail-fast"
54+
local opt__uninstall="$opt_common $opt_lock --bin --root"
55+
local opt__update="$opt_common $opt_pkg $opt_mani $opt_lock --aggressive --precise"
5256
local opt__verify_project="${opt__fetch}"
5357
local opt__version="$opt_help $opt_verbose $opt_color"
54-
local opt__yank="$opt_common --vers --undo --index --token"
58+
local opt__yank="$opt_common $opt_lock --vers --undo --index --token"
5559

5660
if [[ $cword -eq 1 ]]; then
5761
if [[ "$cur" == -* ]]; then
@@ -67,6 +71,9 @@ _cargo()
6771
--color)
6872
COMPREPLY=( $( compgen -W "$color" -- "$cur" ) )
6973
;;
74+
--message-format)
75+
COMPREPLY=( $( compgen -W "$msg_format" -- "$cur" ) )
76+
;;
7077
--manifest-path)
7178
_filedir toml
7279
;;
@@ -113,55 +120,55 @@ _locate_manifest(){
113120
# command line options for completion
114121
_get_names_from_array()
115122
{
116-
local manifest=$(_locate_manifest)
117-
if [[ -z $manifest ]]; then
118-
return 0
119-
fi
120-
121-
local last_line
122-
local -a names
123-
local in_block=false
124-
local block_name=$1
125-
while read line
126-
do
127-
if [[ $last_line == "[[$block_name]]" ]]; then
128-
in_block=true
129-
else
130-
if [[ $last_line =~ .*\[\[.* ]]; then
131-
in_block=false
132-
fi
133-
fi
134-
135-
if [[ $in_block == true ]]; then
136-
if [[ $line =~ .*name.*\= ]]; then
137-
line=${line##*=}
138-
line=${line%%\"}
139-
line=${line##*\"}
140-
names+=($line)
141-
fi
142-
fi
143-
144-
last_line=$line
145-
done < $manifest
146-
echo "${names[@]}"
123+
local manifest=$(_locate_manifest)
124+
if [[ -z $manifest ]]; then
125+
return 0
126+
fi
127+
128+
local last_line
129+
local -a names
130+
local in_block=false
131+
local block_name=$1
132+
while read line
133+
do
134+
if [[ $last_line == "[[$block_name]]" ]]; then
135+
in_block=true
136+
else
137+
if [[ $last_line =~ .*\[\[.* ]]; then
138+
in_block=false
139+
fi
140+
fi
141+
142+
if [[ $in_block == true ]]; then
143+
if [[ $line =~ .*name.*\= ]]; then
144+
line=${line##*=}
145+
line=${line%%\"}
146+
line=${line##*\"}
147+
names+=($line)
148+
fi
149+
fi
150+
151+
last_line=$line
152+
done < $manifest
153+
echo "${names[@]}"
147154
}
148155

149156
#Gets the bin names from the manifest file
150157
_bin_names()
151158
{
152-
_get_names_from_array "bin"
159+
_get_names_from_array "bin"
153160
}
154161

155162
#Gets the test names from the manifest file
156163
_test_names()
157164
{
158-
_get_names_from_array "test"
165+
_get_names_from_array "test"
159166
}
160167

161168
#Gets the bench names from the manifest file
162169
_benchmark_names()
163170
{
164-
_get_names_from_array "bench"
171+
_get_names_from_array "bench"
165172
}
166173

167174
_get_examples(){
@@ -188,16 +195,16 @@ _get_targets(){
188195
local FIND_PATHS=( "/" )
189196
local FIND_PATH LINES LINE
190197
while [[ "$CURRENT_PATH" != "/" ]]; do
191-
FIND_PATHS+=( "$CURRENT_PATH" )
192-
CURRENT_PATH=$(dirname $CURRENT_PATH)
198+
FIND_PATHS+=( "$CURRENT_PATH" )
199+
CURRENT_PATH=$(dirname $CURRENT_PATH)
193200
done
194201
for FIND_PATH in ${FIND_PATHS[@]}; do
195-
if [[ -f "$FIND_PATH"/.cargo/config ]]; then
202+
if [[ -f "$FIND_PATH"/.cargo/config ]]; then
196203
LINES=( `grep "$FIND_PATH"/.cargo/config -e "^\[target\."` )
197204
for LINE in ${LINES[@]}; do
198-
TARGETS+=(`sed 's/^\[target\.\(.*\)\]$/\1/' <<< $LINE`)
205+
TARGETS+=(`sed 's/^\[target\.\(.*\)\]$/\1/' <<< $LINE`)
199206
done
200-
fi
207+
fi
201208
done
202209
echo "${TARGETS[@]}"
203210
}

0 commit comments

Comments
 (0)