diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/commands/command.rb | 30 | ||||
-rw-r--r-- | railties/lib/rails/commands/commands_tasks.rb | 7 |
2 files changed, 15 insertions, 22 deletions
diff --git a/railties/lib/rails/commands/command.rb b/railties/lib/rails/commands/command.rb index c8707be3ab..fe0b77cb96 100644 --- a/railties/lib/rails/commands/command.rb +++ b/railties/lib/rails/commands/command.rb @@ -10,17 +10,20 @@ module Rails @options = {} end - def run(task_name) - command_name = self.class.command_name_for(task_name) + def self.run(task_name, argv) + command_name = command_name_for(task_name) + if command = command_for(command_name) + command.new(argv).run(command_name) + true # Indicate command was found and run. + end + end + + def run(command_name) parse_options_for(command_name) @option_parser.parse! @argv - if command = command_for(command_name) - command.public_send(command_name) - else - puts @option_parser - end + public_send(command_name) end def self.options_for(command_name, &options_to_parse) @@ -31,11 +34,6 @@ module Rails options_for(command_name) { |opts, _| opts.banner = banner } end - def exists?(task_name) # :nodoc: - command_name = self.class.command_name_for(task_name) - !command_for(command_name).nil? - end - private @@commands = [] @@command_options = {} @@ -61,14 +59,10 @@ module Rails task_name.gsub(':', '_').to_sym end - def command_for(command_name) - klass = @@commands.find do |command| + def self.command_for(command_name) + @@commands.find do |command| command.public_instance_methods.include?(command_name) end - - if klass - klass.new(@argv) - end end end end diff --git a/railties/lib/rails/commands/commands_tasks.rb b/railties/lib/rails/commands/commands_tasks.rb index f79b40b2ab..6f3f4f7042 100644 --- a/railties/lib/rails/commands/commands_tasks.rb +++ b/railties/lib/rails/commands/commands_tasks.rb @@ -32,15 +32,14 @@ EOT def initialize(argv) @argv = argv - @rails_command = Rails::Commands::Command.new(argv) end def run_command!(command) command = parse_command(command) - if @rails_command.exists?(command) - @rails_command.run(command) - elsif COMMAND_WHITELIST.include?(command) + run_with_command = Rails::Commands::Command.run(command, argv) + + if !run_with_command && COMMAND_WHITELIST.include?(command) send(command) else write_error_message(command) |