_cargo 25.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
#compdef cargo

typeset -A opt_args
autoload -U regexp-replace

_cargo() {

_arguments \
    '(- 1 *)'{-h,--help}'[show help message]' \
10
    '(- 1 *)'{-V,--version}'[show version information]' \
11
    '(- 1 *)'--list'[list installed commands]' \
12
    '(- 1 *)'--explain'[Run `rustc --explain CODE`]' \
13
14
    '(- 1 *)'{-v,--verbose}'[use verbose output]' \
    '(- 1 *)'--color'[colorization option]' \
15
16
    '(- 1 *)'--frozen'[Require Cargo.lock and cache are up to date]' \
    '(- 1 *)'--locked'[Require Cargo.lock is up to date]' \
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    '1: :_cargo_cmds' \
    '*:: :->args'

case $state in
    args)
        case $words[1] in
            bench)
                _arguments \
                    '--features=[space separated feature list]' \
                    '--all-features[enable all available features]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
                    "${command_scope_spec[@]}" \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '--no-default-features[do not build the default features]' \
                    '--no-run[compile but do not run]' \
                    '(-p,--package)'{-p=,--package=}'[package to run benchmarks for]:packages:_get_package_names' \
Frederick Zhang's avatar
Frederick Zhang committed
34
                    '--target=[target triple]: :_get_targets' \
35
36
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
Frederick Zhang's avatar
Frederick Zhang committed
37
                    '--message-format=[error format]:format option:(human json)' \
Frederick Zhang's avatar
Frederick Zhang committed
38
                    '--color=[coloring]:colorization option:(auto always never)' \
39
40
41
42
43
44
45
46
47
48
49
50
51
                    ;;

            build)
                _arguments \
                    '--features=[space separated feature list]' \
                    '--all-features[enable all available features]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
                    "${command_scope_spec[@]}" \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '--no-default-features[do not build the default features]' \
                    '(-p,--package)'{-p=,--package=}'[package to build]:packages:_get_package_names' \
                    '--release=[build in release mode]' \
Frederick Zhang's avatar
Frederick Zhang committed
52
                    '--target=[target triple]: :_get_targets' \
53
54
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
Frederick Zhang's avatar
Frederick Zhang committed
55
                    '--message-format=[error format]:format option:(human json)' \
Frederick Zhang's avatar
Frederick Zhang committed
56
                    '--color=[coloring]:colorization option:(auto always never)' \
57
58
59
60
61
62
63
64
65
                    ;;

            clean)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '(-p,--package)'{-p=,--package=}'[package to clean]:packages:_get_package_names' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--release[whether or not to clean release artifacts]' \
Frederick Zhang's avatar
Frederick Zhang committed
66
                    '--target=[target triple(default:all)]: :_get_targets' \
67
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
68
                    '--color=[coloring]:colorization option:(auto always never)' \
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
                    ;;

            doc)
                _arguments \
                    '--features=[space separated feature list]' \
                    '--all-features[enable all available features]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '--no-deps[do not build docs for dependencies]' \
                    '--no-default-features[do not build the default features]' \
                    '--open[open docs in browser after the build]' \
                    '(-p, --package)'{-p,--package}'=[package to document]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--release[build artifacts in release mode, with optimizations]' \
Frederick Zhang's avatar
Frederick Zhang committed
84
                    '--target=[build for the target triple]: :_get_targets' \
85
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
86
                    '--color=[coloring]:colorization option:(auto always never)' \
87
88
89
90
91
92
93
94
                    ;;

            fetch)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
95
                    '--color=[coloring]:colorization option:(auto always never)' \
96
97
98
99
100
101
102
103
                    ;;

            generate-lockfile)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
104
                    '--color=[coloring]:colorization option:(auto always never)' \
105
106
107
108
109
110
111
112
113
                    ;;

            git-checkout)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    'q(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--reference=[REF]' \
                    '--url=[URL]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
114
                    '--color=[coloring]:colorization option:(auto always never)' \
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
                    ;;

            help)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '*: :_cargo_cmds' \
                    ;;

            init)
                _arguments \
                    '--bin[use binary template]' \
                    '--vcs:initialize a new repo with a given VCS:(git hg none)' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--name=[set the resulting package name]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
131
                    '--color=[coloring]:colorization option:(auto always never)' \
132
133
134
135
136
137
                    ;;

            install)
                _arguments \
                    '--bin=[only install the specified binary]' \
                    '--branch=[branch to use when installing from git]' \
Frederick Zhang's avatar
Frederick Zhang committed
138
                    '--color=[coloring]:colorization option:(auto always never)' \
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
                    '--debug[build in debug mode instead of release mode]' \
                    '--example[install the specified example instead of binaries]' \
                    '--features=[space separated feature list]' \
                    '--all-features[enable all available features]' \
                    '--git=[URL from which to install the crate]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
                    '--no-default-features[do not build the default features]' \
                    '--path=[local filesystem path to crate to install]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--rev=[specific commit to use when installing from git]' \
                    '--root=[directory to install packages into]' \
                    '--tag=[tag to use when installing from git]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
                    '--vers=[version to install from crates.io]' \
                    ;;

            locate-project)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    ;;

            login)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--host=[Host to set the token for]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
168
                    '--color=[coloring]:colorization option:(auto always never)' \
169
170
171
172
173
174
175
176
177
178
179
180
181
                    ;;

            metadata)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
                    "--no-deps[output information only about the root package and don't fetch dependencies]" \
                    '--no-default-features[do not include the default feature]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '--features=[space separated feature list]' \
                    '--all-features[enable all available features]' \
                    '--format-version=[format version(default: 1)]' \
Frederick Zhang's avatar
Frederick Zhang committed
182
                    '--color=[coloring]:colorization option:(auto always never)' \
183
184
185
186
187
188
189
190
191
192
                    ;;

            new)
                _arguments \
                    '--bin[use binary template]' \
                    '--vcs:initialize a new repo with a given VCS:(git hg none)' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--name=[set the resulting package name]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
193
                    '--color=[coloring]:colorization option:(auto always never)' \
194
195
196
197
198
199
200
201
202
203
204
205
                    ;;

            owner)
                _arguments \
                    '(-a, --add)'{-a,--add}'[add owner LOGIN]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--index[registry index]' \
                    '(-l, --list)'{-l,--list}'[list owners of a crate]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-r, --remove)'{-r,--remove}'[remove owner LOGIN]' \
                    '--token[API token to use when authenticating]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
206
                    '--color=[coloring]:colorization option:(auto always never)' \
207
208
209
210
211
212
213
214
215
216
217
                    ;;

            package)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-l, --list)'{-l,--list}'[print files included in a package without making one]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '--no-metadata[ignore warnings about a lack of human-usable metadata]' \
                    '--no-verify[do not build to verify contents]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
218
                    '--color=[coloring]:colorization option:(auto always never)' \
219
220
221
222
223
224
225
226
                    ;;

            pkgid)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
227
                    '--color=[coloring]:colorization option:(auto always never)' \
228
229
230
231
232
233
234
235
236
237
238
                    ;;

            publish)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--host=[Host to set the token for]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '--no-verify[Do not verify tarball until before publish]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--token[token to use when uploading]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
239
                    '--color=[coloring]:colorization option:(auto always never)' \
240
241
242
243
244
245
246
                    ;;

            read-manifest)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
247
                    '--color=[coloring]:colorization option:(auto always never)' \
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
                    ;;

            run)
                _arguments \
                    '--example=[name of the bin target]' \
                    '--features=[space separated feature list]' \
                    '--all-features[enable all available features]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '--bin=[name of the bin target]' \
                    '--no-default-features[do not build the default features]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--release=[build in release mode]' \
                    '--target=[target triple]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
264
                    '--message-format=[error format]:format option:(human json)' \
Frederick Zhang's avatar
Frederick Zhang committed
265
                    '--color=[coloring]:colorization option:(auto always never)' \
266
267
268
269
270
                    '*: :_normal' \
                    ;;

            rustc)
                _arguments \
Frederick Zhang's avatar
Frederick Zhang committed
271
                    '--message-format=[error format]:format option:(human json)' \
Frederick Zhang's avatar
Frederick Zhang committed
272
                    '--color=[coloring]:colorization option:(auto always never)' \
273
274
275
276
277
278
279
280
281
282
                    '--features=[features to compile for the package]' \
                    '--all-features[enable all available features]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
                    '--manifest-path=[path to the manifest to fetch dependencies for]' \
                    '--no-default-features[do not compile default features for the package]' \
                    '(-p, --package)'{-p,--package}'=[profile to compile for]' \
                    '--profile=[profile to build the selected target for]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--release[build artifacts in release mode, with optimizations]' \
Frederick Zhang's avatar
Frederick Zhang committed
283
                    '--target=[target triple which compiles will be for]: :_get_targets' \
284
285
286
287
288
289
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
                    "${command_scope_spec[@]}" \
                    ;;

            rustdoc)
                _arguments \
Frederick Zhang's avatar
Frederick Zhang committed
290
                    '--message-format=[error format]:format option:(human json)' \
Frederick Zhang's avatar
Frederick Zhang committed
291
                    '--color=[coloring]:colorization option:(auto always never)' \
292
293
294
295
296
297
298
299
300
301
                    '--features=[space-separated list of features to also build]' \
                    '--all-features[enable all available features]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
                    '--manifest-path=[path to the manifest to document]' \
                    '--no-default-features[do not build the `default` feature]' \
                    '--open[open the docs in a browser after the operation]' \
                    '(-p, --package)'{-p,--package}'=[package to document]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--release[build artifacts in release mode, with optimizations]' \
Frederick Zhang's avatar
Frederick Zhang committed
302
                    '--target=[build for the target triple]: :_get_targets' \
303
304
305
306
307
308
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
                    "${command_scope_spec[@]}" \
                    ;;

            search)
                _arguments \
Frederick Zhang's avatar
Frederick Zhang committed
309
                    '--color=[coloring]:colorization option:(auto always never)' \
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--host=[host of a registry to search in]' \
                    '--limit=[limit the number of results]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
                    ;;

            test)
                _arguments \
                    '--features=[space separated feature list]' \
                    '--all-features[enable all available features]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '--test=[test name]: :_test_names' \
                    '--no-default-features[do not build the default features]' \
                    '--no-fail-fast[run all tests regardless of failure]' \
                    '--no-run[compile but do not run]' \
                    '(-p,--package)'{-p=,--package=}'[package to run tests for]:packages:_get_package_names' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--release[build artifacts in release mode, with optimizations]' \
Frederick Zhang's avatar
Frederick Zhang committed
331
                    '--target=[target triple]: :_get_targets' \
332
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
333
                    '--message-format=[error format]:format option:(human json)' \
Frederick Zhang's avatar
Frederick Zhang committed
334
                    '--color=[coloring]:colorization option:(auto always never)' \
335
336
337
338
339
340
                    '1: :_test_names' \
                    ;;

            uninstall)
                _arguments \
                    '--bin=[only uninstall the binary NAME]' \
Frederick Zhang's avatar
Frederick Zhang committed
341
                    '--color=[coloring]:colorization option:(auto always never)' \
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-q, --quiet)'{-q,--quiet}'[less output printed to stdout]' \
                    '--root=[directory to uninstall packages from]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
                    ;;

            update)
                _arguments \
                    '--aggressive=[force dependency update]' \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '(-p,--package)'{-p=,--package=}'[package to update]:packages:__get_package_names' \
                    '--precise=[update single dependency to PRECISE]: :' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
357
                    '--color=[coloring]:colorization option:(auto always never)' \
358
359
360
361
362
363
364
365
                    ;;

            verify-project)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--manifest-path=[path to manifest]: :_files -/' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
366
                    '--color=[coloring]:colorization option:(auto always never)' \
367
368
369
370
371
372
                    ;;

            version)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
373
                    '--color=[coloring]:colorization option:(auto always never)' \
374
375
376
377
378
379
380
381
382
383
                    ;;

            yank)
                _arguments \
                    '(-h, --help)'{-h,--help}'[show help message]' \
                    '--index[registry index]' \
                    '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
                    '--token[API token to use when authenticating]' \
                    '--undo[undo a yank, putting a version back into the index]' \
                    '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
Frederick Zhang's avatar
Frederick Zhang committed
384
                    '--color=[coloring]:colorization option:(auto always never)' \
385
386
387
388
389
390
391
392
                    '--vers[yank version]' \
                    ;;
        esac
        ;;
esac
}

_cargo_cmds(){
393
local IFS=$'\n'
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
local -a commands;commands=(
'bench:execute all benchmarks of a local package'
'build:compile the current project'
'clean:remove generated artifacts'
'doc:build package documentation'
'fetch:fetch package dependencies'
'generate-lockfile:create lockfile'
'git-checkout:git checkout'
'help:get help for commands'
'init:create new project in current directory'
'install:install a Rust binary'
'locate-project:print "Cargo.toml" location'
'login:login to remote server'
'metadata:the metadata for a project in json'
'new:create a new project'
'owner:manage the owners of a crate on the registry'
'package:assemble local package into a distributable tarball'
'pkgid:print a fully qualified package specification'
'publish:upload package to the registry'
'read-manifest:print manifest in JSON format'
'run:run the main binary of the local package'
'rustc:compile a package and all of its dependencies'
'rustdoc:build documentation for a package'
'search:search packages on crates.io'
'test:execute all unit and tests of a local package'
'uninstall:remove a Rust binary'
'update:update dependencies'
'verify-project:check Cargo.toml'
'version:show version information'
'yank:remove pushed file from index'
424
$( cargo --list | sed -n '1!p' | tr -d ' ' | egrep -v "^bench$|^build$|^clean$|^doc$|^fetch$|^generate-lockfile$|^git-checkout$|^help$|^init$|^install$|^locate-project$|^login$|^metadata$|^new$|^owner$|^package$|^pkgid$|^publish$|^read-manifest$|^run$|^rustc$|^rustdoc$|^search$|^test$|^uninstall$|^update$|^verify-project$|^version$|^yank$" | sed -r "s/(.*)/echo \"\1:$\(cargo help \1 | head -n 1\)\"/" | sh )
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
)
_describe 'command' commands

}


#FIXME: Disabled until fixed
#gets package names from the manifest file
_get_package_names()
{
}

#TODO:see if it makes sense to have 'locate-project' to have non-json output.
#strips package name from json stuff
_locate_manifest(){
local manifest=`cargo locate-project 2>/dev/null`
regexp-replace manifest '\{"root":"|"\}' ''
echo $manifest
}

# Extracts the values of "name" from the array given in $1 and shows them as
# command line options for completion
_get_names_from_array()
{
    local -a filelist;
    local manifest=$(_locate_manifest)
    if [[ -z $manifest ]]; then
        return 0
    fi

    local last_line
    local -a names;
    local in_block=false
    local block_name=$1
    names=()
    while read line
    do
        if [[ $last_line == "[[$block_name]]" ]]; then
            in_block=true
        else
            if [[ $last_line =~ '.*\[\[.*' ]]; then
                in_block=false
            fi
        fi

        if [[ $in_block == true ]]; then
            if [[ $line =~ '.*name.*=' ]]; then
                regexp-replace line '^.*name *= *|"' ""
                names+=$line
            fi
        fi

        last_line=$line
    done < $manifest
    _describe $block_name names

}

#Gets the test names from the manifest file
_test_names()
{
    _get_names_from_array "test"
}

#Gets the bench names from the manifest file
_benchmark_names()
{
    _get_names_from_array "bench"
}

Frederick Zhang's avatar
Frederick Zhang committed
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#Gets the target names from config files
_get_targets()
{
    local CURRENT_PATH
    if [[ $(uname -o) = "Cygwin" && -f "$PWD"/Cargo.toml ]]; then
            CURRENT_PATH=$PWD
    else
            CURRENT_PATH=$(_locate_manifest)
    fi
    if [[ -z "$CURRENT_PATH" ]]; then
            return 1
    fi
    local -a TARGETS
    local -a FIND_PATHS=( "/" )
    local -a FLINES
    local FIND_PATH FLINE
    while [[ "$CURRENT_PATH" != "/" ]]; do
        FIND_PATHS+=( "$CURRENT_PATH" )
        CURRENT_PATH=$(dirname $CURRENT_PATH)
    done
    for FIND_PATH in ${FIND_PATHS[@]}; do
        if [[ -f "$FIND_PATH"/.cargo/config ]]; then
            FLINES=( `grep "$FIND_PATH"/.cargo/config -e "^\[target\."` )
            for FLINE in ${FLINES[@]}; do
                TARGETS+=(`sed 's/^\[target\.\(.*\)\]$/\1/' <<< $FLINE`)
            done
        fi
    done
    _describe 'target' TARGETS
}

526
527
528
529
530
531
532
533
534
535
536
537
538
539
# These flags are mutally exclusive specifiers for the scope of a command; as
# they are used in multiple places without change, they are expanded into the
# appropriate command's `_arguments` where appropriate.
set command_scope_spec
command_scope_spec=(
    '(--bin --example --test --lib)--bench=[benchmark name]: :_benchmark_names'
    '(--bench --bin --test --lib)--example=[example name]'
    '(--bench --example --test --lib)--bin=[binary name]'
    '(--bench --bin --example --test)--lib=[library name]'
    '(--bench --bin --example --lib)--test=[test name]'
)


_cargo