module Rails::Command

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/rails/command.rbs

module Rails::Command
  def invoke: (String full_namespace, ?Array[] args, **Hash config) -> false
end

def command_type # :doc:

:doc:
def command_type # :doc:
  @command_type ||= "command"
end

def commands

def commands
  lookup!
  visible_commands = (subclasses - hidden_commands).flat_map(&:printing_commands)
  (visible_commands - COMMANDS_IN_USAGE).sort
end

def environment # :nodoc:

:nodoc:
def environment # :nodoc:
  ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development"
end

def file_lookup_paths # :doc:

:doc:
def file_lookup_paths # :doc:
  @file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_command.rb" ]
end

def find_by_namespace(namespace, command_name = nil) # :nodoc:

:nodoc:

"webrat", "webrat:integration", "rails:webrat", "rails:webrat:integration"

Will search for the following commands:

find_by_namespace :webrat, :integration

looks in load paths and loads the command just before it's going to be used.
Command names must end with "_command.rb". This is required because Rails

Rails finds namespaces similar to Thor, it only adds one rule:
def find_by_namespace(namespace, command_name = nil) # :nodoc:
  lookups = [ namespace ]
  lookups << "#{namespace}:#{command_name}" if command_name
  lookups.concat lookups.map { |lookup| "rails:#{lookup}" }
  lookup(lookups)
  namespaces = subclasses.index_by(&:namespace)
  namespaces[(lookups & namespaces.keys).first]
end

def hidden_commands # :nodoc:

:nodoc:
def hidden_commands # :nodoc:
  @hidden_commands ||= []
end

def invoke(full_namespace, args = [], **config)

Experimental RBS support (using type sampling data from the type_fusion project).

def invoke: (String full_namespace, ? args, **current_command | Thor::Command config) -> false

This signature was generated using 2 samples from 1 application.

Receives a namespace, arguments, and the behavior to invoke the command.
def invoke(full_namespace, args = [], **config)
  namespace = full_namespace = full_namespace.to_s
  if char = namespace =~ /:(\w+)$/
    command_name, namespace = $1, namespace.slice(0, char)
  else
    command_name = namespace
  end
  command_name, namespace = "help", "help" if command_name.blank? || HELP_MAPPINGS.include?(command_name)
  command_name, namespace, args = "application", "application", ["--help"] if rails_new_with_no_path?(args)
  command_name, namespace = "version", "version" if %w( -v --version ).include?(command_name)
  original_argv = ARGV.dup
  ARGV.replace(args)
  command = find_by_namespace(namespace, command_name)
  if command && command.all_commands[command_name]
    command.perform(command_name, args, config)
  else
    args = ["--describe", full_namespace] if HELP_MAPPINGS.include?(args[0])
    find_by_namespace("rake").perform(full_namespace, args, config)
  end
ensure
  ARGV.replace(original_argv)
end

def lookup_paths # :doc:

:doc:
def lookup_paths # :doc:
  @lookup_paths ||= %w( rails/commands commands )
end

def print_commands # :nodoc:

:nodoc:
def print_commands # :nodoc:
  commands.each { |command| puts("  #{command}") }
end

def rails_new_with_no_path?(args)

def rails_new_with_no_path?(args)
  args == ["new"]
end

def root

Returns the root of the Rails engine or app running the command.
def root
  if defined?(ENGINE_ROOT)
    Pathname.new(ENGINE_ROOT)
  elsif defined?(APP_PATH)
    Pathname.new(File.expand_path("../..", APP_PATH))
  end
end