class Hexlet::BaseCLI

Constants

CONFIG_DIR

include Thor::Shell::Basic

CREDENTIALS_FILE

Public Instance Methods

config() click to toggle source
# File lib/hexlet/base_cli.rb, line 36
def config
  if File.file?(CREDENTIALS_FILE)
    YAML.load_file(CREDENTIALS_FILE)
  else
    {}
  end
end
logger() click to toggle source
# File lib/hexlet/base_cli.rb, line 24
def logger
  logger = Logger.new(STDOUT)
  logger.level = options[:verbose] ? Logger::DEBUG : Logger::INFO
  logger
end
login(key) click to toggle source
# File lib/hexlet/base_cli.rb, line 13
def login(key)
  client = build_client(key)
  if client.login
    puts (t :ok)
    write_config("hexlet_api_key" => key)
  else
    puts (t :not_found)
  end
end
t(key, options = {}) click to toggle source
# File lib/hexlet/base_cli.rb, line 30
def t key, options = {}
  command_name =  @_invocations.values.last.last
  ns = self.class.to_s.downcase.split("::").last
  I18n.t key, options.merge(scope: [ns, command_name])
end
write_config(data) click to toggle source
# File lib/hexlet/base_cli.rb, line 44
def write_config(data)
  FileUtils.mkdir_p(CONFIG_DIR)
  File.open(CREDENTIALS_FILE, 'w') do |f|
    f.write data.to_yaml
  end
  # TODO puts (I18n.t "update_config")
end