Class: DeployGate::CommandBuilder

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/deploygate/command_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



4
5
6
# File 'lib/deploygate/command_builder.rb', line 4

def arguments
  @arguments
end

Instance Method Details

#check_updatevoid

This method returns an undefined value.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/deploygate/command_builder.rb', line 116

def check_update
  current_version = DeployGate::VERSION

  # check cache
  if DeployGate::Config::CacheVersion.exist?
    data = DeployGate::Config::CacheVersion.read
    if Time.parse(data['check_date']) > 1.day.ago
      # cache available
      latest_version = data['latest_version']
      if Gem::Version.new(latest_version) > Gem::Version.new(current_version)
        show_update_message(latest_version)
      end
    else
      request_gem_update_checker
    end
  else
    request_gem_update_checker
  end
end

#create_error_issue_body(error) ⇒ String

Parameters:

  • error (Exception)

Returns:

  • (String)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/deploygate/command_builder.rb', line 81

def create_error_issue_body(error)
  return <<EOF

# Status
deploygate-cli ver #{DeployGate::VERSION}

# Error message
#{error.message}

# Backtrace
```
#{error.backtrace.join("\n")}
```
EOF
end

#error_handling(title, body, labels = []) ⇒ Object

Parameters:

  • title (String)
  • body (String)
  • labels (Array) (defaults to: [])


100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/deploygate/command_builder.rb', line 100

def error_handling(title, body, labels = [])
  options = {
      :title => title,
      :body  => body,
      :labels => labels
  }
  url = GithubIssueRequest::Url.new(options).to_s
  puts ''
  if HighLine.agree('Do you want to report this issue on GitHub? (y/n) ') {|q| q.default = "n"}
    puts "Please open github issue: #{url}"
    system('open', url) if Commands::Deploy::Push.openable?
  end
  puts ''
end

#request_gem_update_checkervoid

This method returns an undefined value.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/deploygate/command_builder.rb', line 137

def request_gem_update_checker
  gem_name = DeployGate.name.downcase
  current_version = DeployGate::VERSION

  checker = GemUpdateChecker::Client.new(gem_name, current_version)
  if checker.update_available
    show_update_message(checker.latest_version)
  end
  cache_data = {
      :latest_version => checker.latest_version,
      :check_date => Time.now
  }
  DeployGate::Config::CacheVersion.write(cache_data)
end

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/deploygate/command_builder.rb', line 6

def run
  GithubIssueRequest::Url.config('deploygate', 'deploygate-cli')
  check_update()

  program :name, 'dg'
  program :version,  VERSION
  program :description, 'You can control to DeployGate in your terminal.'

  command :login do |c|
    c.syntax = 'dg login'
    c.description = 'DeployGate login command'
    c.action do |args, options|
      begin
        Commands::Login.run
      rescue => e
        error_handling("Commands::Login Error: #{e.class}", create_error_issue_body(e))
        raise e
      end
    end
  end

  command :deploy do |c|
    c.syntax = 'dg deploy /path/to/app'
    c.description = 'upload to deploygate'
    c.option '--message STRING', String, 'release message'
    c.option '--user STRING', String, 'owner name or group name'
    c.option '--distribution-key STRING', String, 'update distribution key'
    c.option '--open', 'open browser (OSX only)'
    c.option '--disable_notify', 'disable notify via email (iOS app only)'
    c.action do |args, options|
      options.default :message => '', :user => nil, :open => false, 'disable_notify' => false
      begin
        Commands::Deploy.run(args, options)
      rescue => e
        error_handling("Commands::Deploy Error: #{e.class}", create_error_issue_body(e))
        raise e
      end
    end
  end
  alias_command :'push', :deploy

  command :logout do |c|
    c.syntax = 'dg logout'
    c.description = 'logout'
    c.action do |args, options|
      begin
        Commands::Logout.run
      rescue => e
        error_handling("Commands::Logout Error: #{e.class}", create_error_issue_body(e))
        raise e
      end
    end
  end

  command :config do |c|
    c.syntax = 'dg config'
    c.description = 'dg user login config'
    c.option '--json', 'output json format'
    c.option '--name STRING', String, 'your DeployGate user name'
    c.option '--token STRING', String, 'your DeployGate api token'
    c.action do |args, options|
      begin
        Commands::Config.run(args, options)
      rescue => e
        error_handling("Commands::Config Error: #{e.class}", create_error_issue_body(e))
        raise e
      end
    end
  end

  run!
end

#show_update_message(latest_version) ⇒ void

This method returns an undefined value.

Parameters:

  • latest_version (String)


154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/deploygate/command_builder.rb', line 154

def show_update_message(latest_version)
  gem_name = DeployGate.name.downcase
  current_version = DeployGate::VERSION
  update_message =<<EOF

#################################################################
# #{gem_name} #{latest_version} is available. You are on #{current_version}.
# It is recommended to use the latest version.
# Update using 'gem update #{gem_name}'.
#################################################################

EOF
  DeployGate::Message::Warning.print(update_message)
end