2024-09-09 23:14:39 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-11-20 06:51:53 +08:00
|
|
|
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)
|
2024-09-09 23:14:39 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|