1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #42220 from ghiculescu/rails-new-no-path-provided

Display a help message if `rails new` is called without a path
This commit is contained in:
Eileen M. Uchitelle 2021-05-14 14:11:57 -04:00 committed by GitHub
commit cc37c6907c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -38,6 +38,7 @@ module Rails
end
command_name, namespace = "help", "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name)
command_name, namespace, args = "application", "application", ["--help"] if rails_new_with_no_path?(args)
command_name, namespace = "version", "version" if %w( -v --version ).include?(command_name)
original_argv = ARGV.dup
@ -92,6 +93,10 @@ module Rails
COMMANDS_IN_USAGE = %w(generate console server test test:system dbconsole new)
private_constant :COMMANDS_IN_USAGE
def rails_new_with_no_path?(args)
args == ["new"]
end
def commands
lookup!

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
require "abstract_unit"
require "rails/command"
class Rails::Command::ApplicationTest < ActiveSupport::TestCase
test "rails new without path prints help" do
output = capture(:stdout) do
Rails::Command.invoke(:application, %w[new])
end
# Doesn't include the default thor error message:
assert_not output.start_with?("No value provided for required arguments")
# Includes contents of ~/railties/lib/rails/generators/rails/app/USAGE:
assert output.include?("The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.")
end
end