aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorKevin Hughes <kevinhughes27@gmail.com>2016-12-16 11:16:16 -0500
committerKevin Hughes <kevinhughes27@gmail.com>2016-12-16 11:16:16 -0500
commit5578ce4036240a2cbb7e0525ac82df95b4979f93 (patch)
treef2e0b09ce20d97623f4e16b19b82fdb764bd4611 /guides
parent0aae8aec3b6c73b9f1f0dae78b0683038f36bc59 (diff)
downloadrails-5578ce4036240a2cbb7e0525ac82df95b4979f93.tar.gz
rails-5578ce4036240a2cbb7e0525ac82df95b4979f93.tar.bz2
rails-5578ce4036240a2cbb7e0525ac82df95b4979f93.zip
[ci skip] add a section explaining command line arguments for generators
Diffstat (limited to 'guides')
-rw-r--r--guides/source/generators.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/guides/source/generators.md b/guides/source/generators.md
index 32bbdc554a..56edfcc8ae 100644
--- a/guides/source/generators.md
+++ b/guides/source/generators.md
@@ -451,6 +451,26 @@ $ rails new thud -m https://gist.github.com/radar/722911/raw/
Whilst the final section of this guide doesn't cover how to generate the most awesome template known to man, it will take you through the methods available at your disposal so that you can develop it yourself. These same methods are also available for generators.
+Adding Command Line Arguments
+-----------------------------
+Rails generators can be easily modified to accept custom command line arguments. This functionality comes from [Thor](http://www.rubydoc.info/github/erikhuda/thor/master/Thor/Base/ClassMethods#class_option-instance_method):
+
+```
+class_option :scope, type: :string, default: 'read_products'
+```
+
+Now our generator can be invoked as follows:
+
+```bash
+rails generate initializer --scope write_products
+```
+
+The command line arguments are accessed through the `options` method inside the generator class. e.g:
+
+```ruby
+@scope = options['scope']
+```
+
Generator methods
-----------------