Class: Honeybadger::CLI::Main
- Inherits:
-
Thor
- Object
- Thor
- Honeybadger::CLI::Main
show all
- Includes:
- Helpers
- Defined in:
- lib/honeybadger/cli/main.rb
Defined Under Namespace
Classes: HoneybadgerTestingException
Constant Summary
collapse
- NOT_BLANK =
Regexp.new('\S').freeze
Instance Method Summary
collapse
Methods included from Helpers
#load_rails, #load_rails_env, #rails?, #rails_framework_opts, #rails_test, #send_test, #standalone_test, #test_exception_class
Instance Method Details
#config ⇒ Object
59
60
61
62
63
|
# File 'lib/honeybadger/cli/main.rb', line 59
def config
load_rails
config = Config.new(rails_framework_opts)
output_config(config.to_hash(options[:default]))
end
|
#deploy ⇒ Object
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
|
# File 'lib/honeybadger/cli/main.rb', line 20
def deploy
load_rails(verbose: true)
payload = Hash[[:environment, :revision, :repository].map {|k| [k, options[k]] }]
payload[:local_username] = options[:user]
ENV['HONEYBADGER_LOGGING_LEVEL'] = '2'
ENV['HONEYBADGER_LOGGING_TTY_LEVEL'] = '0'
ENV['HONEYBADGER_LOGGING_PATH'] = 'STDOUT'
ENV['HONEYBADGER_REPORT_DATA'] = 'true'
say('Loading configuration')
config = Config.new(rails_framework_opts)
config.update(api_key: options[:api_key]) if options[:api_key] =~ NOT_BLANK
unless (payload[:environment] ||= config[:env]) =~ NOT_BLANK
say('Unable to determine environment. (see: `honeybadger help deploy`)', :red)
exit(1)
end
unless config.valid?
say("Invalid configuration: #{config.inspect}", :red)
exit(1)
end
response = config.backend.notify(:deploys, payload)
if response.success?
say("Deploy notification for #{payload[:environment]} complete.", :green)
else
say("Deploy notification failed: #{response.code}", :red)
exit(1)
end
rescue => e
say("An error occurred during deploy notification: #{e}\n\t#{e.backtrace.join("\n\t")}", :red)
exit(1)
end
|
#install(api_key) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/honeybadger/cli/main.rb', line 116
def install(api_key)
say("Installing Honeybadger #{VERSION}")
load_rails(verbose: true)
ENV['HONEYBADGER_LOGGING_LEVEL'] = '2'
ENV['HONEYBADGER_LOGGING_TTY_LEVEL'] = '0'
ENV['HONEYBADGER_LOGGING_PATH'] = 'STDOUT'
ENV['HONEYBADGER_REPORT_DATA'] = 'true'
config = Config.new(rails_framework_opts)
config[:api_key] = api_key.to_s
if (path = config.config_path).exist?
say("You're already on Honeybadger, so you're all set.", :yellow)
else
say("Writing configuration to: #{path}", :yellow)
begin
config.write
rescue Config::ConfigError => e
error("Error: Unable to write configuration file:\n\t#{e}")
return
rescue StandardError => e
error("Error: Unable to write configuration file:\n\t#{e.class} -- #{e.message}\n\t#{e.backtrace.join("\n\t")}")
return
end
end
if (capfile = Pathname.new(config[:root]).join('Capfile')).exist?
if capfile.read.match(/honeybadger/)
say("Detected Honeybadger in Capfile; skipping Capistrano installation.", :yellow)
else
say("Appending Capistrano tasks to: #{capfile}", :yellow)
File.open(capfile, 'a') do |f|
f.puts("\nrequire 'capistrano/honeybadger'")
end
end
end
if options[:test].nil? || options[:test]
Honeybadger.start(config) unless load_rails_env(verbose: true)
say('Sending test notice', :yellow)
unless Agent.instance && send_test(false)
say('Honeybadger is installed, but failed to send a test notice. Try `honeybadger test`.', :red)
exit(1)
end
end
say("Installation complete. Happy 'badgering!", :green)
end
|
#test ⇒ Object
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
108
109
110
111
112
|
# File 'lib/honeybadger/cli/main.rb', line 68
def test
if options[:file]
out = StringIO.new
$stdout = out
flush = Proc.new do
$stdout = STDOUT
File.open(options[:file], 'w+') do |f|
out.rewind
out.each_line {|l| f.write(l) }
end
say("Output written to #{options[:file]}", :green)
end
Agent.at_exit(&flush)
at_exit do
flush.() unless Agent.running?
end
end
say("Detecting framework\n\n", :bold)
load_rails(verbose: true)
ENV['HONEYBADGER_LOGGING_LEVEL'] = '0'
ENV['HONEYBADGER_LOGGING_TTY_LEVEL'] = '0'
ENV['HONEYBADGER_LOGGING_PATH'] = 'STDOUT'
ENV['HONEYBADGER_DEBUG'] = 'true'
ENV['HONEYBADGER_REPORT_DATA'] = options[:dry_run] ? 'false' : 'true'
config = Config.new(rails_framework_opts)
say("\nConfiguration\n\n", :bold)
output_config(config.to_hash)
say("\nStarting Honeybadger\n\n", :bold)
Honeybadger.start(config) unless load_rails_env(verbose: true)
say("\nSending test notice\n\n", :bold)
send_test
say("\nRunning at exit hooks\n\n", :bold)
end
|