class VagrantHosts::Command::Puppetize

Public Class Methods

new(argv, env) click to toggle source
# File lib/vagrant-hosts/command/puppetize.rb, line 10
def initialize(argv, env)
  @argv     = argv
  @env      = env
  @cmd_name = 'hosts puppetize'

  split_argv
end
synopsis() click to toggle source
# File lib/vagrant-hosts/command/puppetize.rb, line 6
def self.synopsis
  'List private_network host info as Puppet Host resources'
end

Public Instance Methods

execute() click to toggle source
# File lib/vagrant-hosts/command/puppetize.rb, line 18
def execute
  argv = parse_options(parser)

  @env.ui.info format_hosts
  0
end

Private Instance Methods

format_hosts() click to toggle source
# File lib/vagrant-hosts/command/puppetize.rb, line 27
def format_hosts
  vagrant_hosts(@env).inject('') do |str, (address, aliases)|
    str << "host { '#{aliases.shift}':\n  ip => '#{address}',\n"
    str << "host_aliases => ['#{aliases.join('\', \' ')}'],\n" if (!aliases.empty?)
    str << "}\n"
  end
end
parser() click to toggle source
# File lib/vagrant-hosts/command/puppetize.rb, line 35
def parser
  OptionParser.new do |o|
    o.banner = "Usage: vagrant #{@cmd_name} [<args>]"
    o.separator ''

    o.on('-h', '--help', 'Display this help message') do
      puts o
      exit 0
    end
  end
end