Class: Veewee::Command::Vagrant::Define

Inherits:
Vagrant::Command::Base
  • Object
show all
Defined in:
lib/veewee/command/vagrant/define.rb

Instance Method Summary collapse

Instance Method Details

#executeObject

Raises:

  • (::Vagrant::Errors::CLIInvalidUsage)


7
8
9
10
11
12
13
14
15
16
17
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
# File 'lib/veewee/command/vagrant/define.rb', line 7

def execute
  options = {}

  opts = OptionParser.new do |opts|
    opts.banner = "Define a new basebox based on a template"
    opts.separator ""
    opts.separator "Usage: vagrant basebox define <boxname> <template>"

    opts.on("-d", "--debug", "enable debugging") do |d|
      options['debug'] = d
    end

    opts.on("-f", "--force", "force overwrite") do |f|
      options['force'] = f
    end

  end

  # Parse the options
  argv = parse_options(opts)
  return if !argv
  raise ::Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 2

  begin
    venv=Veewee::Environment.new(options)
    venv.ui=@env.ui
    definition_name=argv[0]
    template_name=argv[1]
    venv.definitions.define(definition_name,template_name,options)
    venv.ui.info "The basebox '#{definition_name}' has been successfully created from the template '#{template_name}'"
    venv.ui.info "You can now edit the definition files stored in definitions/#{definition_name} or build the box with:"
    venv.ui.info "vagrant basebox build '#{definition_name}'"
  rescue Veewee::Error => ex
    venv.ui.error(ex,:prefix => false)
    exit -1
  end

end