class Cloudcost::CLI
Constants
- Error
Error
raised by this runner
Public Class Methods
exit_on_failure?()
click to toggle source
# File lib/cloudcost/cli.rb, line 11 def self.exit_on_failure? true end
Public Instance Methods
api_connection(options)
click to toggle source
# File lib/cloudcost/cli.rb, line 105 def api_connection(options) api_token = options[:api_token] || Cloudcost::ApiToken.new(options).token Cloudcost::ApiConnection.new(api_token, options) end
load_servers(options)
click to toggle source
# File lib/cloudcost/cli.rb, line 110 def load_servers(options) spinner = TTY::Spinner.new("[:spinner] Loading servers...", clear: options[:csv]) spinner.auto_spin servers = api_connection(options).get_servers(options).map { |server| Server.new(server) } spinner.success "(#{servers.size} found)" servers end
output(servers, options) { |server_list.to_csv| ... }
click to toggle source
# File lib/cloudcost/cli.rb, line 118 def output(servers, options) if options[:output] == "csv" yield Cloudcost::ServerList.new(servers, options).to_csv else yield Cloudcost::ServerList.new(servers, options).cost_table end end
servers()
click to toggle source
# File lib/cloudcost/cli.rb, line 34 def servers servers = load_servers(options) spinner = TTY::Spinner.new("[:spinner] Calculating costs...", clear: options[:csv]) spinner.auto_spin output(servers, options) do |result| spinner.success "(done)" puts puts result end rescue Excon::Error, TokenError, ProfileError, PricingError => e error_message = "ERROR: #{e.message}" if spinner spinner.error("(#{error_message})") else puts error_message end end
tag_option_to_s(options)
click to toggle source
# File lib/cloudcost/cli.rb, line 126 def tag_option_to_s(options) messages = [] messages << "set tags \"#{options[:set_tags].join(", ")}\"" if options[:set_tags] messages << "remove tags \"#{options[:remove_tags].join(", ")}\"" if options[:remove_tags] messages.join(" and ") end
version()
click to toggle source
# File lib/cloudcost/cli.rb, line 24 def version puts "cloudcost v#{Cloudcost::VERSION}" end