Class: VagrantSpec::Command::Init

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/vagrant_spec/command/init.rb

Overview

This command instantiates serveral files for deployment and testing

argv env [Vagrant::Environment]

Constant Summary collapse

DEFAULTS =
VagrantSpec::Config::DEFAULTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#lib_root, #project_root, #template_dir

Constructor Details

#initialize(argv, env) ⇒ Init

Returns a new instance of Init.



24
25
26
27
28
29
30
# File 'lib/vagrant_spec/command/init.rb', line 24

def initialize(argv, env)
  super
  @config                = VagrantSpec::Config.load env
  @directory             = @config.spec.directory
  @ansible_inventory     = @config.spec.ansible_inventory
  @generate_machine_data = @config.spec.generate_machine_data
end

Instance Attribute Details

#ansible_inventoryObject

Returns the value of attribute ansible_inventory.



21
22
23
# File 'lib/vagrant_spec/command/init.rb', line 21

def ansible_inventory
  @ansible_inventory
end

#configObject

Returns the value of attribute config.



19
20
21
# File 'lib/vagrant_spec/command/init.rb', line 19

def config
  @config
end

#directoryObject

Returns the value of attribute directory.



20
21
22
# File 'lib/vagrant_spec/command/init.rb', line 20

def directory
  @directory
end

#generate_machine_dataObject

Returns the value of attribute generate_machine_data.



22
23
24
# File 'lib/vagrant_spec/command/init.rb', line 22

def generate_machine_data
  @generate_machine_data
end

Instance Method Details

#executeObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant_spec/command/init.rb', line 32

def execute
  return unless parse_opts
  VagrantSpec::SpecHelper.new(@env).generate
  unless @ansible_inventory == DEFAULTS['ansible_inventory']
    VagrantSpec::AnsibleInventory.new(@env).generate
  end
  if @generate_machine_data == DEFAULTS['generate_machine_data']
    VagrantSpec::MachineData.new(@env).generate
  end
end

#parse_optsObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/vagrant_spec/command/init.rb', line 43

def parse_opts
  opts = OptionParser.new do |o|
    o.banner = "\nInit: Initializes state configuration"
    o.separator ''
    o.separator 'Usage: vagrant spec init'
    o.separator ''
    o.separator IO.read(File.join(template_dir, 'init_help'))
  end
  parse_options(opts)
end