Class: Baha::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/baha/cli.rb

Instance Method Summary collapse

Instance Method Details

#build(config) ⇒ Object



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
# File 'lib/baha/cli.rb', line 39

def build(config)
  quiet = options[:quiet]
  unless quiet
    if options[:logfile].nil? or options[:logfile] == 'STDOUT'
      Baha::Log.logfile = STDOUT 
    else
      Baha::Log.logfile = STDOUT 
    end
    if options[:debug]
      Baha::Log.level = :debug
    elsif options[:verbose]
      Baha::Log.level = :info
    else
      Baha::Log.level = :error
    end
  end
  begin
    builder = Baha::Builder.new(config)
    builder.build!
  rescue Exception => e
    unless quiet
      Baha::Log.for_name("CLI").fatal("Error encountered while building images")
      Baha::Log.for_name("CLI").fatal(e)
    end
    exit 1
  ensure
    Baha::Log.close!
  end
end

#convert(dockerfile) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/baha/cli.rb', line 92

def convert(dockerfile)
  file = Pathname.new(dockerfile)
  out = options[:output]
  name = options[:name]
  tag = options[:tag]
  Baha::Log.logfile = STDERR
  Baha::Log.level = :info
  log = Baha::Log.for_name("CLI")
  begin
    if file.exist?
      yaml = Baha::Dockerfile.parse(dockerfile)
      yaml = { 'name' => name, 'tag' => tag }.merge(yaml)
      if out == 'STDOUT'
        puts yaml.to_yaml
      else
        File.open(out,'w') do |f|
          f.write yaml.to_yaml
        end
      end
    else
        log.fatal { "DOCKERFILE #{dockerfile} not found" }
        exit 1
    end
  rescue Exception => e
    log.fatal("Error encountered while building images")
    log.fatal(e)
  end
end

#versionObject



121
122
123
# File 'lib/baha/cli.rb', line 121

def version
  puts "baha " + Baha::VERSION
end