Class: Factorix::CLI::Commands::MOD::Disable

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

Overview

Disable MODs in mod-list.json with reverse dependency resolution

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/disable.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/disable.rbs', line 13

def runtime
  @runtime
end

Instance Method Details

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

This method returns an undefined value.

Execute the disable command

Parameters:

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

    MOD names to disable

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

    Whether to disable all MODs

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


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
# File 'lib/factorix/cli/commands/mod/disable.rb', line 37

def call(mod_names: [], all: false, **)
  validate_arguments(mod_names, all)

  # 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:)

  target_mods = if all
                  plan_disable_all(graph)
                else
                  mod_names.map {|name| Factorix::MOD[name:] }
                end

  validate_target_mods(target_mods, graph)
  mods_to_disable = plan_with_dependents(target_mods, graph)

  show_plan(mods_to_disable)
  return if mods_to_disable.empty?
  return unless confirm?("Do you want to disable these MOD(s)?")

  execute_plan(mods_to_disable, mod_list)
  backup_if_exists(runtime.mod_list_path)
  mod_list.save
  say "Disabled #{mods_to_disable.size} MOD(s)", prefix: :success
  say "Saved mod-list.json", prefix: :success
  logger.debug("Saved mod-list.json")
end