[cargo] Use filesystem for --example completions

`cargo run --example` no longer lists examples and never listed examples
that were not built.
This commit is contained in:
Mahmoud Al-Qudsi 2020-08-29 17:06:33 -05:00
parent cf075b4179
commit 0d3f4db33a

View File

@ -31,9 +31,17 @@ for x in bench build rustc test
complete -c cargo -x -n "__fish_seen_subcommand_from $x" -l test -a "(cargo test --test 2>&1 | string replace -rf '^\s+' '')" complete -c cargo -x -n "__fish_seen_subcommand_from $x" -l test -a "(cargo test --test 2>&1 | string replace -rf '^\s+' '')"
end end
function __list_cargo_examples
if not test -d ./examples
return
end
find ./examples/ -mindepth 1 -maxdepth 1 -type f -name "*.rs" -or -type d \
| string replace -r './examples/(.*)(?:.rs)?$' '$1'
end
for x in bench build run rustc test for x in bench build run rustc test
complete -c cargo -x -n "__fish_seen_subcommand_from $x" -l bin -a "(cargo run --bin 2>&1 | string replace -rf '^\s+' '')" complete -c cargo -x -n "__fish_seen_subcommand_from $x" -l bin -a "(cargo run --bin 2>&1 | string replace -rf '^\s+' '')"
complete -c cargo -x -n "__fish_seen_subcommand_from $x" -l example -a "(cargo run --example 2>&1 | string replace -rf '^\s+' '')" complete -c cargo -x -n "__fish_seen_subcommand_from $x" -l example -a "(__list_cargo_examples)"
end end
for x in build run rustc test for x in build run rustc test