Module: Onering::CLI
- Defined in:
- lib/onering/cli.rb,
lib/onering/cli/call.rb,
lib/onering/cli/fact.rb,
lib/onering/cli/assets.rb,
lib/onering/cli/devices.rb,
lib/onering/cli/reporter.rb,
lib/onering/cli/automation.rb
Defined Under Namespace
Classes: Assets, Automation, Call, Devices, Fact, Plugin, Report
Class Method Summary
collapse
Class Method Details
.connect(cliargs) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/onering/cli.rb', line 32
def self.connect(cliargs)
@_args = cliargs
return Onering::API.new({
'autoconnect' => cliargs[:autoconnect],
'config' => {
'url' => cliargs[:url],
'path' => cliargs[:path],
'source' => cliargs[:source],
'nosslverify' => cliargs[:nosslverify],
'params' => Hash[(cliargs[:param] || []).collect{|i| i.split('=',2) }],
'authentication' => {
'type' => (cliargs[:apikey_given] ? :token : nil),
'keyfile' => (cliargs[:apikey] || cliargs[:sslkey])
}.compact
}.compact
}.compact)
end
|
.output(data, format) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/onering/cli.rb', line 51
def self.output(data, format)
return nil if @_args[:quiet]
return nil if data.nil?
Onering::Logger.debug("Outputting data as #{format}:", "Onering::CLI")
case format
when 'text', 'txt'
if data.is_a?(Hash)
data.coalesce.each do |k,v|
puts k.to_s+': '+v.to_s
end
elsif data.is_a?(Array) and data.first.is_a?(Array)
puts data.collect{|i| i.map(&:to_s).join(@_args.get(:separator, "\t")) }.sort.join("\n")
else
[*data].each do |d|
if d.is_a?(Hash)
d.coalesce.each do |k,v|
puts k.to_s+': '+v.to_s
end
else
puts d unless d.nil? or d.to_s.empty?
end
end
end
when 'json'
puts MultiJson.dump(data, :pretty => true)
when 'yaml'
puts YAML.dump(data)
else
Onering::Logger.error("Unknown output format #{format.inspect}", "Onering::CLI")
end
return nil
end
|