Class: Factorix::CLI::Commands::MOD::Upload

Inherits:
Base
  • Object
show all
Includes:
PortalSupport
Defined in:
lib/factorix/cli/commands/mod/upload.rb

Overview

Upload MOD to Factorio MOD Portal (handles both new and update)

Instance Method Summary collapse

Methods inherited from Base

backup_support!, confirmable!, inherited, require_game_stopped!

Instance Method Details

#call(file:, description: nil, category: nil, license: nil, source_url: nil) ⇒ void

This method returns an undefined value.

Execute the upload command

Parameters:

  • file (String)

    path to MOD zip file

  • description (String, nil) (defaults to: nil)

    optional description

  • category (String, nil) (defaults to: nil)

    optional category

  • license (String, nil) (defaults to: nil)

    optional license

  • source_url (String, nil) (defaults to: nil)

    optional source URL

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/factorix/cli/commands/mod/upload.rb', line 34

def call(file:, description: nil, category: nil, license: nil, source_url: nil, **)
  file_path = Pathname(file)

  raise InvalidArgumentError, "File not found: #{file}" unless file_path.exist?
  raise InvalidArgumentError, "Not a file: #{file}" unless file_path.file?
  raise InvalidArgumentError, "File must be a .zip file" if file_path.extname.casecmp(".zip").nonzero?

  mod_name = extract_mod_name(file_path)
   = (description:, category:, license:, source_url:)

  presenter = Progress::Presenter.new(title: "\u{1F4E4} Uploading #{file_path.basename}", output: err)

  uploader = portal.mod_management_api.uploader
  handler = Progress::UploadHandler.new(presenter)
  uploader.subscribe(handler)

  begin
    portal.upload_mod(mod_name, file_path, **)
    say "Upload completed successfully!", prefix: :success
  ensure
    uploader.unsubscribe(handler)
  end
end