Class: DeployGate::CommandBuilder
- Inherits:
-
Object
- Object
- DeployGate::CommandBuilder
- Includes:
- Commander::Methods
- Defined in:
- lib/deploygate/command_builder.rb
Constant Summary collapse
- LOGIN =
'login'
- LOGOUT =
'logout'
- DEPLOY =
'deploy'
- ADD_DEVICES =
'add-devices'
- CONFIG =
'config'
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
Instance Method Summary collapse
- #check_update ⇒ void
- #create_error_issue_body(error) ⇒ String
- #create_issue_url(command, error) ⇒ String
- #error_handling(command, error) ⇒ Object
- #request_gem_update_checker ⇒ void
- #run ⇒ Object
- #show_update_message(latest_version) ⇒ void
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.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/deploygate/command_builder.rb', line 166 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) (latest_version) end else request_gem_update_checker end else request_gem_update_checker end end |
#create_error_issue_body(error) ⇒ String
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/deploygate/command_builder.rb', line 111 def create_error_issue_body(error) return <<EOF # Status deploygate-cli ver #{DeployGate::VERSION} # Error message #{error.} # Backtrace ``` #{error.backtrace.join("\n")} ``` EOF end |
#create_issue_url(command, error) ⇒ String
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/deploygate/command_builder.rb', line 130 def create_issue_url(command, error) title = case command when LOGIN I18n.t('command_builder.login.error', e: error.class) when LOGOUT I18n.t('command_builder.logout.error', e: error.class) when DEPLOY I18n.t('command_builder.deploy.error', e: error.class) when ADD_DEVICES I18n.t('command_builder.add_devices.error', e: error.class) when CONFIG I18n.t('command_builder.config.error', e: error.class) end = { :title => title, :body => create_error_issue_body(error), } GithubIssueRequest::Url.new().to_s end |
#error_handling(command, error) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/deploygate/command_builder.rb', line 153 def error_handling(command, error) STDERR.puts HighLine.color(I18n.t('command_builder.error_handling.message', message: error.), HighLine::RED) puts '' if HighLine.agree(I18n.t('command_builder.error_handling.agree')) {|q| q.default = "n"} url = create_issue_url(command, error) 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.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/deploygate/command_builder.rb', line 187 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 (checker.latest_version) end cache_data = { :latest_version => checker.latest_version, :check_date => Time.now } DeployGate::Config::CacheVersion.write(cache_data) end |
#run ⇒ Object
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 100 101 102 103 104 105 106 107 |
# File 'lib/deploygate/command_builder.rb', line 12 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.option '--terminal', I18n.t('command_builder.login.terminal') c.action do |args, | .default :terminal => false begin Commands::Login.run(args, ) rescue => e error_handling(LOGIN, 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, | .default :message => '', :user => nil, :open => false, 'disable_notify' => false begin Commands::Deploy.run(args, ) rescue => e error_handling(DEPLOY, 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, | .default :user => nil begin Commands::AddDevices.run(args, ) rescue => e error_handling(ADD_DEVICES, 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, | begin Commands::Logout.run rescue => e error_handling(LOGOUT, 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, | begin Commands::Config.run(args, ) rescue => e error_handling(CONFIG, e) raise e end end end run! end |
#show_update_message(latest_version) ⇒ void
This method returns an undefined value.
204 205 206 207 208 209 210 |
# File 'lib/deploygate/command_builder.rb', line 204 def (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 |