Class: AllImages::App

Inherits:
Object
  • Object
show all
Includes:
FileUtils, Term::ANSIColor
Defined in:
lib/all_images/app.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ App

Returns a new instance of App.



12
13
14
15
16
17
# File 'lib/all_images/app.rb', line 12

def initialize(args)
  @args     = args.dup
  @command  = pick_command
  @commands = %w[ ls help run debug run_all ].sort
  @suffix   = Tins::Token.new(alphabet: Tins::Token::BASE32_ALPHABET, bits: 32)
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/all_images/app.rb', line 19

def run
  @config   = load_config or return 23
  result = 0
  case @command
  when 'ls'
    puts Array(@config['images']).map(&:first)
  when 'help'
    puts "Usage: #{File.basename($0)} #{@commands * ?|} [IMAGE]"
  else
    Array(@config['images']).each do |image, script|
      case @command
      when 'run_all'
        result |= run_image(image, script)
      when 'run_selected'
        image == @selected and result |= run_image(image, script)
      when 'debug_selected'
        image == @selected and result |= run_image(image, script, interactive: true)
      end
      if @config['fail_fast'] && result != 0
        return 1
      end
    end
  end
  result
end