Revision 49620a31
Added by Brian Gupta about 12 years ago
- ID 49620a313b5d93bace4a96db42da3734ad8d924e
extras/cli/foremancli | ||
---|---|---|
end
|
||
collections_filterable.each do |collection|
|
||
options[collection] = false
|
||
opts.on("--#{collection} [filter]", "Retreive a list of #{collection}") do |f|
|
||
opts.on("--#{collection} [filter]", "Retrieve a list of #{collection}") do |f|
|
||
options[collection] = f || true
|
||
end
|
||
end
|
||
collections.each do |collection|
|
||
options[collection] = false
|
||
opts.on("--#{collection}", "Retreive a list of #{collection}") do
|
||
opts.on("--#{collection}", "Retrieve a list of #{collection}") do
|
||
options[collection] = true
|
||
end
|
||
end
|
||
... | ... | |
puts " FOREMAN_USER Foreman user"
|
||
puts " FOREMAN_PASSWORD Foreman password"
|
||
puts ""
|
||
puts " CLI options take precendence over ENVIRONMENT VARIABLES"
|
||
puts " CLI options take precedence over ENVIRONMENT VARIABLES"
|
||
puts ""
|
||
puts " FILTERS:"
|
||
puts ""
|
||
... | ... | |
when "yaml"
|
||
YAML.dump(response)
|
||
else
|
||
(response.first.is_a?(Hash) ? response.map{|o| o.inspect} : response).join("\n")
|
||
r = response.first
|
||
if r.is_a?(Hash)
|
||
# we simply return host list
|
||
if r.first[0] == "host"
|
||
response.map{|h| h["host"]["name"]}
|
||
else
|
||
response.map{|o| o.inspect}
|
||
end
|
||
else
|
||
response.join("\n")
|
||
end
|
||
end)
|
||
end
|
||
|
||
options.each do |collection, filter|
|
||
next unless filter
|
||
if filter == true
|
||
if filter
|
||
print_response(get_collection(collection))
|
||
else
|
||
print_response(search_collection(collection, filter))
|
Also available in: Unified diff
Backported changed to foremancli to stable.