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.



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

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)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/deploygate/command_builder.rb', line 64

def create_error_issue_body(error)
  return "\n# Status\ndeploygate-cli ver \#{DeployGate::VERSION}\n\n# Error message\n\#{error.message}\n\n# Backtrace\n```\n\#{error.backtrace.join(\"\\n\")}\n```\n"
end

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

Parameters:

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


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

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.



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

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
# 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 :init do |c|
    c.syntax = 'dg init'
    c.description = 'project initial command'
    c.action do |args, options|
      begin
        Commands::Init.run
      rescue => e
        error_handling("Commands::Init 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 '--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

  run!
end

#show_update_message(latest_version) ⇒ void

This method returns an undefined value.

Parameters:

  • latest_version (String)


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

def show_update_message(latest_version)
  gem_name = DeployGate.name.downcase
  current_version = DeployGate::VERSION
  update_message ="\n#################################################################\n# \#{gem_name} \#{latest_version} is available. You are on \#{current_version}.\n# It is recommended to use the latest version.\n# Update using 'gem update \#{gem_name}'.\n#################################################################\n\n"
  DeployGate::Message::Warning.print(update_message)
end