Newer
Older
dub_jkp / scripts / zsh-completion / _dub
@WebFreak001 WebFreak001 on 26 May 2023 11 KB support specifying --d-versions
  1. #compdef dub
  2.  
  3. # Useful help:
  4. # https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org
  5. # http://zsh.sourceforge.net/Doc/Release/Completion-System.html
  6. # http://zdharma.org/Zsh-100-Commits-Club/Zsh-Native-Scripting-Handbook.html
  7. #
  8. # Completions installed on your system, e.g. for MacOSX + Homebrew users:
  9. # /usr/local/Cellar/zsh/$VERSION/share/zsh/functions
  10. # The GIT completion is quite amazing (and equally complex)
  11. # The CVS completion is much easier to grok (e.g. for function dispatch)
  12.  
  13.  
  14. # Entry point
  15. _dub() {
  16. # TODO:
  17. # - Handle registry URLs
  18. # - Handle multiple dub (e.g. ./bin/dub add [TAB])
  19. # - Interactively query configuration (for -c and --override-config)
  20. # => Dub does not currently support this
  21. # - Add ability to provide version, e.g. vibe-d@0.8.6 (see dub add)
  22. # - Get registry packages if it doesn't make us lag
  23. # - Query compilers
  24.  
  25. # Note that global arguments won't show up when completing commands
  26. # This is on purpose, to reduce the amount of options being shown during completion,
  27. # as users are much more likely to be looking for command-specific options.
  28. _arguments -S -C \
  29. '(* : -)'{-h,--help}'[Display general or command specific help and exit]' \
  30. '(* : -)--version[Print version information and exit]' \
  31. \
  32. '--root=[Run as if dub was started in given path]: :_directories' \
  33. '--skip-registry=[Skips searching packages on certain repositories]:mode:(none standard configured all)' \
  34. '--registry=[Search the given registry URL first when resolving dependencies]:registry URL:_urls' \
  35. '--bare[Read only packages contained in the current directory]' \
  36. '--cache=[Puts any fetched packages in the specified location]:cache location:(local|system|user)' \
  37. '--annotate[Do not perform any action, just print what would be done]' \
  38. \
  39. + '(verbosity)' \
  40. '--vquiet[Print no messages]' \
  41. '--verror[Only print errors]' \
  42. {-q,--quiet}'[Only print warnings and errors]' \
  43. {-v,--verbose}'[Print diagnostic output]' \
  44. '--vverbose[Print debug output]' \
  45. \
  46. '--[End of dub arguments, the following will be sent to the program]' \
  47. '*::dub command:_command_dispatch'
  48. }
  49.  
  50.  
  51. # Command dispatch function
  52. _command_dispatch() {
  53. declare -a commands=(
  54. init:'Initialize a new dub package'
  55. run:'Build and run a dub package (default action)'
  56. build:'Build a dub package (by name, or in the working directory by default)'
  57. test:'Execute the tests of a dub package'
  58. generate:'Generates project files using the specified generator'
  59. describe:'Prints a JSON description of the project and its dependencies'
  60. clean:'Removes intermediate build files and cached build results'
  61. dustmite:'Create reduced test cases for build errors'
  62.  
  63. fetch:'Manually retrieves and caches a package'
  64. add:'Adds dependencies to the package file'
  65. remove:'Removes a cached package'
  66. upgrade:'Forces an upgrade of the dependencies'
  67. add-path:'Adds a default package search path'
  68. remove-path:'Removes a package search path'
  69. add-local:'Adds a local package directory (e.g. a git repository)'
  70. remove-local:'Removes a local package directory'
  71. list:'Prints a list of all local packages dub is aware of'
  72. search:'Search for available packages'
  73. add-override:'Adds a new package override'
  74. remove-override:'Removes an existing package override'
  75. list-overrides:'Prints a list of all local package overrides'
  76. clean-caches:'Removes cached metadata'
  77. convert:'Converts the file format of the package recipe'
  78. )
  79. if (( CURRENT == 1 )); then
  80. _alternative \
  81. 'files:filename:_files -g "*.d"' \
  82. "commands:dub command: _describe -t commands command commands"
  83. else
  84. integer ret=0
  85. local cmd=${${(k)commands}[(r)$words[1]:*]%%:*}
  86. if [ ! -z "$cmd" ]; then
  87. _call_function ret _dub_$cmd
  88. else
  89. # Assume single file, it takes program arguments
  90. _message "Arguments for single file package $words[1]"
  91. fi
  92. return 0
  93. fi
  94. }
  95.  
  96. (( $+functions[_dub_add] )) ||
  97. _dub_add() {
  98. # TODO: Make dub list more machine-readable
  99. local -a dubList=("${(@f)$(dub list)}")
  100. # First element is 'Packages present in the system...'
  101. # Last element is an empty line
  102. dubList=(${dubList[2,$#dubList-1]})
  103. local -A pkgs
  104. # Collect versions and names
  105. for ((i = 1; i <= ${#dubList}; i++)); do
  106. pkg_name=${${=${dubList[i]}}[1]}
  107. pkg_version=${${${=${dubList[i]}}[2]}%:}
  108. # Subpackages are currently not supported by 'dub add' (see dlang/dub#1846)
  109. if [ ! -z "${pkg_name:#*:*}" ]; then
  110. pkgs[${pkg_name}]+="${pkg_version}, "
  111. fi
  112. done
  113. # Merge versions
  114. local -a packages
  115. for name ver in ${(kv)pkgs}; do
  116. packages+=${name}:"${ver%, }"
  117. done
  118.  
  119. # Package list includes ':' which is used as description
  120. #_values 'local packages' ${pkgs//:/\\:}
  121.  
  122. # Use the unique property to get rid of subpkgs
  123. _describe -t packages package packages
  124. }
  125.  
  126. (( $+functions[_dub_init] )) ||
  127. _dub_init() {
  128. _arguments -S -C \
  129. ':package directory:_directories' \
  130. '*:package dependency:_dub_add' \
  131. '(-t --type)'{-t,--type}'[Set the type of project to generate]:project type:((minimal\:"simple hello world project (default)" vibe.d\:"minimal HTTP server based on vibe.d" deimos\:"skeleton for C header bindings" custom\:"custom project provided by dub package"))' \
  132. '(-f --format)'{-f,--format}'[Sets the format to use for the manifest file]:format:(json sdl)' \
  133. '(-n --non-iteractive)'{-n,--non-iteractive}'[Do not prompt for values and use only defaults]' \
  134. '(* : -)'{-h,--help}'[Display general or command specific help and exit]'
  135. }
  136.  
  137. (( $+functions[_dub_list] )) ||
  138. _dub_list() {
  139. _arguments -S -C \
  140. '(* : -)'{-h,--help}'[Display general or command specific help and exit]'
  141. }
  142.  
  143. # dub generate, dub build, dub run...
  144. (( $+functions[_dub_generate_generic] )) ||
  145. _dub_generate_generic() {
  146. _arguments -S -C \
  147. $@ \
  148. '::package:_dub_add' \
  149. '(* : -)'{-h,--help}'[Display general or command specific help and exit]' \
  150. '(-b --build)'{-b,--build=}'[Specifies the type of build to perform]:build type:("debug (default)" plain release release-debug release-nobounds unittest profile profile-gc docs ddox cov cov-ctfe unittest-cov unittest-cov-ctfe syntax)' \
  151. '(-c --config)'{-c,--config=}'[Builds the specified configuration]:package configuration: ' \
  152. '*--override-config=[ Uses the specified configuration for a certain dependency]:dependency/config: ' \
  153. '--compiler=[Specifies the compiler binary to use (can be a path)]:compiler:(dmd gdc ldc gdmd ldmd)' \
  154. '(-a --arch)'{-a,--arch=}'[Force a different architecture (e.g. x86 or x86_64)]:architecture: ' \
  155. '(-d --debug)*'{-d,--debug=}'[Define the specified debug version identifier when building]:Debug version: ' \
  156. '--d-version=[Define the specified version identifier when building]:Version identifier: ' \
  157. '--nodeps[Do not resolve missing dependencies before building]' \
  158. '--build-mode=[Specifies the way the compiler and linker are invoked]:build mode:("separate (default)" allAtOnce singleFile)' \
  159. '--single[Treats the package name as a filename. The file must contain a package recipe comment]:file:_files -g "*.d"' \
  160. '--filter-versions[Experimental: Filter version identifiers and debug version identifiers to improve build cache efficiency]' \
  161. '--combined[Tries to build the whole project in a single compiler run]' \
  162. '--print-builds[Prints the list of available build types]' \
  163. '--print-configs[Prints the list of available configurations]' \
  164. '--print-platform[Prints the identifiers for the current build platform as used for the manifests build field]' \
  165. '--parallel[Runs multiple compiler instances in parallel, if possible]'
  166. }
  167.  
  168. (( $+functions[_dub_generate] )) ||
  169. _dub_generate() {
  170. local curcontext="$curcontext"
  171. declare -a generators=(
  172. visuald:'VisualD project files',
  173. sublimetext:'SublimeText project file'
  174. cmake:'CMake build scripts'
  175. build:'Builds the package directly (use "dub build" instead)'
  176. )
  177. local localArgs=(
  178. ':generator: _describe -t generators generator generators'
  179. )
  180.  
  181. integer ret=0
  182. _call_function ret _dub_generate_generic ${(@)localArgs}
  183. return ret
  184. }
  185.  
  186. (( $+functions[_dub_build] )) ||
  187. _dub_build() {
  188. local localArgs=(
  189. $@
  190. '--rdmd[Use rdmd instead of directly invoking the compiler]'
  191. '(-f --force)'{-f,--force}'[Forces a recompilation even if the target is up to date]'
  192. '(-y--yes)'{-y,--yes}'[Assume "yes" as answer to all interactive prompts]'
  193. '(-n--non-interactive)'{-n,--non-interactive}'[Do not enter interactive mode]'
  194. )
  195.  
  196. integer ret=0
  197. _call_function ret _dub_generate_generic ${(@)localArgs}
  198. return ret
  199. }
  200.  
  201. (( $+functions[_dub_run] )) ||
  202. _dub_run() {
  203. local localArgs=(
  204. '--[End of dub arguments, the following will be sent to the program]'
  205. '--temp-build[Builds the project in the temp folder if possible]'
  206. )
  207.  
  208. integer ret=0
  209. _call_function ret _dub_build ${(@)localArgs}
  210. return ret
  211. }
  212.  
  213. (( $+functions[_dub_test] )) ||
  214. _dub_test() {
  215. local localArgs=(
  216. '--main-file=[Specifies a custom file containing the main() function to use for running the tests]:main file:_files -g "*.d"'
  217. )
  218.  
  219. integer ret=0
  220. _call_function ret _dub_build ${(@)localArgs}
  221. return ret
  222. }
  223.  
  224. (( $+functions[_dub_describe] )) ||
  225. _dub_describe() {
  226. local localArgs=(
  227. '--import-paths[Shortcut for --data=import-paths --data-list]'
  228. '--string-import-paths[Shortcut for --data=string-import-paths --data-list]'
  229. '--data=[List the values of a particular build setting]:listing options: _values -s , argument main-source-file dflags lflags libs linker-files source-files versions debug-versions import-paths string-import-paths import-files options'
  230. '--data-list[Output --data information in list format (line-by-line)]'
  231. '--data-0[Output --data information using null-delimiters, rather than spaces or newlines]'
  232. )
  233.  
  234. integer ret=0
  235. _call_function ret _dub_build ${(@)localArgs}
  236. return ret
  237. }
  238.  
  239. (( $+functions[_dub_clean] )) ||
  240. _dub_clean() {
  241. _arguments -S -C \
  242. '(* : -)'{-h,--help}'[Display general or command specific help and exit]' \
  243. + '(toclean)' \
  244. '--all-packages[Cleans up *all* known packages (dub list)]' \
  245. ':package:_dub_add'
  246. }
  247.  
  248. (( $+functions[_dub_dustmite] )) ||
  249. _dub_dustmite() {
  250. local localArgs=(
  251. ':target directory:_directories'
  252. '--compiler-status=[The expected status code of the compiler run]:status code: '
  253. '--compiler-regex=[A regular expression used to match against the compiler output]:regex: '
  254. '--linker-status=[The expected status code of the linker run]:status code: '
  255. '--linker-regex=[A regular expression used to match against the linker output]:regex: '
  256. '--program-status=[The expected status code of the built executable]:status code: '
  257. '--program-regex=[A regular expression used to match against the program output]:regex: '
  258. '--[End of dub arguments, the following will be sent to the program]'
  259. )
  260.  
  261. integer ret=0
  262. _call_function ret _dub_generate_generic ${(@)localArgs}
  263. return ret
  264. }
  265.  
  266. _dub