Class: Factorix::CLI::Commands::Blueprint::Decode

Inherits:
Factorix::CLI::Commands::Base show all
Defined in:
lib/factorix/cli/commands/blueprint/decode.rb

Overview

Decode a Factorio blueprint string to JSON

Instance Method Summary collapse

Methods inherited from Factorix::CLI::Commands::Base

backup_support!, confirmable!, inherited, require_game_stopped!

Instance Method Details

#call(file: nil, output: nil) ⇒ void

This method returns an undefined value.

Execute the decode command

Parameters:

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

    Path to file containing blueprint string

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

    Output file path



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/factorix/cli/commands/blueprint/decode.rb', line 25

def call(file: nil, output: nil, **)
  blueprint_string = file ? Pathname(file).read.strip : $stdin.read.strip
  blueprint = Factorix::Blueprint.decode(blueprint_string)
  json_string = blueprint.to_json

  if output
    Pathname(output).write(json_string)
  else
    out.puts json_string
  end
end