Class: VagrantSpec::Command::Init
- Inherits:
-
Object
- Object
- VagrantSpec::Command::Init
- 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
-
#ansible_inventory ⇒ Object
Returns the value of attribute ansible_inventory.
-
#config ⇒ Object
Returns the value of attribute config.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#generate_machine_data ⇒ Object
Returns the value of attribute generate_machine_data.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(argv, env) ⇒ Init
constructor
A new instance of Init.
- #parse_opts ⇒ Object
Methods included from Utils
#lib_root, #project_root, #template_dir
Constructor Details
#initialize(argv, env) ⇒ Init
Returns a new instance of Init.
25 26 27 28 29 30 31 |
# File 'lib/vagrant_spec/command/init.rb', line 25 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_inventory ⇒ Object
Returns the value of attribute ansible_inventory.
22 23 24 |
# File 'lib/vagrant_spec/command/init.rb', line 22 def ansible_inventory @ansible_inventory end |
#config ⇒ Object
Returns the value of attribute config.
20 21 22 |
# File 'lib/vagrant_spec/command/init.rb', line 20 def config @config end |
#directory ⇒ Object
Returns the value of attribute directory.
21 22 23 |
# File 'lib/vagrant_spec/command/init.rb', line 21 def directory @directory end |
#generate_machine_data ⇒ Object
Returns the value of attribute generate_machine_data.
23 24 25 |
# File 'lib/vagrant_spec/command/init.rb', line 23 def generate_machine_data @generate_machine_data end |
Instance Method Details
#execute ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vagrant_spec/command/init.rb', line 33 def execute return unless parse_opts FileUtils.mkdir @directory unless Dir.exist? @directory 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_opts ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vagrant_spec/command/init.rb', line 44 def parse_opts opts = OptionParser.new do |o| o. = "\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 (opts) end |