Sha256: 47a6430884cd29c0fd328be34d19578178eb4e5fd1dbe4385ccc5de813f7b02f
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
module Onering module CLI require 'yaml' require 'multi_json' @_args = {} def self.connect(cliargs) @_args = cliargs return Onering::API.new({ 'autoconnect' => cliargs[:autoconnect], 'config' => { 'url' => cliargs[:url], 'path' => cliargs[:path], 'authentication' => { 'type' => (cliargs[:apikey_given] ? :token : nil), 'keyfile' => (cliargs[:apikey] || cliargs[:sslkey]) }.compact }.compact }.compact) end def self.output(data, format) return nil if @_args[:quiet] case format when 'text' if data.is_a?(Hash) data.coalesce.each do |k,v| puts k.to_s+': '+v.to_s end 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.empty? end end end when 'json' puts MultiJson.dump(data) when 'yaml' puts YAML.dump(data) else raise "Unknown output format #{format.inspect}" end nil end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
onering-client-0.0.57 | lib/onering/cli.rb |
onering-client-0.0.56 | lib/onering/cli.rb |
onering-client-0.0.55 | lib/onering/cli.rb |