Class: Boxes::Command::Build

Inherits:
Boxes::Command show all
Defined in:
lib/boxes/command/build.rb

Overview

Command handling for the box building functionality.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Build

Returns a new instance of Build.



18
19
20
21
22
23
24
25
26
27
# File 'lib/boxes/command/build.rb', line 18

def initialize(argv)
  @build = {}
  @build[:name] = argv.option('name')
  @build[:provider] = argv.option('provider')
  @build[:template] = argv.option('template')
  scripts = argv.option('scripts') || ''
  @build[:scripts] = scripts.split(',')

  super
end

Class Method Details

.optionsObject



8
9
10
11
12
13
14
15
16
# File 'lib/boxes/command/build.rb', line 8

def self.options
  [
    ['--name', 'The name for the build'],
    ['--provider=[virtualbox|vmware]',
     'The provider to build the box for'],
    ['--template', 'Template to build the box with'],
    ['--scripts', 'Scripts to apply to the box']
  ].concat(super)
end

Instance Method Details

#runObject



37
38
39
40
41
42
43
44
45
# File 'lib/boxes/command/build.rb', line 37

def run
  env = Boxes::Environment.new
  builder = Boxes::Builder.new(env, @build)
  builder.run
  builder.clean
rescue Boxes::Errors::BuildRunError => e
  puts "[!] #{e}".red
  exit 1
end

#validate!Object



29
30
31
32
33
34
35
# File 'lib/boxes/command/build.rb', line 29

def validate!
  super

  %w(name provider template).each do |key|
    help! "A #{key} is required!" if @build[key.to_sym].nil?
  end
end