class Baha::CLI

Public Instance Methods

build(config) click to toggle source
# 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) click to toggle source
# 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
version() click to toggle source
# File lib/baha/cli.rb, line 121
def version
  puts "baha " + Baha::VERSION
end