Class: VagrantPlugins::Deltacloud::Command::AbstractCommand

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

Instance Method Summary collapse

Constructor Details

#initialize(argv, env) ⇒ AbstractCommand

Returns a new instance of AbstractCommand.



7
8
9
10
# File 'lib/vagrant-deltacloud-provider/command/abstract_command.rb', line 7

def initialize(argv, env)
  @env = env
  super(normalize_args(argv), env)
end

Instance Method Details

#cmd(_name, _argv, _env) ⇒ Object



40
41
42
# File 'lib/vagrant-deltacloud-provider/command/abstract_command.rb', line 40

def cmd(_name, _argv, _env)
  fail 'Command not implemented. \'cmd\' method must be overridden in all subclasses'
end

#execute(name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-deltacloud-provider/command/abstract_command.rb', line 12

def execute(name)
  env = {}
  with_target_vms(nil, provider: :deltacloud) do |machine|
    env[:deltacloud_client] = Deltacloud::DeltacloudClient.instance
    env[:machine] = machine
    env[:ui] = @env.ui
  end

  cmd(name, @argv, env)
  @env.ui.info('')
# rubocop:disable Lint/RescueException
rescue Errors::VagrantDeltacloudError => e
  raise e
rescue Exception => e
  puts I18n.t('vagrant_deltacloud.global_error') unless e.message && e.message.start_with?('Catched Error:')
  raise e
end

#normalize_args(args) ⇒ Object

Before Vagrant 1.5, args list ends with an extra arg ‘–’. It removes it if present.



34
35
36
37
38
# File 'lib/vagrant-deltacloud-provider/command/abstract_command.rb', line 34

def normalize_args(args)
  return args if args.nil?
  args.pop if args.size > 0 && args.last == '--'
  args
end