Class: CloudCompose::Cli::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_compose/cli/build.rb

Class Method Summary collapse

Class Method Details

.call(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cloud_compose/cli/build.rb', line 7

def call(args)
  input_file = args.shift

  if input_file.nil?
    raise ArgumentError, 'Missing input path `cloud-compose build <input-path>`'
  end

  template_path = File.expand_path(input_file)
  template = CloudCompose::Template.new(template_path, File.expand_path('.'))
  content = template.to_s

  file_name = File.basename(template_path)
  file_name.slice!(File.extname(file_name))
  file_name += '-build.yml'
  output_path = File.dirname(template_path)
  output_path += "/#{file_name}"

  File.open(output_path, 'w') do |f|
    f.write(content)
  end

  STDERR.puts "Built: #{output_path}"
end