Class: RbVmomi::VIM::EsxcliCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/rvc/extensions/HostSystem.rb

Instance Method Summary collapse

Instance Method Details

#option_parserObject



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/rvc/extensions/HostSystem.rb', line 169

def option_parser
  parser = Trollop::Parser.new
  parser.text cli_info.help
  cli_info.param.each do |cli_param|
    vmodl_param = type_info.paramTypeInfo.find { |x| x.name == cli_param.name }
    opts = trollop_type(vmodl_param.type)
    opts[:required] = vmodl_param.annotation.find { |a| a.name == "optional"} ? false : true
    opts[:long] = cli_param.displayName
    #pp opts.merge(:name => cli_param.name)
    # XXX correct short options
    parser.opt cli_param.name, cli_param.help, opts
  end
  parser
end

#trollop_type(t) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/rvc/extensions/HostSystem.rb', line 184

def trollop_type t
  if t[-2..-1] == '[]'
    multi = true
    t = t[0...-2]
  else
    multi = false
  end
  type = case t
  when 'string', 'boolean' then t.to_sym
  when 'long' then :int
  else fail "unexpected esxcli type #{t.inspect}"
  end
  { :type => type, :multi => multi }
end