Class: EmergeCLI::Commands::Upload::Snapshots
- Inherits:
-
GlobalOptions
- Object
- Dry::CLI::Command
- GlobalOptions
- EmergeCLI::Commands::Upload::Snapshots
- Defined in:
- lib/commands/upload/snapshots/snapshots.rb
Instance Method Summary collapse
- #call(image_paths:, **options) ⇒ Object
-
#initialize(network: nil, git_info_provider: nil) ⇒ Snapshots
constructor
A new instance of Snapshots.
Methods inherited from GlobalOptions
Constructor Details
#initialize(network: nil, git_info_provider: nil) ⇒ Snapshots
Returns a new instance of Snapshots.
44 45 46 47 48 |
# File 'lib/commands/upload/snapshots/snapshots.rb', line 44 def initialize(network: nil, git_info_provider: nil) @network = network @git_info_provider = git_info_provider @profiler = EmergeCLI::Profiler.new end |
Instance Method Details
#call(image_paths:, **options) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/commands/upload/snapshots/snapshots.rb', line 50 def call(image_paths:, **) @options = @profiler = EmergeCLI::Profiler.new(enabled: [:profile]) before() start_time = Time.now run_id = nil success = false begin api_token = @options[:api_token] || ENV.fetch('EMERGE_API_TOKEN', nil) raise 'API token is required and cannot be blank' if api_token.nil? || api_token.strip.empty? @network ||= EmergeCLI::Network.new(api_token:) @git_info_provider ||= GitInfoProvider.new Sync do (image_paths) client = create_client(image_paths) image_files = @profiler.measure('find_image_files') { find_image_files(client) } check_duplicate_files(image_files, client) run_id = @profiler.measure('create_run') { create_run } upload_images(run_id, [:concurrency], image_files, client) @profiler.measure('finish_run') { finish_run(run_id) } unless [:batch] end Logger.info 'Upload completed successfully!' Logger.info "Time taken: #{(Time.now - start_time).round(2)} seconds" @profiler.report Logger.info "✅ View your snapshots at https://emergetools.com/snapshot/#{run_id}" success = true rescue StandardError => e Logger.error "CLI Error: #{e.}" Sync { report_error(run_id, e., 'crash') } if run_id raise e # Re-raise the error to dry-cli ensure @network&.close end success end |