_rails 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. #compdef rails
  2. # ------------------------------------------------------------------------------
  3. # Copyright (c) 2016 GitHub zsh-users - https://github.com/zsh-users
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are met:
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. # * Neither the name of the zsh-users nor the
  14. # names of its contributors may be used to endorse or promote products
  15. # derived from this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
  21. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. # ------------------------------------------------------------------------------
  28. # Description
  29. # -----------
  30. #
  31. # Completion script for Ruby on Rails 7.1.0 (https://rubyonrails.org/).
  32. #
  33. # ------------------------------------------------------------------------------
  34. # Authors
  35. # -------
  36. #
  37. # * Kazuya Takeshima (https://github.com/mitukiii)
  38. # * Shohei Yoshida (https://github.com/syohex)
  39. #
  40. # ------------------------------------------------------------------------------
  41. _rails() {
  42. local context state state_descr line curcontext="$curcontext"
  43. typeset -A opt_args
  44. local -a runtime_options rails_options
  45. runtime_options=(
  46. '(- *)'{-h,--help}'[Show this help message and quit]'
  47. '(- *)'{-v,--version}'[Show Rails version and quit]'
  48. )
  49. runtime_options=(
  50. '(-f --force)'{-f,--force}'[Overwrite files that already exist]'
  51. '(-p --pretend)'{-p,--pretend}'[Run but do not make any changes]'
  52. '(-q --quiet)'{-q,--quiet}'[Suppress status output]'
  53. '(-s --skip)'{-s,--skip}'[Skip files that already exist]'
  54. )
  55. local ret=1
  56. _arguments -C \
  57. $rails_options \
  58. '1: :_rails_subcommands' \
  59. '*:: :->command' && ret=0
  60. case "$state" in
  61. (command)
  62. case $words[1] in
  63. (new)
  64. _rails_new && ret=0
  65. ;;
  66. (generate|g|destroy|d)
  67. _rails_generate && ret=0
  68. ;;
  69. (console|c)
  70. _arguments \
  71. '(- *)'{-h,--help}'[Show this help message and quit]' \
  72. '(-e --environment)'{-e,--environment=}'[The environment to run "console" in]:env:(test development production)' \
  73. '(-s --sandbox)'{-s,--sandbox}'[Rollback database modifications on exit]' \
  74. && ret=0
  75. ;;
  76. (server|s)
  77. _arguments \
  78. '(- *)'{-h,--help}'[Show this help message and quit]' \
  79. '(-e --environment)'{-e,--environment=}'[The environment to run "server" in]:env:(test development production)' \
  80. '(-p --port)'{-p,--port}'[Run Rails on the specified port]:port' \
  81. '(-b --binding)'{-b,--binding=}'[Bind Rails to the specified IP]:binding' \
  82. '(-c --config)'{-c,--config=}'[Use a custom rackup configuration]:config file:_files -g "*.ru"' \
  83. '(-d --daemon)'{-d,--daemon}'[Run server as a Daemon]' \
  84. '(-u --using)'{-u,--using=}'[Specify the Rack server used to run the application]:server:(thin puma webrick)' \
  85. '(-P --pid)'{-P,--pid=}'[Specify the PID file]:pid file:_files -g "*.pid"' \
  86. '(-C --dev-caching --no-dev-caching)'{-C,--dev-caching}'[Perform caching in development]' \
  87. '(-C --dev-caching --no-dev-caching)--no-dev-caching[Not perform caching in development]' \
  88. '--early-hints[Enable HTTP/2 early hints]' \
  89. '(--log-to-stdout --no-log-to-stdout)--log-to-stdout[Log to stdout]' \
  90. '(--log-to-stdout --no-log-to-stdout)--no-log-to-stdout[Not log to stdout]' \
  91. && ret=0
  92. ;;
  93. (dbconsole|db)
  94. _arguments \
  95. '(- *)'{-h,--help}'[Show this help message and quit]' \
  96. '(-e --environment)'{-e,--environment=}'[The environment to run "server" in]:env:(test development production)' \
  97. '(-p --include-password)'{-p,--include-password}'[Automatically provide the password from database.yml]' \
  98. '--mode=[Automatically put the sqlite3 database in the specified mode]:mode:(html list line column)' \
  99. '(--header --no-header)--header[Display header]' \
  100. '(--header --no-header)--no-header[Not display header]' \
  101. '(--db --database)'{--db=,--database=}'[Specify the database to use]:database:_files' \
  102. && ret=0
  103. ;;
  104. (test|t|test:system)
  105. _arguments \
  106. '(- *)'{-h,--help}'[Show this help message and quit]' \
  107. '--no-plugins[Bypass minitest plugin auto-loading]' \
  108. '(-s --seed)'{-s,--seed=}'[Sets random seed]:seed' \
  109. '(-v -verbose)'{-v,--verbose}'[Show progress processing files]' \
  110. '--show-skips[Show skipped at the end of run]' \
  111. \*{-n,--name=}'[Filter run on /regexp/ or string]:pattern' \
  112. *--exclude='[Exclude /regexp/ or string from run]:pattern' \
  113. \*{-S,--skip=}'[Skip reporting of certain types of results]' \
  114. '(-w --warnings)'{-w,--warnings}'[Run with Ruby warnings enabled]' \
  115. '(-e --environment)'{-e,--environment=}'[Run tests in the given environment]' \
  116. '(-b --backtrace)'{-b,--backtrace}'[Show the complete backtrace]' \
  117. '(-d --defer-output)'{-d,--defer-output}'[Output test failures and errors after the test run]' \
  118. '(-f --fail-fast)'{-f,--fail-fast}'[Abort test run on first failure or error]' \
  119. '(-c --color --no-color)'{-c,--color}'[Enable color in the output]' \
  120. '(-c --color --no-color)--no-color[Disable color in the output]' \
  121. '--profile=[Enable profiling of tests and list the slowest test cases]:count' \
  122. '(-p --pride)'{-p,--pride}'[Show your testing pride]' \
  123. '*:: :_files -g "*.rb"' \
  124. && ret=0
  125. ;;
  126. (runner|r)
  127. _arguments \
  128. '(- *)'{-h,--help}'[Show this help message and quit]' \
  129. '(-e --environment)'{-e,--environment=}'[The environment to run "runner"]:env:(test development production)' \
  130. '*:: :_files -g "*.rb"' \
  131. && ret=0
  132. ;;
  133. (plugin)
  134. _arguments \
  135. '1: :(new)' \
  136. '*:: :_rails_new' \
  137. && ret=0
  138. ;;
  139. (routes)
  140. _arguments \
  141. '(- *)'{-h,--help}'[Show this help message and quit]' \
  142. '(-c --controller)'{-c,--controller=}'[Filter by a specific controller]:controller' \
  143. '(-g --grep)'{-g,--grep}'[Grep routes by a specific pattern]' \
  144. '(-E --expanded)'{-E,--expanded}'[Print routes expanded vertically with parts explained]' \
  145. '(-u --unused)'{-u,--unused}'[Print unused routes]' \
  146. && ret=0
  147. ;;
  148. (*)
  149. _arguments \
  150. '(- *)'{-h,--help}'[Show help message and quit]' \
  151. '*:: :_files' \
  152. && ret=0
  153. ;;
  154. esac
  155. ;;
  156. esac
  157. return ret
  158. }
  159. (( $+functions[_rails_subcommands] )) ||
  160. _rails_subcommands() {
  161. local -a commands
  162. _rails_is_in_app
  163. if (( $? == 1 )); then
  164. # is not in rails app directory
  165. commands=(
  166. new'[Create a new Rails application]'
  167. )
  168. else
  169. commands=(
  170. {generate,g}'[Generate new code]'
  171. {console,c}'[Start the Rails console]'
  172. {server,s}'[Start the Rails server]'
  173. {test,t}'[Run tests]'
  174. "test\\:system[Run systems test only]"
  175. {dbconsole,db}'[Start a console for the database specified in config/database.yml]'
  176. plugin'[Install a plugin]'
  177. # generated by ./bin/rails --help | ruby -ne '(b=$2;printf("%s[%s]\n", $1.gsub(/:/,"\\:"),b.strip)) if /^([a-z0-9_:]+)\S*\s+([^(\n]+)/'
  178. "about[List versions of all Rails frameworks and the environment]"
  179. "action_mailbox\:ingress\:exim[Relay an inbound email from Exim to Action Mailbox]"
  180. "action_mailbox\:ingress\:postfix[Relay an inbound email from Postfix to Action Mailbox]"
  181. "action_mailbox\:ingress\:qmail[Relay an inbound email from Qmail to Action Mailbox]"
  182. "action_mailbox\:install[Install Action Mailbox and its dependencies]"
  183. "action_mailbox\:install\:migrations[Copy migrations from action_mailbox to application]"
  184. "action_text\:install[Copy over the migration, stylesheet, and JavaScript files]"
  185. "action_text\:install\:migrations[Copy migrations from action_text to application]"
  186. "active_storage\:install[Copy over the migration needed to the application]"
  187. "app\:template[Apply the template supplied by LOCATION=]"
  188. "app\:update[Update configs and some other initially generated files]"
  189. "assets\:clean[Remove old compiled assets]"
  190. "assets\:clobber[Remove compiled assets]"
  191. "assets\:environment[Load asset compile environment]"
  192. "assets\:precompile[Compile all the assets named in config.assets.precompile]"
  193. "cache_digests\:dependencies[Lookup first-level dependencies for TEMPLATE]"
  194. "cache_digests\:nested_dependencies[Lookup nested dependencies for TEMPLATE]"
  195. "credentials\:diff[Enroll/disenroll in decrypted diffs of credentials using git]"
  196. "credentials\:edit[Open the decrypted credentials in $VISUAL or $EDITOR for editing]"
  197. "credentials\:show[Show the decrypted credentials]"
  198. "db\:create[Create the database from DATABASE_URL or config/database.yml for the current RAILS_ENV]"
  199. "db\:drop[Drop the database from DATABASE_URL or config/database.yml for the current RAILS_ENV]"
  200. "db\:encryption\:init[Generate a set of keys for configuring Active Record encryption in a given environment]"
  201. "db\:environment\:set[Set the environment value for the database]"
  202. "db\:fixtures\:load[Load fixtures into the current environment's database]"
  203. "db\:migrate[Migrate the database]"
  204. "db\:migrate\:down[Run the 'down' for a given migration VERSION]"
  205. "db\:migrate\:redo[Roll back the database one migration and re-migrate up]"
  206. "db\:migrate\:status[Display status of migrations]"
  207. "db\:migrate\:up[Run the 'up' for a given migration VERSION]"
  208. "db\:prepare[Run setup if database does not exist, or run migrations if it does]"
  209. "db\:reset[Drop and recreate all databases from their schema for the current environment and load the seeds]"
  210. "db\:rollback[Roll the schema back to the previous version]"
  211. "db\:schema\:cache\:clear[Clear a db/schema_cache.yml file]"
  212. "db\:schema\:cache\:dump[Create a db/schema_cache.yml file]"
  213. "db\:schema\:dump[Create a database schema file]"
  214. "db\:schema\:load[Load a database schema file]"
  215. "db\:seed[Load the seed data from db/seeds.rb]"
  216. "db\:seed\:replant[Truncate tables of each database for current environment and load the seeds]"
  217. "db\:setup[Create all databases, load all schemas, and initialize with the seed data]"
  218. "db\:system\:change[Change 'config/database.yml' and your database gem to the target database]"
  219. "db\:version[Retrieve the current schema version number]"
  220. "destroy[Remove code generated by 'bin/rails generate']"
  221. "dev\:cache[Toggle development mode caching on/off]"
  222. "encrypted\:edit[Open the decrypted file in $VISUAL or $EDITOR for editing]"
  223. "encrypted\:show[Show the decrypted contents of the file]"
  224. "importmap\:install[Setup Importmap for the app]"
  225. "initializers[Print out all defined initializers in the order they are invoked by Rails.]"
  226. "log\:clear[Truncate all/specified *.log files in log/ to zero bytes]"
  227. "middleware[Print out your Rack middleware stack]"
  228. "notes[Show comments in your code annotated with FIXME, OPTIMIZE, and TODO]"
  229. "restart[Restart app by touching tmp/restart.txt]"
  230. "routes[List all the defined routes]"
  231. "runner[Run Ruby code in the context of your application]"
  232. "secret[Generate a cryptographically secure secret key]"
  233. "secrets\:edit[**deprecated** Open the secrets in $VISUAL or $EDITOR for editing]"
  234. "secrets\:show[**deprecated** Show the decrypted secrets]"
  235. "stats[Report code statistics]"
  236. "stimulus\:install[Install Stimulus into the app]"
  237. "stimulus\:install\:importmap[Install Stimulus on an app running importmap-rails]"
  238. "stimulus\:install\:node[Install Stimulus on an app running node]"
  239. "test\:all[Run all tests, including system tests]"
  240. "test\:channels[Run tests in test/channels]"
  241. "test\:controllers[Run tests in test/controllers]"
  242. "test\:db[Reset the database and run 'bin/rails test']"
  243. "test\:functionals[Run tests in test/controllers, test/mailers, and test/functional]"
  244. "test\:generators[Run tests in test/lib/generators]"
  245. "test\:helpers[Run tests in test/helpers]"
  246. "test\:integration[Run tests in test/integration]"
  247. "test\:jobs[Run tests in test/jobs]"
  248. "test\:mailboxes[Run tests in test/mailboxes]"
  249. "test\:mailers[Run tests in test/mailers]"
  250. "test\:models[Run tests in test/models]"
  251. "test\:units[Run tests in test/models, test/helpers, and test/unit]"
  252. "time\:zones[List all time zones, list by two-letter country code]"
  253. "tmp\:clear[Clear cache, socket and screenshot files from tmp/]"
  254. "tmp\:create[Create tmp directories for cache, sockets, and pids]"
  255. "turbo\:install[Install Turbo into the app]"
  256. "turbo\:install\:importmap[Install Turbo into the app with asset pipeline]"
  257. "turbo\:install\:node[Install Turbo into the app with webpacker]"
  258. "turbo\:install\:redis[Switch on Redis and use it in development]"
  259. "version[Show the Rails version]"
  260. "yarn\:install[Install all JavaScript dependencies as specified via Yarn]"
  261. "zeitwerk\:check[Check project structure for Zeitwerk compatibility]"
  262. )
  263. fi
  264. _values 'command' $commands
  265. }
  266. # rails new
  267. (( $+functions[_rails_new] )) ||
  268. _rails_new() {
  269. local ret=1
  270. _arguments \
  271. $runtime_options \
  272. $rails_options \
  273. --skip-namespace'[Skip namespace]' \
  274. '(-n --name)'{-n,--name=}'[Name of the app]:name' \
  275. '(-r --ruby)'{-r,--ruby=}'[Path to the Ruby binary of your choice]:path:_files' \
  276. '(-b --builder)'{-b,--builder=}'[Path to a application builder(can be a filesystem path or URL)]: :_rails_path_or_url' \
  277. '(-m --template)'{-m,--template=}'[Path to an application template(can be a filesystem path or URL)]: :_rails_path_or_url' \
  278. '(-d --database)'{-d,--database=}'[Preconfigure for selected database]:database:(mysql trilogy oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc)' \
  279. --skip-gemfile"[Don't create a Gemfile]" \
  280. --skip-bundle"[Don't run bundle install]" \
  281. '(-G --skip-git)'{-G,--skip-git}'[Skip git init]' \
  282. --skip-docker'[Skip Dockerfile]' \
  283. --skip-keeps'[Skip source control .keep files]' \
  284. '(-M --skip-action-mailer)'{-M,--skip-action-mailer}'[Skip Action Mailer files]' \
  285. --skip-action-mailbox'[Skip Action Mailbox gem]' \
  286. --skip-action-text'[Skip Action Text gem]' \
  287. '(-O --skip-active-record)'{-O,--skip-active-record}'[Skip Active Record files]' \
  288. --skip-active-job'[Skip Active Job]' \
  289. --skip-active-storage'[Skip Active Storage files]' \
  290. '(-C --skip-action-cable)'{-C,--skip-action-cable}'[Skip Action Cable files]' \
  291. '(-A --skip-asset-pipeline)'{-A,--skip-asset-pipeline}'[Skip asset pipeline]' \
  292. '(-a --asset-pipeline)'{-a,--asset-pipeline=}'[Choose your asset pipeline]:asset pipeline:(sprockets propshaft)' \
  293. '(-J --skip-js)'{-J,--skip-js}'[Skip JavaScript files]' \
  294. --skip-hotwire'[Skip Hotwire integration]' \
  295. --skip-jbuilder'[Skip jbuilder gem]' \
  296. '(-T --skip-test)'{-T,--skip-test}'[Skip test files]' \
  297. --skip-system-test'[Skip system test files]' \
  298. --skip-bootsnap'[Skip bootsnap gem]' \
  299. --skip-dev-gems'[Skip development gems(e.g. web-console)]' \
  300. --dev'[Setup the application with Gemfile pointing to your Rails checkout]' \
  301. --edge'[Setup the application with Gemfile pointing to Rails repository]' \
  302. --master'[Set up the application with Gemfile pointing to Rails repository main branch]' \
  303. --rc='[Path to file containing extra configuration options for rails command]:rc:_files' \
  304. --api'[Preconfigure smaller stack for API only apps]' \
  305. --minimal'[Preconfigure a minimal rails app]' \
  306. '(-j --js)'{-j,--js=}'[Choose JavaScript approach]:javascript:(importmap bun webpack esbuild rollup)' \
  307. '(-c --css)'{-c,--css=}'[Choose CSS processor]:css processor:(tailwind bootstrap bulma postcss sass)' \
  308. '(-B --skip-bundle)'{-B,--skip-bundle}"[Don't run bundle install]" \
  309. --skip-decrypted-diffs"[Don't configure git to show decrypted diffs of encrypted credentials]" \
  310. ':app path:_directories' && ret=0
  311. return ret
  312. }
  313. # rails generate
  314. (( $+functions[_rails_generate] )) ||
  315. _rails_generate() {
  316. local ret=1
  317. _arguments -C \
  318. '(- *)'{-h,--help}"[Print generator's options and usage]" \
  319. $runtime_options \
  320. '1:generator:_rails_generate_generator' \
  321. '*:: :->generate' && ret=0
  322. case "$state" in
  323. (generate)
  324. local -a opts
  325. opts=(
  326. '(- *)'{-h,--help}'[Show this help message and quit]'
  327. $runtime_options
  328. '--skip-namespace[Skip namespace]'
  329. '--skip-collision-check[Skip collision check]'
  330. )
  331. case $words[1] in
  332. (application_record|migration|model|resource|scaffold|scaffold_controller)
  333. opts+=(
  334. '(-o --orm)'{-o,--orm=}'[ORM to be invoked]:orm:(active_record)'
  335. )
  336. ;|
  337. (channel)
  338. opts+=(
  339. '--no-assets[Not generate assets]'
  340. )
  341. ;|
  342. (controller|resource|scaffold|scaffold_controller)
  343. opts+=(
  344. '--skip-routes[Do not add routes to config/routes.rb]'
  345. '--no-helper[Not generate helper]'
  346. )
  347. ;|
  348. (controller|job|model|resource|scaffold)
  349. opts+=(
  350. '--parent=[The parent class for the generated controller]:parent class'
  351. )
  352. ;|
  353. (controller|mailer|resource|scaffold|scaffold_controller)
  354. opts+=(
  355. '(-e --template-engine)'{-e,--template-engine=}'[Template engine to be invoked]:engine:(erb)'
  356. )
  357. ;|
  358. (channel|controller|generator|helper|job|mailbox|mailer|model|scaffold|scaffold_controller)
  359. opts+=(
  360. '(-t --test-framework)'{-t,--test-framework=}'[Test framework to be invoked]:test_framework:(test_unit)'
  361. )
  362. ;|
  363. (generator|test_unit:channel)
  364. opts+=(
  365. '--no-namespace[Not generate namespace generate]'
  366. )
  367. ;|
  368. (integration_test)
  369. opts+=(
  370. '--integration-tool=[Integration tool to be invoked]:tool:(test_unit)'
  371. )
  372. ;|
  373. (jbuilder|resource|scaffold|scaffold_controller)
  374. opts+=(
  375. '--model-name=[ModelName to be used]:name'
  376. )
  377. ;|
  378. (jbuilder|model|resource|scaffold|scaffold_controller)
  379. opts+=(
  380. '--force-plural[Do not singularize the model name]'
  381. )
  382. ;|
  383. (jbuilder|migration|model|resource|scaffold_controller)
  384. opts+=(
  385. '--no-timestamps[Not generate timestamps]'
  386. )
  387. ;|
  388. (job)
  389. opts+=(
  390. '--queue=[The queue name for the generated job]:name'
  391. )
  392. ;|
  393. (migration|model|resource|scaffold)
  394. opts+=(
  395. '--primary-key-type=[The type for primary key]'
  396. '(--db --database)'{--db,--database=}'[The database for your migration]:db'
  397. )
  398. ;|
  399. (model|resource|scaffold)
  400. opts+=(
  401. '--no-migration[Not generate migration]'
  402. '--no-indexes[Not add indexes for references and belongs_to columns]'
  403. '--no-fixture[Not generate fixture]'
  404. '(-r --fixture-replacement)'{-r,--fixture-replacement=}'[Fixture replacement to be invoked]:fixture'
  405. )
  406. ;|
  407. (resource)
  408. opts+=(
  409. '(-c --resource-controller)'{-c,--resource-controller=}'[Resource controller to be invoked]:controller:(controller)'
  410. '(-a --actions)'{-a,--actions=}'[Actions for the source controller]:action'
  411. )
  412. ;|
  413. (resource|scaffold|scaffold_controller)
  414. opts+=(
  415. '--no-resource-route[Not generate resource route]'
  416. )
  417. ;|
  418. (scaffold)
  419. opts+=(
  420. '(-c --scaffold-controller)'{-c,--scaffold-controller=}'[Scaffold controller to be invoked]:controller:(scaffold_controller)'
  421. )
  422. ;|
  423. (scaffold|scaffold_controller)
  424. opts+=(
  425. '--api[Generate API-only controller and tests, with no view templates]'
  426. '--no-jbuilder[Not generate jbuilder]'
  427. )
  428. ;|
  429. (scaffold|scaffold_controller|system_test)
  430. opts+=(
  431. '--system-tests=[System test framework to be invoked]:framework:(test_unit)'
  432. )
  433. ;|
  434. (stimulus)
  435. opts+=(
  436. '--skip-manifest[Do not update the stimulus manifest]'
  437. )
  438. ;|
  439. (jbuilder|migration|resource|scaffold)
  440. opts+=(
  441. '*:field:_rails_migration_fields'
  442. )
  443. ;|
  444. esac
  445. _arguments $opts && ret=0
  446. ;;
  447. esac
  448. return ret
  449. }
  450. (( $+functions[_rails_generate_generator] )) ||
  451. _rails_generate_generator() {
  452. local -a generators=(
  453. # rails
  454. application_record benchmark channel controller generator helper integration_test
  455. jbuilder job mailbox mailer migration model resource scaffold scaffold_controller
  456. system_test task
  457. # active record
  458. "active_record\\:application_record"
  459. "active_record\\:multi_db"
  460. # Stimulus
  461. stimulus
  462. # TestUnit
  463. "test_unit\\:channel" "test_unit\\:generator" "test_unit\\:install"
  464. "test_unit\\:mailbox" "test_unit\\:plugin"
  465. )
  466. _values 'generators' $generators
  467. }
  468. # Utilities
  469. (( $+functions[_rails_is_in_app] )) ||
  470. _rails_is_in_app() {
  471. local dir="$PWD"
  472. while [ -n "$dir" ]; do
  473. if [[ -f "${dir}/bin/rails" ]]; then
  474. return 0
  475. fi
  476. dir="${dir/*}"
  477. done
  478. return 1
  479. }
  480. (( $+functions[_rails_path_or_url] )) ||
  481. _rails_path_or_url() {
  482. _alternative \
  483. 'files:path:_files -g "*.rb"' \
  484. 'url:url:_urls'
  485. }
  486. (( $+functions[_rails_migration_fields] )) ||
  487. _rails_migration_fields() {
  488. if compset -P '*:*:'; then
  489. _values 'index' 'index' 'uniq'
  490. else
  491. if compset -P '*:'; then
  492. _values -s ':' 'type' 'string' 'text' 'integer' 'float' 'decimal' 'datetime' 'timestamp' 'time' 'date' 'binary' 'boolean' 'references'
  493. else
  494. _guard '[[:alnum:]_]#' 'field'
  495. fi
  496. fi
  497. }
  498. _rails "$@"
  499. # Local Variables:
  500. # mode: Shell-Script
  501. # sh-indentation: 2
  502. # indent-tabs-mode: nil
  503. # sh-basic-offset: 2
  504. # End:
  505. # vim: ft=zsh sw=2 ts=2 et