mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 20:33:55 +08:00
75f4a14568
The previous approach of splitting Thor commands into multiple files caused problems when the same method name was used in multiple commands. This also loads the Rails environment only for commands that need it. That makes the CLI boot faster for most commands or when the help should be shown. That's also why we can't use `Rails.root` in the CLI.
41 lines
932 B
Ruby
41 lines
932 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Migrations::CLI
|
|
class UploadCommand
|
|
def initialize(options)
|
|
@options = options
|
|
end
|
|
|
|
def execute
|
|
puts "Starting uploads..."
|
|
|
|
validate_settings_file!
|
|
settings = load_settings
|
|
|
|
::Migrations::Uploader::Uploads.perform!(settings)
|
|
|
|
puts ""
|
|
end
|
|
|
|
private
|
|
|
|
def load_settings
|
|
settings = ::Migrations::SettingsParser.parse!(@options.settings)
|
|
merge_settings_from_cli_args!(@options, settings)
|
|
|
|
settings
|
|
end
|
|
|
|
def merge_settings_from_cli_args!(settings)
|
|
settings[:fix_missing] = options.fix_missing if @options.fix_missing.present?
|
|
settings[:create_optimized_images] = options.optimize if @options.optimize.present?
|
|
end
|
|
|
|
def validate_settings_file!
|
|
path = @options.settings
|
|
|
|
raise ::Migrations::NoSettingsFound, "Settings file not found: #{path}" if !File.exist?(path)
|
|
end
|
|
end
|
|
end
|