4e8ffe88d4311edcd084de5efd4ee6688e9e70f7

Author
Ben Goldberg <ben@benaaron.dev>
Committer
GitHub <noreply@github.com>
Date

Message

fix(cargo): complete flags for default cargo aliases (#9692)

By default, cargo provides alias for some commonly used functions. This patch
makes it that those alias will complete the same as their full commands.

Default alias:
b -> build
c -> check
t -> test
r -> run

Since cargo allows users to define custom alias it would be nice if
oh-my-zsh automatically detected those and preformed completions as such
but that would be a much more complex patch.

Diff

 1diff --git a/plugins/cargo/_cargo b/plugins/cargo/_cargo
 2index ffc9fcdc830e30064afc74efc7c4a9fc40220702..ebff993107b9f8362eef7d11c34d64cb093609d9 100644
 3--- a/plugins/cargo/_cargo
 4+++ b/plugins/cargo/_cargo
 5@@ -77,7 +77,7 @@ _cargo() {
 6                         '*:args:_default'
 7                         ;;
 8 
 9-                build)
10+                build|b)
11                     _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
12                         '--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
13                         "${command_scope_spec[@]}" \
14@@ -86,7 +86,7 @@ _cargo() {
15                         '--build-plan[output the build plan in JSON]' \
16                         ;;
17 
18-                check)
19+                check|c)
20                     _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
21                         '--all-targets[equivalent to specifying --lib --bins --tests --benches --examples]' \
22                         "${command_scope_spec[@]}" \
23@@ -224,7 +224,7 @@ _cargo() {
24                     _arguments -s -S $common $manifest
25                         ;;
26 
27-                run)
28+                run|r)
29                     _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
30                         '--example=[name of the bin target]:name' \
31                         '--bin=[name of the bin target]:name' \
32@@ -259,7 +259,7 @@ _cargo() {
33                         '*: :_guard "^-*" "query"'
34                         ;;
35 
36-                test)
37+                test|t)
38                     _arguments -s -S $common $parallel $features $msgfmt $triple $target $manifest \
39                         '--test=[test name]: :_cargo_test_names' \
40                         '--no-fail-fast[run all tests regardless of failure]' \