Class: Factorix::CLI::Commands::MOD::Enable

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

Overview

Enable MODs in mod-list.json with 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/enable.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/enable.rbs', line 13

def runtime
  @runtime
end

Instance Method Details

#call(mod_names:) ⇒ void

This method returns an undefined value.

Execute the enable command

Parameters:

  • mod_names (Array<String>) —

    MOD names to enable

  • mod_names: (Array[String])
  • yes: (Boolean)
  • quiet: (Boolean)


33
34
35
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
# File 'lib/factorix/cli/commands/mod/enable.rb', line 33

def call(mod_names:, **)
  # 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:)

  # Convert MOD names to MOD objects
  target_mods = mod_names.map {|name| Factorix::MOD[name:] }

  # Validate target MODs exist
  validate_target_mods_exist(target_mods, graph)

  # Determine MODs to enable
  mods_to_enable = plan_with_dependencies(target_mods, graph)

  # Validate the plan (check for conflicts)
  validate_plan(mods_to_enable, graph)

  # Show plan to user
  show_plan(mods_to_enable)

  # Return early if nothing to enable
  return if mods_to_enable.empty?

  # Ask for confirmation
  return unless confirm?("Do you want to enable these MOD(s)?")

  # Execute the plan
  execute_plan(mods_to_enable, mod_list)

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