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)


112
113
114
# File 'lib/deploygate/commands/config.rb', line 112

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
70
71
# File 'lib/deploygate/commands/config.rb', line 57

def (json_format, data = {})
  message = 'Login failed'
  data[:error]   = true
  data[:message] = message

  if json_format
    print_json(data)
  else
    DeployGate::Message::Error.print(message)
    puts <<EOF

Please check your name and api token.
EOF
  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
    DeployGate::Message::Success.print(message)
    puts ''
  end

  (, json_format, data)
end

This method returns an undefined value.

Parameters:

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


97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/deploygate/commands/config.rb', line 97

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

  if json_format
    print_json(data)
  else
    puts <<EOF
User name: #{data[:name]}
EOF
  end
end

This method returns an undefined value.

Parameters:

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


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/deploygate/commands/config.rb', line 76

def (json_format, data = {})
  message = 'Not user login'
  data[:error]   = true
  data[:message] = message

  if json_format
    print_json(data)
  else
    DeployGate::Message::Warning.print(message)
    puts <<EOF

Please login to dg command.
$ dg login
EOF
  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