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

#arguments ⇒ Object (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_update ⇒ void

This method returns an undefined value.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/deploygate/command_builder.rb', line 138

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)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/deploygate/command_builder.rb', line 103

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: [])


122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/deploygate/command_builder.rb', line 122

def error_handling(title, body, labels = [])
  options = {
      :title => title,
      :body  => body,
      :labels => labels
  }
  url = GithubIssueRequest::Url.new(options).to_s
  puts ''
  if HighLine.agree(I18n.t('command_builder.error_handling.agree')) {|q| q.default = "n"}
    puts I18n.t('command_builder.error_handling.please_open', url: url)
    system('open', url) if Commands::Deploy::Push.openable?
  end
  puts ''
end

#request_gem_update_checker ⇒ void

This method returns an undefined value.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/deploygate/command_builder.rb', line 159

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

#run ⇒ Object



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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/deploygate/command_builder.rb', line 6

def run
  Signal.trap(:INT){
    puts ''
    exit 0
  }

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

  program :name, I18n.t('command_builder.name')
  program :version,  VERSION
  program :description, I18n.t('command_builder.description')

  command :login do |c|
    c.syntax = 'dg login'
    c.description = I18n.t('command_builder.login.description')
    c.action do |args, options|
      begin
        Commands::Login.run
      rescue => e
        error_handling(I18n.t('command_builder.login.error', e: 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 = I18n.t('command_builder.deploy.description')
    c.option '--message STRING', String, I18n.t('command_builder.deploy.message')
    c.option '--user STRING', String, I18n.t('command_builder.deploy.user')
    c.option '--distribution-key STRING', String, I18n.t('command_builder.deploy.distribution_key')
    c.option '--open', I18n.t('command_builder.deploy.open')
    c.option '--disable_notify', I18n.t('command_builder.deploy.disable_notify')
    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(I18n.t('command_builder.deploy.error', e: e.class), create_error_issue_body(e))
        raise e
      end
    end
  end
  alias_command :'push', :deploy

  command 'add-devices' do |c|
    c.syntax = 'dg add-devices'
    c.description = I18n.t('command_builder.add_devices.description')
    c.option '--user STRING', String, I18n.t('command_builder.add_devices.user')
    c.option '--udid STRING', String, I18n.t('command_builder.add_devices.udid')
    c.option '--device-name STRING', String, I18n.t('command_builder.add_devices.device_name')
    c.action do |args, options|
      options.default :user => nil
      begin
        Commands::AddDevices.run(args, options)
      rescue => e
        error_handling(I18n.t('command_builder.add_devices.error', e: e.class), create_error_issue_body(e))
        raise e
      end
    end
  end

  command :logout do |c|
    c.syntax = 'dg logout'
    c.description = I18n.t('command_builder.logout.description')
    c.action do |args, options|
      begin
        Commands::Logout.run
      rescue => e
        error_handling(I18n.t('command_builder.logout.error', e: e.class), create_error_issue_body(e))
        raise e
      end
    end
  end

  command :config do |c|
    c.syntax = 'dg config'
    c.description = I18n.t('command_builder.config.description')
    c.option '--json', I18n.t('command_builder.config.json')
    c.option '--name STRING', String, I18n.t('command_builder.config.name')
    c.option '--token STRING', String, I18n.t('command_builder.config.token')
    c.action do |args, options|
      begin
        Commands::Config.run(args, options)
      rescue => e
        error_handling(I18n.t('command_builder.config.error', e: 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)


176
177
178
179
180
181
182
# File 'lib/deploygate/command_builder.rb', line 176

def show_update_message(latest_version)
  gem_name = DeployGate.name.downcase
  current_version = DeployGate::VERSION
  STDERR.puts ''
  STDERR.puts HighLine.color(I18n.t('command_builder.show_update_message', gem_name: gem_name, latest_version: latest_version, current_version: current_version), HighLine::YELLOW)
  STDERR.puts ''
end