class DeployGate::Commands::Config
Public Class Methods
login(name, token, json_format)
click to toggle source
@param [String] name @param [String] token @param [Boolean] json_format @return [void]
# File lib/deploygate/commands/config.rb, line 29 def login(name, token, json_format) if API::V1::Session.check(name, token) DeployGate::Session.save(name, token) login_user = DeployGate::Session.new().show_login_user print_login_success(login_user, json_format) else print_login_failed(json_format) end end
print_json(data)
click to toggle source
@param [Hash] data @return [void]
# File lib/deploygate/commands/config.rb, line 105 def print_json(data) puts data.to_json end
print_login_failed(json_format, data = {})
click to toggle source
@param [Boolean] json_format @param [Hash] data @return [void]
# File lib/deploygate/commands/config.rb, line 57 def print_login_failed(json_format, data = {}) message = I18n.t('commands.config.print_login_failed.message') data[:error] = true data[:message] = message if json_format print_json(data) else puts HighLine.color(message, HighLine::RED) puts '' puts I18n.t('commands.config.print_login_failed.note') end end
print_login_success(login_user, json_format)
click to toggle source
@param [Hash] login_user @param [Boolean] json_format @return [void]
# File lib/deploygate/commands/config.rb, line 42 def print_login_success(login_user, json_format) message = 'Login success' data = {:message => message, :error => false} unless json_format puts HighLine.color(message, HighLine::GREEN) puts '' end print_login_user(login_user, json_format, data) end
print_login_user(login_user, json_format, data = {})
click to toggle source
@param [Hash] login_user @param [Boolean] json_format @param [Hash] data @return [void]
# File lib/deploygate/commands/config.rb, line 92 def print_login_user(login_user, json_format, data = {}) data[:error] = data[:error].nil? ? false : data[:error] data[:name] = login_user['name'] if json_format print_json(data) else puts I18n.t('commands.config.print_login_user', name: data[:name]) end end
print_not_login(json_format, data = {})
click to toggle source
@param [Boolean] json_format @param [Hash] data @return [void]
# File lib/deploygate/commands/config.rb, line 74 def print_not_login(json_format, data = {}) message = I18n.t('commands.config.print_not_login.message') data[:error] = true data[:message] = message if json_format print_json(data) else puts HighLine.color(message, HighLine::YELLOW) puts '' puts I18n.t('commands.config.print_not_login.note') end end
run(args, options)
click to toggle source
@param [Array] args @param [Commander::Command::Options] options
# File lib/deploygate/commands/config.rb, line 8 def run(args, options) json_format = options.json name = options.name token = options.token if name.nil? || token.nil? login_user = DeployGate::Session.new().show_login_user if login_user.nil? print_not_login(json_format) else print_login_user(login_user, json_format) end else login(name, token, json_format) end end