提交 70d12677 编写于 作者: R Rafael Mendonça França

Merge pull request #15294 from schneems/schneems/generator-output-in-error2

print generators on failed generate
......@@ -156,7 +156,8 @@ def self.invoke(namespace, args=ARGV, config={})
args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? }
klass.start(args, config)
else
puts "Could not find generator #{namespace}."
puts "Could not find generator '#{namespace}'. Please choose a generator below."
print_generators
end
end
......@@ -199,17 +200,6 @@ def hide_namespaces(*namespaces)
# Show help message with available generators.
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
puts "General options:"
......@@ -222,6 +212,20 @@ def self.help(command = 'generate')
puts "Please choose a generator below."
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.
rails = groups.delete("rails")
rails.map! { |n| n.sub(/^rails:/, '') }
......
......@@ -21,8 +21,10 @@ def test_simple_invoke
end
def test_invoke_when_generator_is_not_found
output = capture(:stdout){ Rails::Generators.invoke :unknown }
assert_equal "Could not find generator unknown.\n", output
name = :unknown
output = capture(:stdout){ Rails::Generators.invoke name }
assert_match "Could not find generator '#{name}'", output
assert_match "scaffold", output
end
def test_help_when_a_generator_with_required_arguments_is_invoked_without_arguments
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册