module Gcloud::Cli::ConfigRepository

Constants

CONFIG_FILE
DEFAULT_URL

Public Instance Methods

find_or_create() click to toggle source
# File lib/gcloud/cli/config_repository.rb, line 12
def find_or_create
  load || prompt
end

Private Instance Methods

load() click to toggle source
# File lib/gcloud/cli/config_repository.rb, line 35
def load
  return YAML.load_file(CONFIG_FILE)
rescue Errno::ENOENT => _
  return false
end
prompt() click to toggle source
# File lib/gcloud/cli/config_repository.rb, line 18
def prompt
  puts "Could not find a valid config file. Creating one at #{CONFIG_FILE}"

  url = ask "URL for GCloud: " do |q|
    q.default = DEFAULT_URL
  end

  api_key = ask "API Key: " do |q|
    q.validate = /\w+/
  end

  config = Config.new(url, api_key)
  save(config)

  return config
end
save(config) click to toggle source
# File lib/gcloud/cli/config_repository.rb, line 41
def save(config)
  File.open(CONFIG_FILE, 'w') do |file|
    file.write(YAML.dump(config))
  end
end