_cargo 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. #compdef cargo
  2. typeset -A opt_args
  3. autoload -U regexp-replace
  4. _cargo() {
  5. _arguments \
  6. '(- 1 *)'{-h,--help}'[show help message]' \
  7. '(- 1 *)'--list'[list installed commands]' \
  8. '(- 1 *)'{-v,--verbose}'[use verbose output]' \
  9. '(- 1 *)'--color'[colorization option]' \
  10. '(- 1 *)'{-V,--version}'[show version information]' \
  11. '1: :_cargo_cmds' \
  12. '*:: :->args'
  13. case $state in
  14. args)
  15. case $words[1] in
  16. bench)
  17. _arguments \
  18. '--features=[space separated feature list]' \
  19. '--all-features[enable all available features]' \
  20. '(-h, --help)'{-h,--help}'[show help message]' \
  21. '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
  22. "${command_scope_spec[@]}" \
  23. '--manifest-path=[path to manifest]: :_files -/' \
  24. '--no-default-features[do not build the default features]' \
  25. '--no-run[compile but do not run]' \
  26. '(-p,--package)'{-p=,--package=}'[package to run benchmarks for]:packages:_get_package_names' \
  27. '--target=[target triple]' \
  28. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  29. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  30. '--color=:colorization option:(auto always never)' \
  31. ;;
  32. build)
  33. _arguments \
  34. '--features=[space separated feature list]' \
  35. '--all-features[enable all available features]' \
  36. '(-h, --help)'{-h,--help}'[show help message]' \
  37. '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
  38. "${command_scope_spec[@]}" \
  39. '--manifest-path=[path to manifest]: :_files -/' \
  40. '--no-default-features[do not build the default features]' \
  41. '(-p,--package)'{-p=,--package=}'[package to build]:packages:_get_package_names' \
  42. '--release=[build in release mode]' \
  43. '--target=[target triple]' \
  44. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  45. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  46. '--color=:colorization option:(auto always never)' \
  47. ;;
  48. clean)
  49. _arguments \
  50. '(-h, --help)'{-h,--help}'[show help message]' \
  51. '--manifest-path=[path to manifest]: :_files -/' \
  52. '(-p,--package)'{-p=,--package=}'[package to clean]:packages:_get_package_names' \
  53. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  54. '--release[whether or not to clean release artifacts]' \
  55. '--target=[target triple(default:all)]' \
  56. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  57. '--color=:colorization option:(auto always never)' \
  58. ;;
  59. doc)
  60. _arguments \
  61. '--features=[space separated feature list]' \
  62. '--all-features[enable all available features]' \
  63. '(-h, --help)'{-h,--help}'[show help message]' \
  64. '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
  65. '--manifest-path=[path to manifest]: :_files -/' \
  66. '--no-deps[do not build docs for dependencies]' \
  67. '--no-default-features[do not build the default features]' \
  68. '--open[open docs in browser after the build]' \
  69. '(-p, --package)'{-p,--package}'=[package to document]' \
  70. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  71. '--release[build artifacts in release mode, with optimizations]' \
  72. '--target=[build for the target triple]' \
  73. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  74. '--color=:colorization option:(auto always never)' \
  75. ;;
  76. fetch)
  77. _arguments \
  78. '(-h, --help)'{-h,--help}'[show help message]' \
  79. '--manifest-path=[path to manifest]: :_files -/' \
  80. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  81. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  82. '--color=:colorization option:(auto always never)' \
  83. ;;
  84. generate-lockfile)
  85. _arguments \
  86. '(-h, --help)'{-h,--help}'[show help message]' \
  87. '--manifest-path=[path to manifest]: :_files -/' \
  88. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  89. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  90. '--color=:colorization option:(auto always never)' \
  91. ;;
  92. git-checkout)
  93. _arguments \
  94. '(-h, --help)'{-h,--help}'[show help message]' \
  95. 'q(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  96. '--reference=[REF]' \
  97. '--url=[URL]' \
  98. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  99. '--color=:colorization option:(auto always never)' \
  100. ;;
  101. help)
  102. _arguments \
  103. '(-h, --help)'{-h,--help}'[show help message]' \
  104. '*: :_cargo_cmds' \
  105. ;;
  106. init)
  107. _arguments \
  108. '--bin[use binary template]' \
  109. '--vcs:initialize a new repo with a given VCS:(git hg none)' \
  110. '(-h, --help)'{-h,--help}'[show help message]' \
  111. '--name=[set the resulting package name]' \
  112. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  113. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  114. '--color=:colorization option:(auto always never)' \
  115. ;;
  116. install)
  117. _arguments \
  118. '--bin=[only install the specified binary]' \
  119. '--branch=[branch to use when installing from git]' \
  120. '--color=:colorization option:(auto always never)' \
  121. '--debug[build in debug mode instead of release mode]' \
  122. '--example[install the specified example instead of binaries]' \
  123. '--features=[space separated feature list]' \
  124. '--all-features[enable all available features]' \
  125. '--git=[URL from which to install the crate]' \
  126. '(-h, --help)'{-h,--help}'[show help message]' \
  127. '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
  128. '--no-default-features[do not build the default features]' \
  129. '--path=[local filesystem path to crate to install]' \
  130. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  131. '--rev=[specific commit to use when installing from git]' \
  132. '--root=[directory to install packages into]' \
  133. '--tag=[tag to use when installing from git]' \
  134. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  135. '--vers=[version to install from crates.io]' \
  136. ;;
  137. locate-project)
  138. _arguments \
  139. '(-h, --help)'{-h,--help}'[show help message]' \
  140. '--manifest-path=[path to manifest]: :_files -/' \
  141. ;;
  142. login)
  143. _arguments \
  144. '(-h, --help)'{-h,--help}'[show help message]' \
  145. '--host=[Host to set the token for]' \
  146. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  147. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  148. '--color=:colorization option:(auto always never)' \
  149. ;;
  150. metadata)
  151. _arguments \
  152. '(-h, --help)'{-h,--help}'[show help message]' \
  153. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  154. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  155. "--no-deps[output information only about the root package and don't fetch dependencies]" \
  156. '--no-default-features[do not include the default feature]' \
  157. '--manifest-path=[path to manifest]: :_files -/' \
  158. '--features=[space separated feature list]' \
  159. '--all-features[enable all available features]' \
  160. '--format-version=[format version(default: 1)]' \
  161. '--color=:colorization option:(auto always never)' \
  162. ;;
  163. new)
  164. _arguments \
  165. '--bin[use binary template]' \
  166. '--vcs:initialize a new repo with a given VCS:(git hg none)' \
  167. '(-h, --help)'{-h,--help}'[show help message]' \
  168. '--name=[set the resulting package name]' \
  169. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  170. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  171. '--color=:colorization option:(auto always never)' \
  172. ;;
  173. owner)
  174. _arguments \
  175. '(-a, --add)'{-a,--add}'[add owner LOGIN]' \
  176. '(-h, --help)'{-h,--help}'[show help message]' \
  177. '--index[registry index]' \
  178. '(-l, --list)'{-l,--list}'[list owners of a crate]' \
  179. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  180. '(-r, --remove)'{-r,--remove}'[remove owner LOGIN]' \
  181. '--token[API token to use when authenticating]' \
  182. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  183. '--color=:colorization option:(auto always never)' \
  184. ;;
  185. package)
  186. _arguments \
  187. '(-h, --help)'{-h,--help}'[show help message]' \
  188. '(-l, --list)'{-l,--list}'[print files included in a package without making one]' \
  189. '--manifest-path=[path to manifest]: :_files -/' \
  190. '--no-metadata[ignore warnings about a lack of human-usable metadata]' \
  191. '--no-verify[do not build to verify contents]' \
  192. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  193. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  194. '--color=:colorization option:(auto always never)' \
  195. ;;
  196. pkgid)
  197. _arguments \
  198. '(-h, --help)'{-h,--help}'[show help message]' \
  199. '--manifest-path=[path to manifest]: :_files -/' \
  200. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  201. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  202. '--color=:colorization option:(auto always never)' \
  203. ;;
  204. publish)
  205. _arguments \
  206. '(-h, --help)'{-h,--help}'[show help message]' \
  207. '--host=[Host to set the token for]' \
  208. '--manifest-path=[path to manifest]: :_files -/' \
  209. '--no-verify[Do not verify tarball until before publish]' \
  210. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  211. '--token[token to use when uploading]' \
  212. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  213. '--color=:colorization option:(auto always never)' \
  214. ;;
  215. read-manifest)
  216. _arguments \
  217. '(-h, --help)'{-h,--help}'[show help message]' \
  218. '--manifest-path=[path to manifest]: :_files -/' \
  219. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  220. '--color=:colorization option:(auto always never)' \
  221. ;;
  222. run)
  223. _arguments \
  224. '--example=[name of the bin target]' \
  225. '--features=[space separated feature list]' \
  226. '--all-features[enable all available features]' \
  227. '(-h, --help)'{-h,--help}'[show help message]' \
  228. '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
  229. '--manifest-path=[path to manifest]: :_files -/' \
  230. '--bin=[name of the bin target]' \
  231. '--no-default-features[do not build the default features]' \
  232. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  233. '--release=[build in release mode]' \
  234. '--target=[target triple]' \
  235. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  236. '--color=:colorization option:(auto always never)' \
  237. '*: :_normal' \
  238. ;;
  239. rustc)
  240. _arguments \
  241. '--color=:colorization option:(auto always never)' \
  242. '--features=[features to compile for the package]' \
  243. '--all-features[enable all available features]' \
  244. '(-h, --help)'{-h,--help}'[show help message]' \
  245. '(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
  246. '--manifest-path=[path to the manifest to fetch dependencies for]' \
  247. '--no-default-features[do not compile default features for the package]' \
  248. '(-p, --package)'{-p,--package}'=[profile to compile for]' \
  249. '--profile=[profile to build the selected target for]' \
  250. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  251. '--release[build artifacts in release mode, with optimizations]' \
  252. '--target=[target triple which compiles will be for]' \
  253. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  254. "${command_scope_spec[@]}" \
  255. ;;
  256. rustdoc)
  257. _arguments \
  258. '--color=:colorization option:(auto always never)' \
  259. '--features=[space-separated list of features to also build]' \
  260. '--all-features[enable all available features]' \
  261. '(-h, --help)'{-h,--help}'[show help message]' \
  262. '(-j, --jobs)'{-j,--jobs}'=[number of parallel jobs, defaults to # of CPUs]' \
  263. '--manifest-path=[path to the manifest to document]' \
  264. '--no-default-features[do not build the `default` feature]' \
  265. '--open[open the docs in a browser after the operation]' \
  266. '(-p, --package)'{-p,--package}'=[package to document]' \
  267. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  268. '--release[build artifacts in release mode, with optimizations]' \
  269. '--target=[build for the target triple]' \
  270. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  271. "${command_scope_spec[@]}" \
  272. ;;
  273. search)
  274. _arguments \
  275. '--color=:colorization option:(auto always never)' \
  276. '(-h, --help)'{-h,--help}'[show help message]' \
  277. '--host=[host of a registry to search in]' \
  278. '--limit=[limit the number of results]' \
  279. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  280. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  281. ;;
  282. test)
  283. _arguments \
  284. '--features=[space separated feature list]' \
  285. '--all-features[enable all available features]' \
  286. '(-h, --help)'{-h,--help}'[show help message]' \
  287. '(-j, --jobs)'{-j,--jobs}'[number of parallel jobs, defaults to # of CPUs]' \
  288. '--manifest-path=[path to manifest]: :_files -/' \
  289. '--test=[test name]: :_test_names' \
  290. '--no-default-features[do not build the default features]' \
  291. '--no-fail-fast[run all tests regardless of failure]' \
  292. '--no-run[compile but do not run]' \
  293. '(-p,--package)'{-p=,--package=}'[package to run tests for]:packages:_get_package_names' \
  294. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  295. '--release[build artifacts in release mode, with optimizations]' \
  296. '--target=[target triple]' \
  297. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  298. '--color=:colorization option:(auto always never)' \
  299. '1: :_test_names' \
  300. ;;
  301. uninstall)
  302. _arguments \
  303. '--bin=[only uninstall the binary NAME]' \
  304. '--color=:colorization option:(auto always never)' \
  305. '(-h, --help)'{-h,--help}'[show help message]' \
  306. '(-q, --quiet)'{-q,--quiet}'[less output printed to stdout]' \
  307. '--root=[directory to uninstall packages from]' \
  308. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  309. ;;
  310. update)
  311. _arguments \
  312. '--aggressive=[force dependency update]' \
  313. '(-h, --help)'{-h,--help}'[show help message]' \
  314. '--manifest-path=[path to manifest]: :_files -/' \
  315. '(-p,--package)'{-p=,--package=}'[package to update]:packages:__get_package_names' \
  316. '--precise=[update single dependency to PRECISE]: :' \
  317. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  318. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  319. '--color=:colorization option:(auto always never)' \
  320. ;;
  321. verify-project)
  322. _arguments \
  323. '(-h, --help)'{-h,--help}'[show help message]' \
  324. '--manifest-path=[path to manifest]: :_files -/' \
  325. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  326. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  327. '--color=:colorization option:(auto always never)' \
  328. ;;
  329. version)
  330. _arguments \
  331. '(-h, --help)'{-h,--help}'[show help message]' \
  332. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  333. '--color=:colorization option:(auto always never)' \
  334. ;;
  335. yank)
  336. _arguments \
  337. '(-h, --help)'{-h,--help}'[show help message]' \
  338. '--index[registry index]' \
  339. '(-q, --quiet)'{-q,--quiet}'[no output printed to stdout]' \
  340. '--token[API token to use when authenticating]' \
  341. '--undo[undo a yank, putting a version back into the index]' \
  342. '(-v, --verbose)'{-v,--verbose}'[use verbose output]' \
  343. '--color=:colorization option:(auto always never)' \
  344. '--vers[yank version]' \
  345. ;;
  346. esac
  347. ;;
  348. esac
  349. }
  350. _cargo_cmds(){
  351. local -a commands;commands=(
  352. 'bench:execute all benchmarks of a local package'
  353. 'build:compile the current project'
  354. 'clean:remove generated artifacts'
  355. 'doc:build package documentation'
  356. 'fetch:fetch package dependencies'
  357. 'generate-lockfile:create lockfile'
  358. 'git-checkout:git checkout'
  359. 'help:get help for commands'
  360. 'init:create new project in current directory'
  361. 'install:install a Rust binary'
  362. 'locate-project:print "Cargo.toml" location'
  363. 'login:login to remote server'
  364. 'metadata:the metadata for a project in json'
  365. 'new:create a new project'
  366. 'owner:manage the owners of a crate on the registry'
  367. 'package:assemble local package into a distributable tarball'
  368. 'pkgid:print a fully qualified package specification'
  369. 'publish:upload package to the registry'
  370. 'read-manifest:print manifest in JSON format'
  371. 'run:run the main binary of the local package'
  372. 'rustc:compile a package and all of its dependencies'
  373. 'rustdoc:build documentation for a package'
  374. 'search:search packages on crates.io'
  375. 'test:execute all unit and tests of a local package'
  376. 'uninstall:remove a Rust binary'
  377. 'update:update dependencies'
  378. 'verify-project:check Cargo.toml'
  379. 'version:show version information'
  380. 'yank:remove pushed file from index'
  381. )
  382. _describe 'command' commands
  383. }
  384. #FIXME: Disabled until fixed
  385. #gets package names from the manifest file
  386. _get_package_names()
  387. {
  388. }
  389. #TODO:see if it makes sense to have 'locate-project' to have non-json output.
  390. #strips package name from json stuff
  391. _locate_manifest(){
  392. local manifest=`cargo locate-project 2>/dev/null`
  393. regexp-replace manifest '\{"root":"|"\}' ''
  394. echo $manifest
  395. }
  396. # Extracts the values of "name" from the array given in $1 and shows them as
  397. # command line options for completion
  398. _get_names_from_array()
  399. {
  400. local -a filelist;
  401. local manifest=$(_locate_manifest)
  402. if [[ -z $manifest ]]; then
  403. return 0
  404. fi
  405. local last_line
  406. local -a names;
  407. local in_block=false
  408. local block_name=$1
  409. names=()
  410. while read line
  411. do
  412. if [[ $last_line == "[[$block_name]]" ]]; then
  413. in_block=true
  414. else
  415. if [[ $last_line =~ '.*\[\[.*' ]]; then
  416. in_block=false
  417. fi
  418. fi
  419. if [[ $in_block == true ]]; then
  420. if [[ $line =~ '.*name.*=' ]]; then
  421. regexp-replace line '^.*name *= *|"' ""
  422. names+=$line
  423. fi
  424. fi
  425. last_line=$line
  426. done < $manifest
  427. _describe $block_name names
  428. }
  429. #Gets the test names from the manifest file
  430. _test_names()
  431. {
  432. _get_names_from_array "test"
  433. }
  434. #Gets the bench names from the manifest file
  435. _benchmark_names()
  436. {
  437. _get_names_from_array "bench"
  438. }
  439. # These flags are mutally exclusive specifiers for the scope of a command; as
  440. # they are used in multiple places without change, they are expanded into the
  441. # appropriate command's `_arguments` where appropriate.
  442. set command_scope_spec
  443. command_scope_spec=(
  444. '(--bin --example --test --lib)--bench=[benchmark name]: :_benchmark_names'
  445. '(--bench --bin --test --lib)--example=[example name]'
  446. '(--bench --example --test --lib)--bin=[binary name]'
  447. '(--bench --bin --example --test)--lib=[library name]'
  448. '(--bench --bin --example --lib)--test=[test name]'
  449. )
  450. _cargo