Class: VagrantPlugins::Provider::PickCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/vagrant-provider/pick-command.rb

Instance Method Summary collapse

Methods inherited from BaseCommand

#active_provider, #line, #machine_folder, #machine_names, #machine_provider, #provider_name, #providers_for

Instance Method Details

#executeObject



5
6
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
45
46
47
48
# File 'lib/vagrant-provider/pick-command.rb', line 5

def execute
  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant provider pick <provider> [machine-name]"
    o.separator ""
    o.separator "Bring back previously stored provider state"
    o.separator ""
  end

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

  provider_name = argv[0].to_sym
  machine_name = (argv[1] || @env.primary_machine_name).to_sym

  if not machine_names.include? machine_name
    raise Vagrant::Errors::MachineNotFound,
      name: machine_name
  end

  if active_provider(machine_name)
    raise HasActiveProvider
  end

  provider = machine_provider(machine_name, provider_name)
  if not provider
    raise NoStashedProvider
  end

  source = machine_folder.join("#{machine_name}_#{provider_name}")
  target = machine_folder.join("#{machine_name}")

  target.rmtree if target.exist?
  source.rename(target)

  line "Restored #{provider[:name]} provider from stash"

  # Success, exit status 0
  0
end