Class: Factorix::CLI::Commands::MOD::Image::List

Inherits:
Base
  • Object
show all
Includes:
PortalSupport
Defined in:
lib/factorix/cli/commands/mod/image/list.rb

Overview

List images for a MOD on Factorio MOD Portal

Instance Method Summary collapse

Methods inherited from Base

backup_support!, confirmable!, inherited, require_game_stopped!

Instance Method Details

#call(mod_name:, json:) ⇒ void

This method returns an undefined value.

Execute the list command

Parameters:

  • mod_name (String)

    the MOD name

  • json (Boolean)

    output in JSON format



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/factorix/cli/commands/mod/image/list.rb', line 28

def call(mod_name:, json:, **)
  # Get full MOD info to retrieve images
  mod_info = portal.get_mod_full(mod_name)

  images = if mod_info.detail&.images&.any?
             mod_info.detail.images.map do |image|
               {
                 id: image.id,
                 thumbnail: image.thumbnail.to_s,
                 url: image.url.to_s
               }
             end
           else
             []
           end

  if json
    out.puts JSON.pretty_generate(images)
  else
    output_table(images)
  end
end