aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-12-16 13:04:02 -0500
committerGitHub <noreply@github.com>2016-12-16 13:04:02 -0500
commite55fac51d93fc832281a5c34f99a72304822bdd3 (patch)
tree1a707b9bf06d495a1f5a21feb03e23437ff1f82c
parentf98d487f1b736f24cd2348220f3b5f20e1b90a8c (diff)
parent5578ce4036240a2cbb7e0525ac82df95b4979f93 (diff)
downloadrails-e55fac51d93fc832281a5c34f99a72304822bdd3.tar.gz
rails-e55fac51d93fc832281a5c34f99a72304822bdd3.tar.bz2
rails-e55fac51d93fc832281a5c34f99a72304822bdd3.zip
Merge pull request #27386 from kevinhughes27/add-generator-command-line-arg-docs
Docs Command Line Arguments for Generators
-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
-----------------