提交 fb173b66 编写于 作者: Y yuuji.yaginuma

Do not show suggestion message when not exist suggestion

**before**

```
$ ./bin/rails g g
Could not find generator 'g'. Maybe you meant nil?
Run `rails generate --help` for more options.
```

**after**

```
$ ./bin/rails g g
Could not find generator 'g'.
Run `rails generate --help` for more options.
```
上级 a4fe5c5b
......@@ -302,9 +302,10 @@ def rack_server_suggestion(server)
MSG
else
suggestion = Rails::Command::Spellchecker.suggest(server, from: RACK_SERVERS)
suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
<<~MSG
Could not find server "#{server}". Maybe you meant #{suggestion.inspect}?
Could not find server "#{server}". #{suggestion_msg}
Run `rails server --help` for more options.
MSG
end
......
......@@ -272,8 +272,10 @@ def invoke(namespace, args = ARGV, config = {})
else
options = sorted_groups.flat_map(&:last)
suggestion = Rails::Command::Spellchecker.suggest(namespace.to_s, from: options)
suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
puts <<~MSG
Could not find generator '#{namespace}'. Maybe you meant #{suggestion.inspect}?
Could not find generator '#{namespace}'. #{suggestion_msg}
Run `rails generate --help` for more options.
MSG
end
......
......@@ -32,6 +32,12 @@ def test_using_server_mistype
assert_match(/Could not find server "tin". Maybe you meant "thin"?/, run_command("--using", "tin"))
end
def test_using_server_mistype_without_suggestion
output = run_command("--using", "t")
assert_match(/Could not find server "t"/, output)
assert_no_match(/Maybe you meant/, output)
end
def test_using_positional_argument_deprecation
assert_match(/DEPRECATION WARNING/, run_command("tin"))
end
......
......@@ -28,6 +28,7 @@ def test_invoke_when_generator_is_not_found
output = capture(:stdout) { Rails::Generators.invoke name }
assert_match "Could not find generator '#{name}'", output
assert_match "`rails generate --help`", output
assert_no_match "Maybe you meant", output
end
def test_generator_suggestions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册