class TerraformEnterprise::CommandLine::Command

Base class for all commands

Constants

CMD_STR

Public Instance Methods

client() click to toggle source
# File lib/terraform_enterprise/command_line/command.rb, line 46
def client
  settings         = {}
  settings[:token] = options[:token] || ENV['TFE_TOKEN']
  settings[:host]  = ENV['TFE_HOST'] if ENV['TFE_HOST']
  settings[:host]  = options[:host] if options[:host]
  settings[:debug] = options[:debug] || ENV['TFE_DEBUG']
  TerraformEnterprise::API::Client.new(settings)
end
error!(message) click to toggle source
# File lib/terraform_enterprise/command_line/command.rb, line 40
def error!(message)
  formatter = Formatter.new
  formatter.error(message)
  exit(false)
end
render(obj, default_options = {}) click to toggle source
# File lib/terraform_enterprise/command_line/command.rb, line 28
def render(obj, default_options = {})
  normalized_options = symbolize_keys(options.to_h)
  calculated_options =
    if options[:all]
      normalized_options
    else
      symbolize_keys(default_options).merge(normalized_options)
    end
  formatter = Formatter.new
  formatter.render obj, calculated_options
end
symbolize_keys(hash) click to toggle source
# File lib/terraform_enterprise/command_line/command.rb, line 57
def symbolize_keys(hash)
  JSON.parse(JSON[hash], symbolize_names: true)
end