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

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

Overview

Enable MODs in mod-list.json with dependency resolution

Instance Method Summary collapse

Methods inherited from Base

backup_support!, confirmable!, inherited, require_game_stopped!

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



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