Skip to content

Commit

Permalink
print generators on failed generate
Browse files Browse the repository at this point in the history
Let's say we just ran:

```
$ rails g migrate add_click_to_issue_assignment
```

We will get an error that looks like: 

```
Could not find generator migrate.
```

This patch adds all existing migrations to the output to make it easier for a developer to find a valid migration. 

```
Could not find generator "migrate". Please select a valid generator:
Rails:
  assets
  controller
  generator
  helper
  integration_test
  mailer
  migration
  model
  resource
  scaffold
  scaffold_controller
  task
```


It would be nice to do some spelling detection and suggest alternatives, but for now this should  help.
  • Loading branch information
schneems committed May 24, 2014
1 parent f9860fc commit 3915c45
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions railties/lib/rails/generators.rb
Expand Up @@ -156,7 +156,8 @@ def self.invoke(namespace, args=ARGV, config={})
args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? } args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? }
klass.start(args, config) klass.start(args, config)
else else
puts "Could not find generator #{namespace}." puts "Could not find generator #{namespace.inspect}."
print_generators
end end
end end


Expand Down Expand Up @@ -199,17 +200,6 @@ def hide_namespaces(*namespaces)


# Show help message with available generators. # Show help message with available generators.
def self.help(command = 'generate') def self.help(command = 'generate')
lookup!

namespaces = subclasses.map{ |k| k.namespace }
namespaces.sort!

groups = Hash.new { |h,k| h[k] = [] }
namespaces.each do |namespace|
base = namespace.split(':').first
groups[base] << namespace
end

puts "Usage: rails #{command} GENERATOR [args] [options]" puts "Usage: rails #{command} GENERATOR [args] [options]"
puts puts
puts "General options:" puts "General options:"
Expand All @@ -222,6 +212,20 @@ def self.help(command = 'generate')
puts "Please choose a generator below." puts "Please choose a generator below."
puts puts


print_generators
end

def self.print_generators
lookup!

namespaces = subclasses.map{ |k| k.namespace }
namespaces.sort!

groups = Hash.new { |h,k| h[k] = [] }
namespaces.each do |namespace|
base = namespace.split(':').first
groups[base] << namespace
end
# Print Rails defaults first. # Print Rails defaults first.
rails = groups.delete("rails") rails = groups.delete("rails")
rails.map! { |n| n.sub(/^rails:/, '') } rails.map! { |n| n.sub(/^rails:/, '') }
Expand Down

0 comments on commit 3915c45

Please sign in to comment.