Class: Vagrant::Hivemind::Command::Init

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Hivemind::Constants, Util
Defined in:
lib/vagrant/hivemind/commands/init.rb

Constant Summary

Constants included from Vagrant::Hivemind::Constants

Vagrant::Hivemind::Constants::ANSIBLE_HOSTS_FILE, Vagrant::Hivemind::Constants::BOX_SIZES, Vagrant::Hivemind::Constants::BOX_TYPES, Vagrant::Hivemind::Constants::CONTROL_HOSTNAME, Vagrant::Hivemind::Constants::HIVE_FILE, Vagrant::Hivemind::Constants::IP_ADDRESS_REGEX, Vagrant::Hivemind::Constants::PORT_PAIR_REGEX, Vagrant::Hivemind::Constants::PRIVATE_NETWORK, Vagrant::Hivemind::Constants::PRIVATE_NETWORK_END, Vagrant::Hivemind::Constants::PRIVATE_NETWORK_IP_ADDRESS_POOL, Vagrant::Hivemind::Constants::PRIVATE_NETWORK_START, Vagrant::Hivemind::Constants::SIMPLE_HOSTNAME_MAX_LENGTH, Vagrant::Hivemind::Constants::SIMPLE_HOSTNAME_REGEX, Vagrant::Hivemind::Constants::SYSTEM_HOSTS_FILE, Vagrant::Hivemind::Constants::VAGRANT_FILE

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



14
15
16
# File 'lib/vagrant/hivemind/commands/init.rb', line 14

def self.synopsis
  "Initializes a new Hive by creating a '#{HIVE_FILE}'"
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vagrant/hivemind/commands/init.rb', line 18

def execute
  options = {}

  OptionParser.new do |o|
    o.banner = "Usage: vagrant hivemind init [options]"
    o.separator ""
    o.separator "Options:"
    o.separator ""

    o.on("-f", "--force", "Overwrite an existing '#{HIVE_FILE}' with a new one") do |f|
      options[:force] = f
    end

    o.on("-d", "--directory DIRECTORY", "Specify the directory where '#{HIVE_FILE}' will be created (default: current directory)") do |d|
      options[:directory] = []
      options[:directory] << d
    end
  end.parse!

  root_path = Path.get_root_path_from_options options

  if HiveFile.exist? root_path
    if options[:force]
      write_new_hive_file root_path
      @env.ui.info "The Hive file has been overwritten."
      return 0
    else
      @env.ui.error "The Hive file already exists!"
      return 1
    end
  end

  write_new_hive_file root_path
  @env.ui.info "The Hive file has been created in the working directory."

  0
end