@@ -39,7 +39,7 @@ _cargo() {
3939 # appropriate command's `_arguments` where appropriate.
4040 command_scope_spec=(
4141 '(--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 '
4343 '(--bench --example --test --lib)--bin=[specify binary name]:binary name'
4444 '(--bench --bin --example --test)--lib=[specify library name]:library name'
4545 '(--bench --bin --example --lib)--test=[specify test name]:test name'
@@ -148,7 +148,7 @@ _cargo() {
148148 '--bin=[only install the specified binary]:binary' \
149149 '--branch=[branch to use when installing from git]:branch' \
150150 '--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 ' \
152152 '--git=[specify URL from which to install the crate]:url:_urls' \
153153 '--path=[local filesystem path to crate to install]: :_directories' \
154154 '--rev=[specific commit to use when installing from git]:commit' \
@@ -222,7 +222,7 @@ _cargo() {
222222
223223 run)
224224 _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 ' \
226226 '--bin=[name of the bin target]:name' \
227227 '(-p --package)'{-p+,--package=}'[specify package with the target to run]:package:_cargo_package_names' \
228228 '--release[build in release mode]' \
@@ -267,7 +267,7 @@ _cargo() {
267267 '(--doc --bin --example --test --bench)--lib[only test library]' \
268268 '(--lib --bin --example --test --bench)--doc[only test documentation]' \
269269 '(--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 ' \
271271 '(--lib --doc --bin --example --bench)--test=[test name]' \
272272 '(--lib --doc --bin --example --test)--bench=[benchmark name]' \
273273 '*: :_default'
@@ -416,4 +416,11 @@ _cargo_benchmark_names() {
416416 _cargo_names_from_array "bench"
417417}
418418
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+
419426_cargo
0 commit comments