Class: DeployGate::Commands::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/deploygate/commands/config.rb

Class Method Summary collapse

Class Method Details

.login(name, token, json_format) ⇒ void

This method returns an undefined value.

Parameters:

  • name (String)
  • token (String)
  • json_format (Boolean)


29
30
31
32
33
34
35
36
37
# File 'lib/deploygate/commands/config.rb', line 29

def (name, token, json_format)
  if API::V1::Session.check(name, token)
    DeployGate::Session.save(name, token)
     = DeployGate::Session.new().
    (, json_format)
  else
    (json_format)
  end
end

This method returns an undefined value.

Parameters:

  • data (Hash)


105
106
107
# File 'lib/deploygate/commands/config.rb', line 105

def print_json(data)
  puts data.to_json
end

This method returns an undefined value.

Parameters:

  • json_format (Boolean)
  • data (Hash) (defaults to: {})


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/deploygate/commands/config.rb', line 57

def (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

This method returns an undefined value.

Parameters:

  • login_user (Hash)
  • json_format (Boolean)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/deploygate/commands/config.rb', line 42

def (, json_format)
  message = 'Login success'
  data = {:message => message, :error => false}

  unless json_format
    puts HighLine.color(message, HighLine::GREEN)
    puts ''
  end

  (, json_format, data)
end

This method returns an undefined value.

Parameters:

  • login_user (Hash)
  • json_format (Boolean)
  • data (Hash) (defaults to: {})


92
93
94
95
96
97
98
99
100
101
# File 'lib/deploygate/commands/config.rb', line 92

def (, json_format, data = {})
  data[:error] = data[:error].nil? ? false : data[:error]
  data[:name]  = ['name']

  if json_format
    print_json(data)
  else
    puts I18n.t('commands.config.print_login_user', name: data[:name])
  end
end

This method returns an undefined value.

Parameters:

  • json_format (Boolean)
  • data (Hash) (defaults to: {})


74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/deploygate/commands/config.rb', line 74

def (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) ⇒ Object

Parameters:

  • args (Array)
  • options (Commander::Command::Options)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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?
     = DeployGate::Session.new().
    if .nil?
      (json_format)
    else
      (, json_format)
    end
  else
    (name, token, json_format)
  end
end