Class: Factorix::CLI::Commands::MOD::Uninstall

Inherits:
Base show all
Includes:
Confirmable
Defined in:
lib/factorix/cli/commands/mod/uninstall.rb,
sig/factorix/cli/commands/mod/uninstall.rbs

Overview

Uninstall MODs from MOD directory

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Confirmable

prepended

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.



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

def logger
  @logger
end

#runtime ⇒ Runtime (readonly)

Returns the value of attribute runtime.

Returns:



13
14
15
# File 'sig/factorix/cli/commands/mod/uninstall.rbs', line 13

def runtime
  @runtime
end

Instance Method Details

#call(mod_specs: [], all: false) ⇒ void

This method returns an undefined value.

Execute the uninstall command

Parameters:

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

    MOD specifications

  • all (Boolean) (defaults to: false) —

    Uninstall all MODs

  • mod_specs: (Array[String]) (defaults to: [])
  • all: (Boolean) (defaults to: false)
  • yes: (Boolean)
  • quiet: (Boolean)


36
37
38
39
40
41
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
80
81
82
83
84
85
86
87
# File 'lib/factorix/cli/commands/mod/uninstall.rb', line 36

def call(mod_specs: [], all: false, **)
  # Validate arguments
  if all && mod_specs.any?
    raise InvalidArgumentError, "Cannot specify MOD names with --all option"
  end

  unless all || mod_specs.any?
    raise InvalidArgumentError, "Must specify MOD names or use --all option"
  end

  # Load current state (without validation to allow fixing issues)
  mod_list = MODList.load
  presenter = Progress::Presenter.new(title: "\u{1F50D}\u{FE0E} Scanning MOD(s)", output: err)
  handler = Progress::ScanHandler.new(presenter)
  installed_mods = InstalledMOD.all(handler:)
  graph = Dependency::Graph::Builder.build(installed_mods:, mod_list:)

  # Determine uninstall targets
  uninstall_targets = if all
                        plan_uninstall_all(graph, installed_mods)
                      else
                        # Parse mod specs to extract MOD and optional version
                        mod_specs.map {|spec| parse_mod_spec(spec) }
                      end

  targets_to_uninstall = plan_uninstall(uninstall_targets, graph, installed_mods, all:)

  if all
    expansions_to_disable = graph.nodes.count {|node|
      mod = node.mod
      mod.expansion? && mod_list.exist?(mod) && mod_list.enabled?(mod)
    }

    if targets_to_uninstall.empty? && expansions_to_disable.zero?
      say "No MOD(s) to uninstall or disable", prefix: :info
      return
    end
  elsif targets_to_uninstall.empty?
    say "No MOD(s) to uninstall", prefix: :info
    return
  end

  show_plan(targets_to_uninstall, all:, graph:, mod_list:)
  return unless confirm?("Do you want to uninstall these MOD(s)?")

  execute_uninstall(targets_to_uninstall, installed_mods, mod_list)
  disable_expansion_mods(graph, mod_list) if all
  backup_if_exists(runtime.mod_list_path)
  mod_list.save
  say "Uninstalled #{targets_to_uninstall.size} MOD(s)", prefix: :success
  say "Saved mod-list.json", prefix: :success
end