_swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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]'}"
  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. "--version[]"
  75. "--destination[]: :_files"
  76. "(--verbose -v)"{--verbose,-v}"[Increase verbosity of informational output]"
  77. "--no-static-swift-stdlib[Do not link Swift stdlib statically \[default\]]"
  78. "--static-swift-stdlib[Link Swift stdlib statically]"
  79. "--enable-build-manifest-caching[Enable llbuild manifest caching \[Experimental\]]"
  80. "--build-tests[Build both source and test targets]"
  81. "--product[Build the specified product]:Build the specified product: "
  82. "--target[Build the specified target]:Build the specified target: "
  83. "--show-bin-path[Print the binary output path]"
  84. )
  85. _arguments $arguments && return
  86. }
  87. # Generates completions for swift run
  88. #
  89. # In the final compdef file, set the following file header:
  90. #
  91. # #compdef _swift_run
  92. # local context state state_descr line
  93. # typeset -A opt_args
  94. _swift_run() {
  95. arguments=(
  96. ":The executable to run:_swift_executable"
  97. "-Xcc[Pass flag through to all C compiler invocations]:Pass flag through to all C compiler invocations: "
  98. "-Xswiftc[Pass flag through to all Swift compiler invocations]:Pass flag through to all Swift compiler invocations: "
  99. "-Xlinker[Pass flag through to all linker invocations]:Pass flag through to all linker invocations: "
  100. "-Xcxx[Pass flag through to all C++ compiler invocations]:Pass flag through to all C++ compiler invocations: "
  101. "(--configuration -c)"{--configuration,-c}"[Build with configuration (debug|release) ]: :{_values '' 'debug[build with DEBUG configuration]' 'release[build with RELEASE configuration]'}"
  102. "--build-path[Specify build/cache directory ]:Specify build/cache directory :_files"
  103. "(--chdir -C)"{--chdir,-C}"[]: :_files"
  104. "--package-path[Change working directory before any other operation]:Change working directory before any other operation:_files"
  105. "--sanitize[Turn on runtime checks for erroneous behavior]: :{_values '' 'address[enable Address sanitizer]' 'thread[enable Thread sanitizer]'}"
  106. "--disable-prefetching[]"
  107. "--skip-update[Skip updating dependencies from their remote during a resolution]"
  108. "--disable-sandbox[Disable using the sandbox when executing subprocesses]"
  109. "--version[]"
  110. "--destination[]: :_files"
  111. "(--verbose -v)"{--verbose,-v}"[Increase verbosity of informational output]"
  112. "--no-static-swift-stdlib[Do not link Swift stdlib statically \[default\]]"
  113. "--static-swift-stdlib[Link Swift stdlib statically]"
  114. "--enable-build-manifest-caching[Enable llbuild manifest caching \[Experimental\]]"
  115. "--skip-build[Skip building the executable product]"
  116. )
  117. _arguments $arguments && return
  118. }
  119. # Generates completions for swift package
  120. #
  121. # In the final compdef file, set the following file header:
  122. #
  123. # #compdef _swift_package
  124. # local context state state_descr line
  125. # typeset -A opt_args
  126. _swift_package() {
  127. arguments=(
  128. "-Xcc[Pass flag through to all C compiler invocations]:Pass flag through to all C compiler invocations: "
  129. "-Xswiftc[Pass flag through to all Swift compiler invocations]:Pass flag through to all Swift compiler invocations: "
  130. "-Xlinker[Pass flag through to all linker invocations]:Pass flag through to all linker invocations: "
  131. "-Xcxx[Pass flag through to all C++ compiler invocations]:Pass flag through to all C++ compiler invocations: "
  132. "(--configuration -c)"{--configuration,-c}"[Build with configuration (debug|release) ]: :{_values '' 'debug[build with DEBUG configuration]' 'release[build with RELEASE configuration]'}"
  133. "--build-path[Specify build/cache directory ]:Specify build/cache directory :_files"
  134. "(--chdir -C)"{--chdir,-C}"[]: :_files"
  135. "--package-path[Change working directory before any other operation]:Change working directory before any other operation:_files"
  136. "--sanitize[Turn on runtime checks for erroneous behavior]: :{_values '' 'address[enable Address sanitizer]' 'thread[enable Thread sanitizer]'}"
  137. "--disable-prefetching[]"
  138. "--skip-update[Skip updating dependencies from their remote during a resolution]"
  139. "--disable-sandbox[Disable using the sandbox when executing subprocesses]"
  140. "--version[]"
  141. "--destination[]: :_files"
  142. "(--verbose -v)"{--verbose,-v}"[Increase verbosity of informational output]"
  143. "--no-static-swift-stdlib[Do not link Swift stdlib statically \[default\]]"
  144. "--static-swift-stdlib[Link Swift stdlib statically]"
  145. "--enable-build-manifest-caching[Enable llbuild manifest caching \[Experimental\]]"
  146. '(-): :->command'
  147. '(-)*:: :->arg'
  148. )
  149. _arguments $arguments && return
  150. case $state in
  151. (command)
  152. local modes
  153. modes=(
  154. 'edit:Put a package in editable mode'
  155. 'clean:Delete build artifacts'
  156. 'init:Initialize a new package'
  157. 'dump-package:Print parsed Package.swift as JSON'
  158. 'describe:Describe the current package'
  159. 'unedit:Remove a package from editable mode'
  160. 'update:Update package dependencies'
  161. 'completion-tool:Completion tool (for shell completions)'
  162. 'tools-version:Manipulate tools version of the current package'
  163. 'reset:Reset the complete cache/build directory'
  164. 'resolve:Resolve package dependencies'
  165. 'generate-xcodeproj:Generates an Xcode project'
  166. 'fetch:'
  167. 'show-dependencies:Print the resolved dependency graph'
  168. )
  169. _describe "mode" modes
  170. ;;
  171. (arg)
  172. case ${words[1]} in
  173. (edit)
  174. _swift_package_edit
  175. ;;
  176. (clean)
  177. _swift_package_clean
  178. ;;
  179. (init)
  180. _swift_package_init
  181. ;;
  182. (dump-package)
  183. _swift_package_dump-package
  184. ;;
  185. (describe)
  186. _swift_package_describe
  187. ;;
  188. (unedit)
  189. _swift_package_unedit
  190. ;;
  191. (update)
  192. _swift_package_update
  193. ;;
  194. (completion-tool)
  195. _swift_package_completion-tool
  196. ;;
  197. (tools-version)
  198. _swift_package_tools-version
  199. ;;
  200. (reset)
  201. _swift_package_reset
  202. ;;
  203. (resolve)
  204. _swift_package_resolve
  205. ;;
  206. (generate-xcodeproj)
  207. _swift_package_generate-xcodeproj
  208. ;;
  209. (fetch)
  210. _swift_package_fetch
  211. ;;
  212. (show-dependencies)
  213. _swift_package_show-dependencies
  214. ;;
  215. esac
  216. ;;
  217. esac
  218. }
  219. _swift_package_edit() {
  220. arguments=(
  221. ":The name of the package to edit:_swift_dependency"
  222. "--revision[The revision to edit]:The revision to edit: "
  223. "--branch[The branch to create]:The branch to create: "
  224. "--path[Create or use the checkout at this path]:Create or use the checkout at this path:_files"
  225. )
  226. _arguments $arguments && return
  227. }
  228. _swift_package_clean() {
  229. arguments=(
  230. )
  231. _arguments $arguments && return
  232. }
  233. _swift_package_init() {
  234. arguments=(
  235. "--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]'}"
  236. )
  237. _arguments $arguments && return
  238. }
  239. _swift_package_dump-package() {
  240. arguments=(
  241. )
  242. _arguments $arguments && return
  243. }
  244. _swift_package_describe() {
  245. arguments=(
  246. "--type[json|text]: :{_values '' 'text[describe using text format]' 'json[describe using JSON format]'}"
  247. )
  248. _arguments $arguments && return
  249. }
  250. _swift_package_unedit() {
  251. arguments=(
  252. ":The name of the package to unedit:_swift_dependency"
  253. "--force[Unedit the package even if it has uncommited and unpushed changes.]"
  254. )
  255. _arguments $arguments && return
  256. }
  257. _swift_package_update() {
  258. arguments=(
  259. )
  260. _arguments $arguments && return
  261. }
  262. _swift_package_completion-tool() {
  263. arguments=(
  264. ": :{_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]'}"
  265. )
  266. _arguments $arguments && return
  267. }
  268. _swift_package_tools-version() {
  269. arguments=(
  270. "--set[Set tools version of package to the given value]:Set tools version of package to the given value: "
  271. "--set-current[Set tools version of package to the current tools version in use]"
  272. )
  273. _arguments $arguments && return
  274. }
  275. _swift_package_reset() {
  276. arguments=(
  277. )
  278. _arguments $arguments && return
  279. }
  280. _swift_package_resolve() {
  281. arguments=(
  282. ":The name of the package to resolve:_swift_dependency"
  283. "--version[The version to resolve at]:The version to resolve at: "
  284. "--branch[The branch to resolve at]:The branch to resolve at: "
  285. "--revision[The revision to resolve at]:The revision to resolve at: "
  286. )
  287. _arguments $arguments && return
  288. }
  289. _swift_package_generate-xcodeproj() {
  290. arguments=(
  291. "--xcconfig-overrides[Path to xcconfig file]:Path to xcconfig file:_files"
  292. "--enable-code-coverage[Enable code coverage in the generated project]"
  293. "--output[Path where the Xcode project should be generated]:Path where the Xcode project should be generated:_files"
  294. "--legacy-scheme-generator[Use the legacy scheme generator]"
  295. "--watch[Watch for changes to the Package manifest to regenerate the Xcode project]"
  296. )
  297. _arguments $arguments && return
  298. }
  299. _swift_package_fetch() {
  300. arguments=(
  301. )
  302. _arguments $arguments && return
  303. }
  304. _swift_package_show-dependencies() {
  305. arguments=(
  306. "--format[text|dot|json|flatlist]: :{_values '' 'text[list dependencies using text format]' 'dot[list dependencies using dot format]' 'json[list dependencies using JSON format]'}"
  307. )
  308. _arguments $arguments && return
  309. }
  310. # Generates completions for swift test
  311. #
  312. # In the final compdef file, set the following file header:
  313. #
  314. # #compdef _swift_test
  315. # local context state state_descr line
  316. # typeset -A opt_args
  317. _swift_test() {
  318. arguments=(
  319. "-Xcc[Pass flag through to all C compiler invocations]:Pass flag through to all C compiler invocations: "
  320. "-Xswiftc[Pass flag through to all Swift compiler invocations]:Pass flag through to all Swift compiler invocations: "
  321. "-Xlinker[Pass flag through to all linker invocations]:Pass flag through to all linker invocations: "
  322. "-Xcxx[Pass flag through to all C++ compiler invocations]:Pass flag through to all C++ compiler invocations: "
  323. "(--configuration -c)"{--configuration,-c}"[Build with configuration (debug|release) ]: :{_values '' 'debug[build with DEBUG configuration]' 'release[build with RELEASE configuration]'}"
  324. "--build-path[Specify build/cache directory ]:Specify build/cache directory :_files"
  325. "(--chdir -C)"{--chdir,-C}"[]: :_files"
  326. "--package-path[Change working directory before any other operation]:Change working directory before any other operation:_files"
  327. "--sanitize[Turn on runtime checks for erroneous behavior]: :{_values '' 'address[enable Address sanitizer]' 'thread[enable Thread sanitizer]'}"
  328. "--disable-prefetching[]"
  329. "--skip-update[Skip updating dependencies from their remote during a resolution]"
  330. "--disable-sandbox[Disable using the sandbox when executing subprocesses]"
  331. "--version[]"
  332. "--destination[]: :_files"
  333. "(--verbose -v)"{--verbose,-v}"[Increase verbosity of informational output]"
  334. "--no-static-swift-stdlib[Do not link Swift stdlib statically \[default\]]"
  335. "--static-swift-stdlib[Link Swift stdlib statically]"
  336. "--enable-build-manifest-caching[Enable llbuild manifest caching \[Experimental\]]"
  337. "--skip-build[Skip building the test target]"
  338. "(--list-tests -l)"{--list-tests,-l}"[Lists test methods in specifier format]"
  339. "--generate-linuxmain[Generate LinuxMain.swift entries for the package]"
  340. "--parallel[Run the tests in parallel.]"
  341. "(--specifier -s)"{--specifier,-s}"[]: : "
  342. "--xunit-output[]: :_files"
  343. "--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>: "
  344. )
  345. _arguments $arguments && return
  346. }
  347. _swift_compiler() {
  348. }
  349. _swift