Class: Factorix::CLI::Commands::MOD::Settings::Restore

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

Overview

Restore MOD settings from JSON format

Instance Method Summary collapse

Methods inherited from Base

backup_support!, confirmable!, inherited, require_game_stopped!

Instance Method Details

#call(input: nil, settings_file: nil) ⇒ void

This method returns an undefined value.

Execute the restore command

Parameters:

  • input (String, nil) (defaults to: nil)

    Path to JSON file

  • settings_file (String, nil) (defaults to: nil)

    Path to mod-settings.dat file



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/factorix/cli/commands/mod/settings/restore.rb', line 35

def call(input: nil, settings_file: nil, **)
  # Read input
  if input
    input_path = Pathname(input)
    input_string = input_path.read
  else
    # Read from stdin
    input_string = $stdin.read
  end

  # Parse input
  data = JSON.parse(input_string)
  settings = build_settings(data)

  # Determine output path
  output_path = settings_file ? Pathname(settings_file) : runtime.mod_settings_path

  # Backup existing file if it exists
  backup_if_exists(output_path)

  # Save settings
  settings.save(output_path)
end