-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Show default help when calling help outside a Rails application #41425
Conversation
@@ -1009,7 +1009,7 @@ def test_skip_webpack_install | |||
assert_no_file "config/webpacker.yml" | |||
|
|||
output = Dir.chdir(destination_root) do | |||
`bin/rails help` | |||
`bin/rails -h` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bin/rails help
no longer outputs the extended commands (just the common commands ). So this had to be changed to bin/rails -h
which does output the extended commands.
railties/lib/rails/command.rb
Outdated
if char = namespace =~ /:(\w+)$/ | ||
command_name, namespace = $1, namespace.slice(0, char) | ||
elsif namespace.blank? | ||
command_name, namespace = "help", "help" | ||
elsif HELP_MAPPINGS.include?(namespace) | ||
command_name, namespace = "help_extended", "help" | ||
elsif VERSION_MAPPINGS.include?(namespace) | ||
command_name, namespace = "version", "version" | ||
else | ||
command_name = namespace | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If HELP_MAPPINGS
and VERSION_MAPPINGS
were Set
s or Regexp
s, we could write:
if char = namespace =~ /:(\w+)$/ | |
command_name, namespace = $1, namespace.slice(0, char) | |
elsif namespace.blank? | |
command_name, namespace = "help", "help" | |
elsif HELP_MAPPINGS.include?(namespace) | |
command_name, namespace = "help_extended", "help" | |
elsif VERSION_MAPPINGS.include?(namespace) | |
command_name, namespace = "version", "version" | |
else | |
command_name = namespace | |
end | |
case namespace | |
when /^(.+):(\w+)$/ | |
namespace, command_name = $1, $2 | |
when "" | |
namespace, command_name = "help", "help" | |
when HELP_MAPPINGS | |
namespace, command_name = "help", "help_extended" | |
when VERSION_MAPPINGS | |
namespace, command_name = "version", "version" |
Also, it might be good to factor this out into a method like split_command_name
or split_namespace_and_command_name
which would return a [namespace, command_name]
pair.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that looks very nice. 👍
I've extracted it to a split_namespace
method.
Checking back in on this @p8. Do you need any help getting it across the finish line? |
Hi @olivierlacan, sorry for not getting back to you when this issue was raised. 🙇 I think this PR is good to go but more reviews are welcome 😄 I've rebased the PR to main and I'll add some screenshots for extra clarity. BTW the USAGE file is printed on the following line:
The definition of desc is here:rails/railties/lib/rails/command/base.rb Line 31 in 94b9545
|
Comparing to 6.1.3. 6.1.3.2Outside of a Rails app directory:
Inside of a Rails app directory:
This PROutside of a Rails app directory:
Inside of a rails app directory:
I think this makes a lot of sense. But you know what I realized? The order of the "most common Rails command" makes no sense. Why would Anyway, to me this is a great improvement already. 👍 |
@p8 You need another rebase but aside from that @jonathanhefner do you think this looks good? |
Thanks for the review @olivierlacan ! I've rebased against main. |
@olivierlacan I agree that outside an app folder, |
When running `rails -h` or just `rails` outside a Rails application, Rails outputs all options for running the `rails new` command. This can be confusing to users when they probably want to see the common Rails commands. Instead, we should always show the common commands when running `rails -h` inside or outside a Rails application. With this change help works as follows... Outside a Rails application we never show the extended commands: db:migrate, etc... The extended commands require a Rails application. They also take up a lot screen space. - `rails` outputs the help for the common commands - `rails -h` outputs the help for the common commands. - `rails new -h` outputs the help for the new command. Inside a Rails application it works mostly as before. The only change is that calling plain `bin/rails` now only outputs the common commands and not the extended commands. - `bin/rails` outputs the help for the common commands - `bin/rails -h` outputs the help for the common commands and the extended commands
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. |
Summary
When running
rails -h
or justrails
outside a Rails application,Rails outputs all options for running the
rails new
command. This can beconfusing to users when they probably want to see the common Rails commands.
Instead, we should always show the common commands when running
rails -h
inside or outside a Rails application.
With this change help works as follows...
Outside a Rails application we always show the default help when calling
rails
without a command like
new
.We never show the extended commands: db:migrate, etc...
The extended commands require a Rails application.
They also take up a lot screen space.
rails
outputs the help for the common commandsrails -h
outputs the help for the common commands.rails new -h
outputs the help for the new command.Inside a Rails application it works mostly as before. The only change is
that calling plain
bin/rails
now only outputs the common commands andnot the extended commands.
bin/rails
outputs the help for the common commandsbin/rails -h
outputs the help for the common commands and theextended commands
This is a work in progress for #40823
cc @olivierlacan