Class: Factorix::CLI::Commands::MOD::Update

Inherits:
Base show all
Includes:
DownloadSupport, PortalSupport
Defined in:
lib/factorix/cli/commands/mod/update.rb,
sig/factorix/cli/commands/mod/update.rbs

Overview

Update installed MODs to their latest versions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

backup_support!, confirmable!, inherited, require_game_stopped!

Instance Attribute Details

#logger ⇒ Dry::Logger::Dispatcher (readonly)

Returns the value of attribute logger.



11
12
13
# File 'sig/factorix/cli/commands/mod/update.rbs', line 11

def logger
  @logger
end

#portal ⇒ Portal (readonly)

Returns the value of attribute portal.

Returns:



10
11
12
# File 'sig/factorix/cli/commands/mod/update.rbs', line 10

def portal
  @portal
end

#runtime ⇒ Runtime (readonly)

Returns the value of attribute runtime.

Returns:



12
13
14
# File 'sig/factorix/cli/commands/mod/update.rbs', line 12

def runtime
  @runtime
end

Instance Method Details

#call(mod_names: [], jobs: "4") ⇒ void

This method returns an undefined value.

Execute the update command

Parameters:

  • mod_names (Array<String>) (defaults to: []) —

    MOD names to update

  • jobs (Integer) (defaults to: "4") —

    Number of parallel downloads

  • mod_names: (Array[String]) (defaults to: [])
  • jobs: (Integer) (defaults to: "4")
  • yes: (Boolean)
  • quiet: (Boolean)


42
43
44
45
46
47
48
49
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
# File 'lib/factorix/cli/commands/mod/update.rb', line 42

def call(mod_names: [], jobs: "4", **)
  jobs = Integer(jobs)
  presenter = Progress::Presenter.new(title: "\u{1F50D}\u{FE0E} Scanning MOD(s)", output: err)
  handler = Progress::ScanHandler.new(presenter)
  installed_mods = InstalledMOD.all(handler:)
  mod_list = MODList.load

  target_mods = if mod_names.empty?
                  mods = installed_mods.map(&:mod)
                  mods.uniq!
                  mods.reject! {|mod| mod.base? || mod.expansion? }
                  mods
                else
                  mod_names.map {|name| validate_and_get_mod(name) }
                end

  if target_mods.empty?
    say "No MOD(s) to update", prefix: :info
    return
  end

  update_targets = find_update_targets(target_mods, installed_mods, jobs)

  if update_targets.empty?
    say "All MOD(s) are up to date", prefix: :info
    return
  end

  show_plan(update_targets)
  return unless confirm?("Do you want to update these MOD(s)?")

  execute_updates(update_targets, mod_list, jobs)

  backup_if_exists(runtime.mod_list_path)
  mod_list.save
  say "Updated #{update_targets.size} MOD(s)", prefix: :success
  say "Saved mod-list.json", prefix: :success
end