_swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. #compdef swift
  2. local context state state_descr line
  3. typeset -A opt_args
  4. _swift() {
  5. _arguments -C \
  6. '(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \
  7. '(-): :->command' \
  8. '(-)*:: :->arg' && return
  9. case $state in
  10. (command)
  11. local tools
  12. tools=(
  13. 'build:build sources into binary products'
  14. 'run:build and run an executable product'
  15. 'package:perform operations on Swift packages'
  16. 'test:build and run tests'
  17. )
  18. _alternative \
  19. 'tools:common:{_describe "tool" tools }' \
  20. 'compiler: :_swift_compiler' && _ret=0
  21. ;;
  22. (arg)
  23. case ${words[1]} in
  24. (build)
  25. _swift_build
  26. ;;
  27. (run)
  28. _swift_run
  29. ;;
  30. (package)
  31. _swift_package
  32. ;;
  33. (test)
  34. _swift_test
  35. ;;
  36. (*)
  37. _swift_compiler
  38. ;;
  39. esac
  40. ;;
  41. esac
  42. }
  43. _swift_dependency() {
  44. local dependencies
  45. dependencies=( $(swift package completion-tool list-dependencies) )
  46. _describe '' dependencies
  47. }
  48. _swift_executable() {
  49. local executables
  50. executables=( $(swift package completion-tool list-executables) )
  51. _describe '' executables
  52. }
  53. # Generates completions for swift build
  54. #
  55. # In the final compdef file, set the following file header:
  56. #
  57. # #compdef _swift_build
  58. # local context state state_descr line
  59. # typeset -A opt_args
  60. _swift_build() {
  61. arguments=(
  62. "-Xcc[Pass flag through to all C compiler invocations]:Pass flag through to all C compiler invocations: "
  63. "-Xswiftc[Pass flag through to all Swift compiler invocations]:Pass flag through to all Swift compiler invocations: "
  64. "-Xlinker[Pass flag through to all linker invocations]:Pass flag through to all linker invocations: "
  65. "-Xcxx[Pass flag through to all C++ compiler invocations]:Pass flag through to all C++ compiler invocations: "
  66. "(--configuration -c)"{--configuration,-c}"[Build with configuration (debug|release) ]: :{_values '' 'debug[build with DEBUG configuration]' 'release[build with RELEASE configuration]'}"
  67. "--build-path[Specify build/cache directory ]:Specify build/cache directory :_files"
  68. "(--chdir -C)"{--chdir,-C}"[]: :_files"
  69. "--package-path[Change working directory before any other operation]:Change working directory before any other operation:_files"
  70. "--sanitize[Turn on runtime checks for erroneous behavior]: :{_values '' 'address[enable Address sanitizer]' 'thread[enable Thread sanitizer]' 'undefined[enable Undefined Behavior sanitizer]'}"
  71. "--disable-prefetching[]"
  72. "--skip-update[Skip updating dependencies from their remote during a resolution]"
  73. "--disable-sandbox[Disable using the sandbox when executing subprocesses]"
  74. "--disable-package-manifest-caching[Disable caching Package.swift manifests]"
  75. "--version[]"
  76. "--destination[]: :_files"
  77. "(--verbose -v)"{--verbose,-v}"[Increase verbosity of informational output]"
  78. "--no-static-swift-stdlib[Do not link Swift stdlib statically \[default\]]"
  79. "--static-swift-stdlib[Link Swift stdlib statically]"
  80. "--enable-llbuild-library[Enable building with the llbuild library]"
  81. "--force-resolved-versions[]"
  82. "--disable-automatic-resolution[Disable automatic resolution if Package.resolved file is out-of-date]"
  83. "--enable-index-store[Enable indexing-while-building feature]"
  84. "--disable-index-store[Disable indexing-while-building feature]"
  85. "--enable-pubgrub-resolver[\[Experimental\] Enable the new Pubgrub dependency resolver]"
  86. "--enable-parseable-module-interfaces[]"
  87. "--build-tests[Build both source and test targets]"
  88. "--product[Build the specified product]:Build the specified product: "
  89. "--target[Build the specified target]:Build the specified target: "
  90. "--show-bin-path[Print the binary output path]"
  91. )
  92. _arguments $arguments && return
  93. }
  94. # Generates completions for swift run
  95. #
  96. # In the final compdef file, set the following file header:
  97. #
  98. # #compdef _swift_run
  99. # local context state state_descr line
  100. # typeset -A opt_args
  101. _swift_run() {
  102. arguments=(
  103. ":The executable to run:_swift_executable"
  104. "-Xcc[Pass flag through to all C compiler invocations]:Pass flag through to all C compiler invocations: "
  105. "-Xswiftc[Pass flag through to all Swift compiler invocations]:Pass flag through to all Swift compiler invocations: "
  106. "-Xlinker[Pass flag through to all linker invocations]:Pass flag through to all linker invocations: "
  107. "-Xcxx[Pass flag through to all C++ compiler invocations]:Pass flag through to all C++ compiler invocations: "
  108. "(--configuration -c)"{--configuration,-c}"[Build with configuration (debug|release) ]: :{_values '' 'debug[build with DEBUG configuration]' 'release[build with RELEASE configuration]'}"
  109. "--build-path[Specify build/cache directory ]:Specify build/cache directory :_files"
  110. "(--chdir -C)"{--chdir,-C}"[]: :_files"
  111. "--package-path[Change working directory before any other operation]:Change working directory before any other operation:_files"
  112. "--sanitize[Turn on runtime checks for erroneous behavior]: :{_values '' 'address[enable Address sanitizer]' 'thread[enable Thread sanitizer]' 'undefined[enable Undefined Behavior sanitizer]'}"
  113. "--disable-prefetching[]"
  114. "--skip-update[Skip updating dependencies from their remote during a resolution]"
  115. "--disable-sandbox[Disable using the sandbox when executing subprocesses]"
  116. "--disable-package-manifest-caching[Disable caching Package.swift manifests]"
  117. "--version[]"
  118. "--destination[]: :_files"
  119. "(--verbose -v)"{--verbose,-v}"[Increase verbosity of informational output]"
  120. "--no-static-swift-stdlib[Do not link Swift stdlib statically \[default\]]"
  121. "--static-swift-stdlib[Link Swift stdlib statically]"
  122. "--enable-llbuild-library[Enable building with the llbuild library]"
  123. "--force-resolved-versions[]"
  124. "--disable-automatic-resolution[Disable automatic resolution if Package.resolved file is out-of-date]"
  125. "--enable-index-store[Enable indexing-while-building feature]"
  126. "--disable-index-store[Disable indexing-while-building feature]"
  127. "--enable-pubgrub-resolver[\[Experimental\] Enable the new Pubgrub dependency resolver]"
  128. "--enable-parseable-module-interfaces[]"
  129. "--skip-build[Skip building the executable product]"
  130. "--build-tests[Build both source and test targets]"
  131. "--repl[Launch Swift REPL for the package]"
  132. )
  133. _arguments $arguments && return
  134. }
  135. # Generates completions for swift package
  136. #
  137. # In the final compdef file, set the following file header:
  138. #
  139. # #compdef _swift_package
  140. # local context state state_descr line
  141. # typeset -A opt_args
  142. _swift_package() {
  143. arguments=(
  144. "-Xcc[Pass flag through to all C compiler invocations]:Pass flag through to all C compiler invocations: "
  145. "-Xswiftc[Pass flag through to all Swift compiler invocations]:Pass flag through to all Swift compiler invocations: "
  146. "-Xlinker[Pass flag through to all linker invocations]:Pass flag through to all linker invocations: "
  147. "-Xcxx[Pass flag through to all C++ compiler invocations]:Pass flag through to all C++ compiler invocations: "
  148. "(--configuration -c)"{--configuration,-c}"[Build with configuration (debug|release) ]: :{_values '' 'debug[build with DEBUG configuration]' 'release[build with RELEASE configuration]'}"
  149. "--build-path[Specify build/cache directory ]:Specify build/cache directory :_files"
  150. "(--chdir -C)"{--chdir,-C}"[]: :_files"
  151. "--package-path[Change working directory before any other operation]:Change working directory before any other operation:_files"
  152. "--sanitize[Turn on runtime checks for erroneous behavior]: :{_values '' 'address[enable Address sanitizer]' 'thread[enable Thread sanitizer]' 'undefined[enable Undefined Behavior sanitizer]'}"
  153. "--disable-prefetching[]"
  154. "--skip-update[Skip updating dependencies from their remote during a resolution]"
  155. "--disable-sandbox[Disable using the sandbox when executing subprocesses]"
  156. "--disable-package-manifest-caching[Disable caching Package.swift manifests]"
  157. "--version[]"
  158. "--destination[]: :_files"
  159. "(--verbose -v)"{--verbose,-v}"[Increase verbosity of informational output]"
  160. "--no-static-swift-stdlib[Do not link Swift stdlib statically \[default\]]"
  161. "--static-swift-stdlib[Link Swift stdlib statically]"
  162. "--enable-llbuild-library[Enable building with the llbuild library]"
  163. "--force-resolved-versions[]"
  164. "--disable-automatic-resolution[Disable automatic resolution if Package.resolved file is out-of-date]"
  165. "--enable-index-store[Enable indexing-while-building feature]"
  166. "--disable-index-store[Disable indexing-while-building feature]"
  167. "--enable-pubgrub-resolver[\[Experimental\] Enable the new Pubgrub dependency resolver]"
  168. "--enable-parseable-module-interfaces[]"
  169. '(-): :->command'
  170. '(-)*:: :->arg'
  171. )
  172. _arguments $arguments && return
  173. case $state in
  174. (command)
  175. local modes
  176. modes=(
  177. 'update:Update package dependencies'
  178. 'describe:Describe the current package'
  179. 'resolve:Resolve package dependencies'
  180. 'tools-version:Manipulate tools version of the current package'
  181. 'unedit:Remove a package from editable mode'
  182. 'show-dependencies:Print the resolved dependency graph'
  183. 'fetch:'
  184. 'dump-package:Print parsed Package.swift as JSON'
  185. 'edit:Put a package in editable mode'
  186. 'config:Manipulate configuration of the package'
  187. 'completion-tool:Completion tool (for shell completions)'
  188. 'clean:Delete build artifacts'
  189. 'generate-xcodeproj:Generates an Xcode project'
  190. 'reset:Reset the complete cache/build directory'
  191. 'init:Initialize a new package'
  192. )
  193. _describe "mode" modes
  194. ;;
  195. (arg)
  196. case ${words[1]} in
  197. (update)
  198. _swift_package_update
  199. ;;
  200. (describe)
  201. _swift_package_describe
  202. ;;
  203. (resolve)
  204. _swift_package_resolve
  205. ;;
  206. (tools-version)
  207. _swift_package_tools-version
  208. ;;
  209. (unedit)
  210. _swift_package_unedit
  211. ;;
  212. (show-dependencies)
  213. _swift_package_show-dependencies
  214. ;;
  215. (fetch)
  216. _swift_package_fetch
  217. ;;
  218. (dump-package)
  219. _swift_package_dump-package
  220. ;;
  221. (edit)
  222. _swift_package_edit
  223. ;;
  224. (config)
  225. _swift_package_config
  226. ;;
  227. (completion-tool)
  228. _swift_package_completion-tool
  229. ;;
  230. (clean)
  231. _swift_package_clean
  232. ;;
  233. (generate-xcodeproj)
  234. _swift_package_generate-xcodeproj
  235. ;;
  236. (reset)
  237. _swift_package_reset
  238. ;;
  239. (init)
  240. _swift_package_init
  241. ;;
  242. esac
  243. ;;
  244. esac
  245. }
  246. _swift_package_update() {
  247. arguments=(
  248. )
  249. _arguments $arguments && return
  250. }
  251. _swift_package_describe() {
  252. arguments=(
  253. "--type[json|text]: :{_values '' 'text[describe using text format]' 'json[describe using JSON format]'}"
  254. )
  255. _arguments $arguments && return
  256. }
  257. _swift_package_resolve() {
  258. arguments=(
  259. ":The name of the package to resolve:_swift_dependency"
  260. "--version[The version to resolve at]:The version to resolve at: "
  261. "--branch[The branch to resolve at]:The branch to resolve at: "
  262. "--revision[The revision to resolve at]:The revision to resolve at: "
  263. )
  264. _arguments $arguments && return
  265. }
  266. _swift_package_tools-version() {
  267. arguments=(
  268. "--set[Set tools version of package to the given value]:Set tools version of package to the given value: "
  269. "--set-current[Set tools version of package to the current tools version in use]"
  270. )
  271. _arguments $arguments && return
  272. }
  273. _swift_package_unedit() {
  274. arguments=(
  275. ":The name of the package to unedit:_swift_dependency"
  276. "--force[Unedit the package even if it has uncommited and unpushed changes.]"
  277. )
  278. _arguments $arguments && return
  279. }
  280. _swift_package_show-dependencies() {
  281. arguments=(
  282. "--format[text|dot|json|flatlist]: :{_values '' 'text[list dependencies using text format]' 'dot[list dependencies using dot format]' 'json[list dependencies using JSON format]'}"
  283. )
  284. _arguments $arguments && return
  285. }
  286. _swift_package_fetch() {
  287. arguments=(
  288. )
  289. _arguments $arguments && return
  290. }
  291. _swift_package_dump-package() {
  292. arguments=(
  293. )
  294. _arguments $arguments && return
  295. }
  296. _swift_package_edit() {
  297. arguments=(
  298. ":The name of the package to edit:_swift_dependency"
  299. "--revision[The revision to edit]:The revision to edit: "
  300. "--branch[The branch to create]:The branch to create: "
  301. "--path[Create or use the checkout at this path]:Create or use the checkout at this path:_files"
  302. )
  303. _arguments $arguments && return
  304. }
  305. _swift_package_config() {
  306. arguments=(
  307. '(-): :->command'
  308. '(-)*:: :->arg'
  309. )
  310. _arguments $arguments && return
  311. case $state in
  312. (command)
  313. local modes
  314. modes=(
  315. 'unset-mirror:Remove an existing mirror'
  316. 'set-mirror:Set a mirror for a dependency'
  317. 'get-mirror:Print mirror configuration for the given package dependency'
  318. )
  319. _describe "mode" modes
  320. ;;
  321. (arg)
  322. case ${words[1]} in
  323. (unset-mirror)
  324. _swift_package_config_unset-mirror
  325. ;;
  326. (set-mirror)
  327. _swift_package_config_set-mirror
  328. ;;
  329. (get-mirror)
  330. _swift_package_config_get-mirror
  331. ;;
  332. esac
  333. ;;
  334. esac
  335. }
  336. _swift_package_config_unset-mirror() {
  337. arguments=(
  338. "--package-url[The package dependency url]:The package dependency url: "
  339. "--mirror-url[The mirror url]:The mirror url: "
  340. )
  341. _arguments $arguments && return
  342. }
  343. _swift_package_config_set-mirror() {
  344. arguments=(
  345. "--package-url[The package dependency url]:The package dependency url: "
  346. "--mirror-url[The mirror url]:The mirror url: "
  347. )
  348. _arguments $arguments && return
  349. }
  350. _swift_package_config_get-mirror() {
  351. arguments=(
  352. "--package-url[The package dependency url]:The package dependency url: "
  353. )
  354. _arguments $arguments && return
  355. }
  356. _swift_package_completion-tool() {
  357. arguments=(
  358. ": :{_values '' 'generate-bash-script[generate Bash completion script]' 'generate-zsh-script[generate Bash completion script]' 'list-dependencies[list all dependencies' names]' 'list-executables[list all executables' names]'}"
  359. )
  360. _arguments $arguments && return
  361. }
  362. _swift_package_clean() {
  363. arguments=(
  364. )
  365. _arguments $arguments && return
  366. }
  367. _swift_package_generate-xcodeproj() {
  368. arguments=(
  369. "--xcconfig-overrides[Path to xcconfig file]:Path to xcconfig file:_files"
  370. "--enable-code-coverage[Enable code coverage in the generated project]"
  371. "--output[Path where the Xcode project should be generated]:Path where the Xcode project should be generated:_files"
  372. "--legacy-scheme-generator[Use the legacy scheme generator]"
  373. "--watch[Watch for changes to the Package manifest to regenerate the Xcode project]"
  374. "--skip-extra-files[Do not add file references for extra files to the generated Xcode project]"
  375. )
  376. _arguments $arguments && return
  377. }
  378. _swift_package_reset() {
  379. arguments=(
  380. )
  381. _arguments $arguments && return
  382. }
  383. _swift_package_init() {
  384. arguments=(
  385. "--type[empty|library|executable|system-module]: :{_values '' 'empty[generates an empty project]' 'library[generates project for a dynamic library]' 'executable[generates a project for a cli executable]' 'system-module[generates a project for a system module]'}"
  386. "--name[Provide custom package name]:Provide custom package name: "
  387. )
  388. _arguments $arguments && return
  389. }
  390. # Generates completions for swift test
  391. #
  392. # In the final compdef file, set the following file header:
  393. #
  394. # #compdef _swift_test
  395. # local context state state_descr line
  396. # typeset -A opt_args
  397. _swift_test() {
  398. arguments=(
  399. "-Xcc[Pass flag through to all C compiler invocations]:Pass flag through to all C compiler invocations: "
  400. "-Xswiftc[Pass flag through to all Swift compiler invocations]:Pass flag through to all Swift compiler invocations: "
  401. "-Xlinker[Pass flag through to all linker invocations]:Pass flag through to all linker invocations: "
  402. "-Xcxx[Pass flag through to all C++ compiler invocations]:Pass flag through to all C++ compiler invocations: "
  403. "(--configuration -c)"{--configuration,-c}"[Build with configuration (debug|release) ]: :{_values '' 'debug[build with DEBUG configuration]' 'release[build with RELEASE configuration]'}"
  404. "--build-path[Specify build/cache directory ]:Specify build/cache directory :_files"
  405. "(--chdir -C)"{--chdir,-C}"[]: :_files"
  406. "--package-path[Change working directory before any other operation]:Change working directory before any other operation:_files"
  407. "--sanitize[Turn on runtime checks for erroneous behavior]: :{_values '' 'address[enable Address sanitizer]' 'thread[enable Thread sanitizer]' 'undefined[enable Undefined Behavior sanitizer]'}"
  408. "--disable-prefetching[]"
  409. "--skip-update[Skip updating dependencies from their remote during a resolution]"
  410. "--disable-sandbox[Disable using the sandbox when executing subprocesses]"
  411. "--disable-package-manifest-caching[Disable caching Package.swift manifests]"
  412. "--version[]"
  413. "--destination[]: :_files"
  414. "(--verbose -v)"{--verbose,-v}"[Increase verbosity of informational output]"
  415. "--no-static-swift-stdlib[Do not link Swift stdlib statically \[default\]]"
  416. "--static-swift-stdlib[Link Swift stdlib statically]"
  417. "--enable-llbuild-library[Enable building with the llbuild library]"
  418. "--force-resolved-versions[]"
  419. "--disable-automatic-resolution[Disable automatic resolution if Package.resolved file is out-of-date]"
  420. "--enable-index-store[Enable indexing-while-building feature]"
  421. "--disable-index-store[Disable indexing-while-building feature]"
  422. "--enable-pubgrub-resolver[\[Experimental\] Enable the new Pubgrub dependency resolver]"
  423. "--enable-parseable-module-interfaces[]"
  424. "--skip-build[Skip building the test target]"
  425. "(--list-tests -l)"{--list-tests,-l}"[Lists test methods in specifier format]"
  426. "--generate-linuxmain[Generate LinuxMain.swift entries for the package]"
  427. "--parallel[Run the tests in parallel.]"
  428. "--num-workers[Number of tests to execute in parallel.]:Number of tests to execute in parallel.: "
  429. "(--specifier -s)"{--specifier,-s}"[]: : "
  430. "--xunit-output[]: :_files"
  431. "--filter[Run test cases matching regular expression, Format: <test-target>.<test-case> or <test-target>.<test-case>/<test>]:Run test cases matching regular expression, Format: <test-target>.<test-case> or <test-target>.<test-case>/<test>: "
  432. "--enable-code-coverage[Test with code coverage enabled]"
  433. )
  434. _arguments $arguments && return
  435. }
  436. _swift_compiler() {
  437. }
  438. _swift