Class: VagrantPuppetconf::Command::Puppetconf

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

Instance Method Summary collapse

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-puppetconf/command/puppetconf.rb', line 16

def execute
  @ui = Vagrant::UI::Colored.new('puppetconf')

  options = {}
  @opts = OptionParser.new do |opts|
    opts.banner = "Usage: vagrant [vm-name] puppetconf -k config_key -v config_value"

    opts.on('-k', '--key CONFIG_KEY', I18n.t('vagrant.plugins.puppetconf.command.options.key')) do |val|
      options[:key] = val
    end

    opts.on('-v', '--value CONFIG_VALUE', I18n.t('vagrant.plugins.puppetconf.command.options.value')) do |val|
      options[:value] = val
    end
  end

  vms = parse_options @opts

  validate options

  with_target_vms(vms) do |vm|
    Updater.update(vm, @ui, {options[:key] => options[:value]})
  end
end

#validate(options) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/vagrant-puppetconf/command/puppetconf.rb', line 6

def validate(options)
  %w{key value}.each do |opt|
    if options[opt.to_sym].empty?
      @ui.error "#{opt.upcase} not set"
      @ui.info "#{@opts}"
      exit 1
    end
  end
end