Skip to content

Commit 768a2c6

Browse files
authored
Merge pull request rails#46163 from p8/rails-help-with-command-descriptions
Add missing descriptions for additional commands in Rails help
2 parents 9a5c17b + f52b1cc commit 768a2c6

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

railties/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Show descriptions for all commands in Rails help
2+
3+
When calling `rails help` most commands missed their description. We now
4+
show the same descriptions as shown in `rails -T`.
5+
6+
*Petrik de Heus*
7+
18
* Always generate the storage/ directory with rails new to ensure there's a stable place to
29
put permanent files, and a single mount point for containers to map. Then default sqlite3 databases
310
to live there instead of db/, which is only meant for configuration, not data.

railties/lib/rails/command.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ def root
8686
end
8787
end
8888

89-
def print_commands # :nodoc:
90-
commands.each { |command| puts(" #{command}") }
89+
def printing_commands # :nodoc:
90+
lookup!
91+
92+
(subclasses - hidden_commands).flat_map(&:printing_commands)
9193
end
9294

9395
private

railties/lib/rails/command/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def perform(command, args, config) # :nodoc:
9292
end
9393

9494
def printing_commands
95-
namespaced_commands
95+
namespaced_commands.map { |command| [command, ""] }
9696
end
9797

9898
def executable(subcommand = nil)

railties/lib/rails/commands/help/help_command.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@ class HelpCommand < Base # :nodoc:
88
def help(*)
99
say self.class.desc
1010

11-
Rails::Command.print_commands
11+
other_commands = printing_commands_not_in_usage.sort_by(&:first)
12+
print_table(other_commands, indent: 1, truncate: true)
1213
end
14+
15+
private
16+
COMMANDS_IN_USAGE = %w(generate console server test test:system dbconsole new)
17+
private_constant :COMMANDS_IN_USAGE
18+
19+
def printing_commands_not_in_usage # :nodoc:
20+
Rails::Command.printing_commands.reject do |command, _|
21+
command.in?(COMMANDS_IN_USAGE)
22+
end
23+
end
1324
end
1425
end
1526
end

railties/lib/rails/commands/rake/rake_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class RakeCommand < Base # :nodoc:
99

1010
class << self
1111
def printing_commands
12-
formatted_rake_tasks.map(&:first)
12+
formatted_rake_tasks
1313
end
1414

1515
def perform(task, args, config)

railties/test/command/base_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
class Rails::Command::BaseTest < ActiveSupport::TestCase
1010
test "printing commands" do
11-
assert_equal %w(generate), Rails::Command::GenerateCommand.printing_commands
12-
assert_equal %w(secrets:setup secrets:edit secrets:show), Rails::Command::SecretsCommand.printing_commands
13-
assert_equal %w(db:system:change), Rails::Command::Db::System::ChangeCommand.printing_commands
11+
assert_equal [["generate", ""]], Rails::Command::GenerateCommand.printing_commands
12+
assert_equal [["secrets:setup", ""], ["secrets:edit", ""], ["secrets:show", ""]], Rails::Command::SecretsCommand.printing_commands
13+
assert_equal [["db:system:change", ""]], Rails::Command::Db::System::ChangeCommand.printing_commands
1414
end
1515

1616
test "printing commands hides hidden commands" do

0 commit comments

Comments
 (0)