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

Exit with error when rails is called with invalid arguments from wrong directory #42608

Closed

Conversation

endenis
Copy link

@endenis endenis commented Jun 25, 2021

Summary

This PR fixes the problem I had with rails command-line tool: rails exits with zero code if launched with invalid parameters in command-line outside of project directory #42607

I simply added exit(1) for situations when there is an argument that is replaced by --help.

@rails-bot rails-bot bot added the railties label Jun 25, 2021
@zzak
Copy link
Member

zzak commented Jun 25, 2021

Could you add a test?

@p8
Copy link
Member

p8 commented Jun 26, 2021

I think we should check for this earlier in these conditionals.
https://github.com/rails/rails/blob/main/railties/lib/rails/cli.rb#L14-L19
There we can decide which commands are allowed outside of the project directory.

@p8
Copy link
Member

p8 commented Jun 26, 2021

This is also somewhat related to: #41425

@endenis endenis force-pushed the exit-with-error-from-wrong-directory branch 2 times, most recently from 0864925 to c87acd4 Compare June 27, 2021 05:20
@endenis
Copy link
Author

endenis commented Jun 27, 2021

@zzak thank you for your comment. I added a test.

@endenis
Copy link
Author

endenis commented Jun 27, 2021

@p8 interesting point, thank you 🙂

I expanded the logic from cli.rb to handle invalid arguments and moved it to a method of the Command class.

I also moved the logic of --version out of the ARGVScrubber class because in my opinion rendering version information should not be responsibility of that class.

@endenis endenis force-pushed the exit-with-error-from-wrong-directory branch from c87acd4 to a144011 Compare June 30, 2021 00:36
@endenis endenis force-pushed the exit-with-error-from-wrong-directory branch from a144011 to 299f4b5 Compare June 30, 2021 01:02
@rails-bot
Copy link

rails-bot bot commented Sep 28, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Sep 28, 2021
@rails-bot rails-bot bot closed this Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rails exits with zero code if launched with invalid parameters in command-line outside of project directory
3 participants