Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display a help message if rails new is called without a path #42220

Merged
merged 1 commit into from
May 14, 2021

Conversation

ghiculescu
Copy link
Member

Fixes #42196

Previously calling rails new without an app path displayed an error message that wasn't very friendly.

Not it will display the same usage message that rails and rails help new does.

To test (copied from #39282):

  • Pull this branch
  • Uninstall your local rails copy using gem uninstall rails
  • Move into the root directory where you pulled down the rails code, then install: rake install
  • In another directory run rails new

@@ -92,6 +93,10 @@ def print_commands # :nodoc:
COMMANDS_IN_USAGE = %w(generate console server test test:system dbconsole new)
private_constant :COMMANDS_IN_USAGE

def rails_new_with_no_path?(args, config)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way in thor to have behavior run if a required argument is missing. It just aborts.

So instead I chose to handle this before we even reach the thor layer.

@eileencodes
Copy link
Member

Can you add a test in railties/test/generators/app_generator_test.rb?

Fixes rails#42196

Now, `rails new` will display the same error message that `rails` and `rails help new` does.

To test:

- Pull this branch
- Uninstall your local rails copy using `gem uninstall rails`
- Move into the root directory where you pulled down the rails code, then install: `rake install`
- In another directory run `rails new`
class Rails::Command::ApplicationTest < ActiveSupport::TestCase
test "rails new without path prints help" do
output = capture(:stdout) do
Rails::Command.invoke(:application, %w[new])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileencodes the app_generator_test tests the thor command directly, so I needed to put my test a few layers higher in the stack.

@eileencodes eileencodes merged commit cc37c69 into rails:main May 14, 2021
@ghiculescu ghiculescu deleted the rails-new-no-path-provided branch May 14, 2021 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rails new with no argument isn't very helpful
2 participants