_swift 15 KB

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