In my script I use ARGV stream to get command-line arguments. There is a piece of code:
ARGV.each do|a|
item = JSON.parse(%x{curl -X GET https://puppetdb.ai:8081/pdb/query/v4/facts/#{a} --tlsv1 --interface x.x.x.x --cacert certificate.pem --cert certificate-pem.cer --key certificate-privkey.pem})
item.each do |h|
arr << {"name" => h['certname'], "#{a}" => h['value'], "environment" => h['environment']}
end
end
With curl I get some data using puppetdb API. It all works fine, bu I've wanted to add some if statement to print help for script. It looks like that:
ARGV.each do|a|
if (a == "help")
puts "this is help 4 U"
else
item = JSON.parse(%x{curl -X GET https://puppetdb.ai:8081/pdb/query/v4/facts/#{a} --tlsv1 --interface x.x.x.x --cacert certificate.pem --cert certificate-pem.cer --key certificate-privkey.pem})
item.each do |h|
arr << {"name" => h['certname'], "#{a}" => h['value'], "environment" => h['environment']}
end
end
end
but the script ignore "help" and fills in "help" argument to curl. Can you help me with this?