@@ -39,7 +39,7 @@ _cargo() {
39
39
# appropriate command's `_arguments` where appropriate.
40
40
command_scope_spec=(
41
41
'(--bin --example --test --lib)--bench=[specify benchmark name]: :_cargo_benchmark_names'
42
- '(--bench --bin --test --lib)--example=[specify example name]:example name'
42
+ '(--bench --bin --test --lib)--example=[specify example name]:example name:_cargo_example_names '
43
43
'(--bench --example --test --lib)--bin=[specify binary name]:binary name'
44
44
'(--bench --bin --example --test)--lib=[specify library name]:library name'
45
45
'(--bench --bin --example --lib)--test=[specify test name]:test name'
@@ -148,7 +148,7 @@ _cargo() {
148
148
'--bin=[only install the specified binary]:binary' \
149
149
'--branch=[branch to use when installing from git]:branch' \
150
150
'--debug[build in debug mode instead of release mode]' \
151
- '--example=[install the specified example instead of binaries]:example' \
151
+ '--example=[install the specified example instead of binaries]:example:_cargo_example_names ' \
152
152
'--git=[specify URL from which to install the crate]:url:_urls' \
153
153
'--path=[local filesystem path to crate to install]: :_directories' \
154
154
'--rev=[specific commit to use when installing from git]:commit' \
@@ -222,7 +222,7 @@ _cargo() {
222
222
223
223
run)
224
224
_arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
225
- '--example=[name of the bin target]:name' \
225
+ '--example=[name of the bin target]:name:_cargo_example_names ' \
226
226
'--bin=[name of the bin target]:name' \
227
227
'(-p --package)'{-p+,--package=}'[specify package with the target to run]:package:_cargo_package_names' \
228
228
'--release[build in release mode]' \
@@ -267,7 +267,7 @@ _cargo() {
267
267
'(--doc --bin --example --test --bench)--lib[only test library]' \
268
268
'(--lib --bin --example --test --bench)--doc[only test documentation]' \
269
269
'(--lib --doc --example --test --bench)--bin=[binary name]' \
270
- '(--lib --doc --bin --test --bench)--example=[example name]' \
270
+ '(--lib --doc --bin --test --bench)--example=[example name]:_cargo_example_names ' \
271
271
'(--lib --doc --bin --example --bench)--test=[test name]' \
272
272
'(--lib --doc --bin --example --test)--bench=[benchmark name]' \
273
273
'*: :_default'
@@ -416,4 +416,11 @@ _cargo_benchmark_names() {
416
416
_cargo_names_from_array "bench"
417
417
}
418
418
419
+ _cargo_example_names() {
420
+ if [[ -d examples ]]; then
421
+ local -a files=(${(@f)$(echo examples/*.rs(:t:r))})
422
+ _values 'example' "${files[@]}"
423
+ fi
424
+ }
425
+
419
426
_cargo
0 commit comments