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
|
# File 'lib/nadir/cli.rb', line 9
def run
program :name, 'nadir'
program :version, Nadir::VERSION
program :description, 'Ruby/Rails client for Nadir'
never_trace!
command 'setup' do |c|
c.syntax = 'nadir setup API-KEY'
c.description = 'Creates Nadir\'s configuration file config/nadir.yml and populates it with the provided API-KEY.'
c.action do |args, _options|
api_key = args[0]
if File.exist? config_file_path
say_error 'Nadir config file already exists.'
exit(0)
end
unless api_key
say_error 'Please provide an API KEY.'
exit(0)
end
configuration_file = " ---\n api_key: \#{api_key}\n YAML\n\n File.open(config_file_path, 'w') { |file| file.write(configuration_file) }\n\n say_success <<~MSG\n Nadir client configured successfully!\n\n Test the integration by sending a test notification:\n\n bundle exec nadir test-notify\n\n If all is well, you'll see the test notification in https://nadir.dev.\n MSG\n end\n end\n\n command 'test-notify' do |c|\n c.syntax = 'nadir test-notify'\n c.description = 'Send a test notification to Nadir'\n c.action do |args, _options|\n require File.expand_path('config/environment')\n\n Nadir.configure do |config|\n config.enabled_for << 'development'\n end\n\n begin\n raise NadirTestException.new('Test message')\n rescue NadirTestException => e\n if Nadir.notify e, location: 'nadir test-notify'\n say_success 'Test notification sent successfully.'\n else\n say_error 'Test notification could not be delivered.'\n end\n\n Nadir::Transport::HTTPAsync.shut_down\n end\n end\n end\n\n run!\nend\n"
|