greenhat 0.1.5 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/greenhat/accessors/disk.rb +58 -2
- data/lib/greenhat/accessors/gitlab.rb +75 -0
- data/lib/greenhat/accessors/memory.rb +10 -10
- data/lib/greenhat/accessors/process.rb +10 -1
- data/lib/greenhat/cli.rb +148 -63
- data/lib/greenhat/color.rb +27 -0
- data/lib/greenhat/logbot.rb +9 -9
- data/lib/greenhat/settings.rb +51 -3
- data/lib/greenhat/shell/args.rb +146 -0
- data/lib/greenhat/shell/cat.rb +25 -73
- data/lib/greenhat/shell/color_string.rb +43 -0
- data/lib/greenhat/shell/disk.rb +30 -42
- data/lib/greenhat/shell/faststats.rb +104 -58
- data/lib/greenhat/shell/field_helper.rb +75 -0
- data/lib/greenhat/shell/filter_help.rb +162 -0
- data/lib/greenhat/shell/gitlab.rb +61 -2
- data/lib/greenhat/shell/help.rb +98 -15
- data/lib/greenhat/shell/list.rb +46 -0
- data/lib/greenhat/shell/log.rb +115 -209
- data/lib/greenhat/shell/page.rb +39 -0
- data/lib/greenhat/shell/process.rb +57 -2
- data/lib/greenhat/shell/report.rb +70 -60
- data/lib/greenhat/shell/shell_helper.rb +654 -0
- data/lib/greenhat/shell.rb +27 -13
- data/lib/greenhat/thing/file_types.rb +54 -7
- data/lib/greenhat/thing/formatters/json_shellwords.rb +0 -3
- data/lib/greenhat/thing/formatters/nginx.rb +44 -0
- data/lib/greenhat/thing/formatters/syslog.rb +39 -0
- data/lib/greenhat/thing/helpers.rb +4 -4
- data/lib/greenhat/thing/kind.rb +9 -2
- data/lib/greenhat/thing/spinner.rb +3 -3
- data/lib/greenhat/thing.rb +25 -3
- data/lib/greenhat/tty/columns.rb +44 -0
- data/lib/greenhat/version.rb +1 -1
- data/lib/greenhat.rb +16 -14
- metadata +42 -17
- data/lib/greenhat/shell/helper.rb +0 -541
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db336e98cd2a446c371d866d068eb9b485f9782b2ea7182f4b4da651011e2083
|
4
|
+
data.tar.gz: 90b1858171c14ebe93e3a0ff42dffe2965602835f8f2cc98178f6a81ec816352
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d78c52d3e4b800ac90798d8030dfa9962c7e7c628bd8b636f5471fcf2c35044aa044a91edbd412827db2daf36117ab47cfecc4c6a85e49875e3e6d7756e1d0
|
7
|
+
data.tar.gz: fad9f87be4735b5d028ccc7e251fce423de9cf0d440253b65dbaddbc36b268234ffedc7277f9207131692bcf8ea74cd9a4b70c433f55e158b6cd30aae73edf1d
|
@@ -20,8 +20,64 @@ module GreenHat
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.df
|
24
|
-
Thing.where(name: 'df_h')
|
23
|
+
def self.df(args = {})
|
24
|
+
things = Thing.where(name: 'df_h')
|
25
|
+
|
26
|
+
# Host / Archive
|
27
|
+
things.select! { |x| x.archive? args.archive } if args.archive
|
28
|
+
|
29
|
+
things
|
30
|
+
end
|
31
|
+
|
32
|
+
# Unified Output Handler
|
33
|
+
# rubocop:disable Metrics/MethodLength
|
34
|
+
def self.format_output(file, name = false, limit = nil, filter = %w[tmpfs loop])
|
35
|
+
output = []
|
36
|
+
|
37
|
+
output << file.friendly_name if name
|
38
|
+
|
39
|
+
# Reject TMPFS
|
40
|
+
disks = file.data.sort_by { |x| x.use.to_i }.reverse
|
41
|
+
|
42
|
+
# Filter
|
43
|
+
disks.reject! { |x| filter.any? { |y| x.filesystem.include? y } }
|
44
|
+
|
45
|
+
disks = disks[0..limit - 1] if limit
|
46
|
+
|
47
|
+
pad_mount, pad_size, pad_used, pad_avail = GreenHat::Disk.padding(disks)
|
48
|
+
|
49
|
+
# Headers
|
50
|
+
output << [
|
51
|
+
'Mount'.ljust(pad_mount).pastel(:blue),
|
52
|
+
'Size'.ljust(pad_size).pastel(:magenta),
|
53
|
+
'Used'.ljust(pad_used).pastel(:cyan),
|
54
|
+
'Avail'.ljust(pad_avail).pastel(:white),
|
55
|
+
'% Use'.ljust(pad_avail).pastel(:green)
|
56
|
+
].join
|
57
|
+
|
58
|
+
# Table Summary
|
59
|
+
disks.map do |disk|
|
60
|
+
# Pretty Disk Use
|
61
|
+
use = [
|
62
|
+
disk.use.rjust(5).ljust(5).pastel(:green),
|
63
|
+
' ['.pastel(:blue),
|
64
|
+
('=' * (disk.use.to_i / 2)).pastel(:green),
|
65
|
+
' ' * (50 - disk.use.to_i / 2),
|
66
|
+
']'.pastel(:blue)
|
67
|
+
].join
|
68
|
+
|
69
|
+
# Whole Thing
|
70
|
+
output << [
|
71
|
+
disk.mounted_on.ljust(pad_mount).pastel(:blue),
|
72
|
+
disk[:size].to_s.ljust(pad_size).pastel(:magenta),
|
73
|
+
disk.used.to_s.ljust(pad_used).pastel(:cyan),
|
74
|
+
disk.avail.to_s.ljust(pad_avail).pastel(:white),
|
75
|
+
use
|
76
|
+
].join
|
77
|
+
end
|
78
|
+
|
79
|
+
output
|
25
80
|
end
|
81
|
+
# rubocop:enable Metrics/MethodLength
|
26
82
|
end
|
27
83
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module GreenHat
|
2
|
+
# GitLab App Helpers
|
3
|
+
module GitLab
|
4
|
+
def self.node_types
|
5
|
+
[
|
6
|
+
{
|
7
|
+
name: 'Web Service', pattern: %w[puma unicorn]
|
8
|
+
},
|
9
|
+
{
|
10
|
+
name: 'Sidekiq', pattern: %w[sidekiq]
|
11
|
+
},
|
12
|
+
{
|
13
|
+
name: 'Gitaly', pattern: %w[gitaly]
|
14
|
+
},
|
15
|
+
{
|
16
|
+
name: 'Redis', pattern: %w[redis]
|
17
|
+
},
|
18
|
+
{
|
19
|
+
name: 'PostgreSQL', pattern: %w[postgresql]
|
20
|
+
},
|
21
|
+
{
|
22
|
+
name: 'PGBouncer', pattern: %w[pgbouncer]
|
23
|
+
}
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.identify_node(archive)
|
28
|
+
gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' }&.data&.keys
|
29
|
+
hostname = archive.things.find { |x| x.type == 'hostname' }.data.first
|
30
|
+
|
31
|
+
{
|
32
|
+
host: hostname,
|
33
|
+
services: gitlab_status || []
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
# Show GitLab Services in a grid / include versions
|
38
|
+
def self.services(archive, indent = 0)
|
39
|
+
manifest = archive.things.find { |x| x.type == 'gitlab/version-manifest.json' }
|
40
|
+
gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' }
|
41
|
+
|
42
|
+
return nil unless gitlab_status
|
43
|
+
|
44
|
+
list = gitlab_status.data.keys.sort.map do |service|
|
45
|
+
color = gitlab_status.data.dig(service, 0, :status) == 'run' ? :green : :red
|
46
|
+
|
47
|
+
# Collect Service version from manifest
|
48
|
+
version = manifest.data.software[service.to_sym]&.display_version
|
49
|
+
|
50
|
+
# If able to identify version use / fallback
|
51
|
+
if version
|
52
|
+
[
|
53
|
+
service.pastel(color),
|
54
|
+
"(#{version})".pastel(:bright_black)
|
55
|
+
].join(' ')
|
56
|
+
else
|
57
|
+
service.pastel(color)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Keep Alphabetical Sort
|
62
|
+
groups = list.each_slice((list.size / 3.to_f).round).to_a
|
63
|
+
|
64
|
+
table = TTY::Table.new do |t|
|
65
|
+
loop do
|
66
|
+
break if groups.all?(&:empty?)
|
67
|
+
|
68
|
+
t << groups.map(&:shift)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
table.render(:unicode, padding: [0, 1, 0, 1], indent: indent)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -18,24 +18,24 @@ module GreenHat
|
|
18
18
|
used_name = number_to_human_size(mem.used.to_i.megabytes)
|
19
19
|
|
20
20
|
bar = [
|
21
|
-
'|'.
|
22
|
-
'|'.
|
23
|
-
'|'.
|
21
|
+
'|'.pastel(:green) * percentage(mem.used, total),
|
22
|
+
'|'.pastel(:blue) * percentage(mem.shared, total),
|
23
|
+
'|'.pastel(:cyan) * percentage(mem.buffcache, total),
|
24
24
|
' ' * percentage(mem.free, total)
|
25
25
|
].join
|
26
26
|
|
27
27
|
# Make Even
|
28
|
-
padding = 125 - bar.
|
28
|
+
padding = 125 - bar.unpastel.size
|
29
29
|
bar += ' ' * padding if padding.positive?
|
30
30
|
|
31
31
|
[
|
32
|
-
mem.kind.ljust(4).
|
33
|
-
' ['.
|
32
|
+
mem.kind.ljust(4).pastel(:cyan),
|
33
|
+
' ['.pastel(:bright_black),
|
34
34
|
bar.ljust(120),
|
35
|
-
used_name.
|
36
|
-
' / '.
|
37
|
-
total_name.
|
38
|
-
']'.
|
35
|
+
used_name.pastel(:magenta),
|
36
|
+
' / '.pastel(:bright_black),
|
37
|
+
total_name.pastel(:blue),
|
38
|
+
']'.pastel(:bright_black)
|
39
39
|
].join
|
40
40
|
end
|
41
41
|
|
@@ -1,7 +1,16 @@
|
|
1
1
|
module GreenHat
|
2
2
|
# Sidekiq Log Helpers
|
3
3
|
module Ps
|
4
|
-
def self.ps
|
4
|
+
def self.ps(args)
|
5
|
+
things = Thing.where(name: 'ps')
|
6
|
+
|
7
|
+
# Host / Archive
|
8
|
+
things.select! { |x| x.archive? args.archive } if args.archive
|
9
|
+
|
10
|
+
things
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.things
|
5
14
|
Thing.where(name: 'ps')
|
6
15
|
end
|
7
16
|
end
|
data/lib/greenhat/cli.rb
CHANGED
@@ -54,7 +54,9 @@ module GreenHat
|
|
54
54
|
|
55
55
|
# DEBUG PRY
|
56
56
|
reader.on(:keyctrl_p) do |event|
|
57
|
+
# rubocop:disable Lint/Debugger
|
57
58
|
binding.pry
|
59
|
+
# rubocop:enable Lint/Debugger
|
58
60
|
end
|
59
61
|
reader
|
60
62
|
end
|
@@ -63,7 +65,9 @@ module GreenHat
|
|
63
65
|
# Auto Complete
|
64
66
|
# =========================================================
|
65
67
|
def self.auto
|
66
|
-
word =
|
68
|
+
word = @list.last
|
69
|
+
# This is being weird with auto complete
|
70
|
+
# word = reader.line.word
|
67
71
|
|
68
72
|
if word.blank?
|
69
73
|
help
|
@@ -72,6 +76,10 @@ module GreenHat
|
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
79
|
+
def self.file_matches(word)
|
80
|
+
files.select { |x| x[/^#{Regexp.escape(word)}/] }
|
81
|
+
end
|
82
|
+
|
75
83
|
def self.auto_match(matches, word)
|
76
84
|
matches.select! { |x| x[/^#{Regexp.escape(word)}/] }
|
77
85
|
|
@@ -84,13 +92,16 @@ module GreenHat
|
|
84
92
|
|
85
93
|
# Print List of Options
|
86
94
|
elsif matches.count > 1
|
87
|
-
puts matches.join("\t").
|
95
|
+
puts matches.join("\t").pastel(:bright_green)
|
88
96
|
|
89
|
-
#
|
90
|
-
|
91
|
-
file_matches
|
92
|
-
auto_files(file_matches, word) unless file_matches.empty?
|
97
|
+
# General Filename Matching
|
98
|
+
elsif !file_matches(word).empty?
|
99
|
+
auto_files(file_matches(word), word)
|
93
100
|
|
101
|
+
# Submodule Autocompletion
|
102
|
+
elsif current_methods.include?('auto_complete')
|
103
|
+
update_text = current_location.auto_complete(@list, word)
|
104
|
+
auto_update(update_text, word) unless update_text.blank?
|
94
105
|
end
|
95
106
|
end
|
96
107
|
|
@@ -102,7 +113,7 @@ module GreenHat
|
|
102
113
|
# Print List of Options
|
103
114
|
elsif matches.count > 1
|
104
115
|
auto_update(common_substr(matches), word)
|
105
|
-
puts matches.join("\t").
|
116
|
+
puts matches.join("\t").pastel(:bright_green)
|
106
117
|
end
|
107
118
|
end
|
108
119
|
|
@@ -135,15 +146,15 @@ module GreenHat
|
|
135
146
|
|
136
147
|
if all.empty?
|
137
148
|
puts [
|
138
|
-
'Command not found '.
|
139
|
-
cmd.
|
140
|
-
' ('.
|
141
|
-
'help'.
|
142
|
-
' to show available commands'.
|
143
|
-
')'.
|
149
|
+
'Command not found '.pastel(:red),
|
150
|
+
cmd.pastel(:bright_yellow),
|
151
|
+
' ('.pastel(:bright_black),
|
152
|
+
'help'.pastel(:blue),
|
153
|
+
' to show available commands'.pastel(:bright_black),
|
154
|
+
')'.pastel(:bright_black)
|
144
155
|
].join
|
145
156
|
else
|
146
|
-
puts "#{'Did you mean?'.
|
157
|
+
puts "#{'Did you mean?'.pastel(:cyan)} #{all.join("\t").pastel(:green)}"
|
147
158
|
end
|
148
159
|
end
|
149
160
|
|
@@ -152,7 +163,7 @@ module GreenHat
|
|
152
163
|
line = reader.line
|
153
164
|
@list = Shellwords.split line.text
|
154
165
|
rescue StandardError => e
|
155
|
-
puts "#{'Invalid Command'.
|
166
|
+
puts "#{'Invalid Command'.pastel(:red)}: #{e.message.pastel(:green)}"
|
156
167
|
end
|
157
168
|
|
158
169
|
def self.available(list)
|
@@ -227,39 +238,50 @@ module GreenHat
|
|
227
238
|
run # Loop Back
|
228
239
|
rescue StandardError => e
|
229
240
|
LogBot.fatal('CLI Run', e.message)
|
230
|
-
puts e.backtrace[0..4].join("\n").
|
241
|
+
puts e.backtrace[0..4].join("\n").pastel(:red)
|
231
242
|
end
|
232
243
|
|
233
244
|
# Check for `default` method and files
|
234
245
|
def self.default?
|
235
|
-
|
246
|
+
@list.any? { |x| x.include?(cmd) } && current_methods.include?('default')
|
247
|
+
end
|
248
|
+
|
249
|
+
def self.current_commands
|
250
|
+
current_location.methods(false).map(&:to_s).sort - %w[auto_complete]
|
236
251
|
end
|
237
252
|
|
238
253
|
# General Helper
|
239
|
-
def self.help
|
254
|
+
def self.help(long = true)
|
240
255
|
if current_location.methods(false).count.zero?
|
241
|
-
puts 'No Commands'.
|
256
|
+
puts 'No Commands'.pastel(:red)
|
242
257
|
else
|
243
258
|
puts 'Commands: '
|
244
|
-
|
259
|
+
current_commands.each do |item|
|
245
260
|
next if %w[default help].any? { |x| x == item }
|
246
261
|
|
247
|
-
puts "=> #{item.to_s.
|
262
|
+
puts "=> #{item.to_s.pastel(:blue)}"
|
248
263
|
end
|
249
264
|
|
250
|
-
current_location.send(:help) if current_methods.include? 'help'
|
251
265
|
end
|
252
266
|
|
253
267
|
puts ''
|
254
268
|
|
255
269
|
if current_location.constants.count.zero?
|
256
|
-
puts 'No Submodules'.
|
270
|
+
puts 'No Submodules'.pastel(:red)
|
257
271
|
else
|
258
272
|
puts 'Submodules'
|
259
273
|
current_location.constants.each do |item|
|
260
|
-
puts "-> #{item.to_s.demodulize.downcase.
|
274
|
+
puts "-> #{item.to_s.demodulize.downcase.pastel(:yellow)}"
|
261
275
|
end
|
262
276
|
end
|
277
|
+
|
278
|
+
# Execute local help last if exists
|
279
|
+
if current_methods.include?('help') && long
|
280
|
+
puts
|
281
|
+
current_location.send(:help)
|
282
|
+
end
|
283
|
+
|
284
|
+
puts ''
|
263
285
|
end
|
264
286
|
|
265
287
|
def self.location
|
@@ -306,11 +328,11 @@ module GreenHat
|
|
306
328
|
end
|
307
329
|
|
308
330
|
def self.location_reader
|
309
|
-
location.map(&:to_s).map(&:downcase).map(&:demodulize).join('/').gsub('shell', '~').
|
331
|
+
location.map(&:to_s).map(&:downcase).map(&:demodulize).join('/').gsub('shell', '~').pastel(:blue)
|
310
332
|
end
|
311
333
|
|
312
334
|
def self.readline_notch
|
313
|
-
"#{'greenhat'.
|
335
|
+
"#{'greenhat'.pastel(:bright_black)} #{location_reader} » "
|
314
336
|
end
|
315
337
|
|
316
338
|
def self.clear_screen
|
@@ -321,51 +343,100 @@ module GreenHat
|
|
321
343
|
@quiet
|
322
344
|
end
|
323
345
|
|
324
|
-
#
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
# TODO: Add Help (--help)
|
329
|
-
def self.startup_args(files)
|
330
|
-
@report = true if files.any? { |x| ['--report', '-r'].include? x }
|
331
|
-
@quiet = true if files.any? { |x| ['--quiet', '-q'].include? x }
|
332
|
-
@load = true if files.any? { |x| ['--load', '-l'].include? x }
|
346
|
+
# Toggle Quiet Settings
|
347
|
+
def self.quiet!
|
348
|
+
@quiet = !@quiet
|
349
|
+
end
|
333
350
|
|
334
|
-
|
351
|
+
def self.cli_help
|
352
|
+
Shell.version
|
353
|
+
puts
|
354
|
+
puts 'Usage'.pastel(:yellow)
|
355
|
+
puts ' greenhat <sos-archive.tgz> <sos-archive2.tgz> '
|
356
|
+
puts ' greenhat <sos-archive.tgz> -q --command=df'
|
357
|
+
puts
|
335
358
|
|
336
|
-
|
337
|
-
|
359
|
+
puts 'Options'.pastel(:yellow)
|
360
|
+
puts ' --report, -r'.pastel(:green)
|
361
|
+
puts ' Run `report` against archives and exit'
|
362
|
+
puts
|
363
|
+
|
364
|
+
puts ' --quiet, -r'.pastel(:green)
|
365
|
+
puts ' Surpress GreenHat logging output'
|
366
|
+
puts
|
367
|
+
|
368
|
+
puts ' --load, -l'.pastel(:green)
|
369
|
+
puts ' Automatically attempt to read/parse/preload all included files'
|
370
|
+
puts
|
338
371
|
|
339
|
-
|
340
|
-
|
372
|
+
puts ' --command, -c'.pastel(:green)
|
373
|
+
puts ' Run and then exit a GreenHat Shell command'
|
374
|
+
puts
|
375
|
+
|
376
|
+
puts ' --version, -v'.pastel(:green)
|
377
|
+
puts ' Print version and exit'
|
378
|
+
puts
|
341
379
|
end
|
342
380
|
|
343
|
-
#
|
344
|
-
def self.
|
345
|
-
#
|
346
|
-
|
381
|
+
# Arguments before general processing
|
382
|
+
def self.pre_args(flags, files)
|
383
|
+
# Help
|
384
|
+
if flags?(%i[help h], flags)
|
385
|
+
cli_help
|
386
|
+
exit 0
|
387
|
+
end
|
347
388
|
|
348
|
-
|
389
|
+
# Version
|
390
|
+
if flags?(%i[version v], flags)
|
391
|
+
Shell.version
|
392
|
+
exit 0
|
393
|
+
end
|
349
394
|
|
350
|
-
|
351
|
-
|
395
|
+
# Quiet Flag
|
396
|
+
@quiet = true if flags?(%i[quiet q], flags)
|
352
397
|
|
398
|
+
# rubocop:disable Style/GuardClause
|
399
|
+
# MIA Files
|
353
400
|
if files.empty? || files.count { |x| File.exist? x }.zero?
|
354
|
-
puts "No arguments or files don't exist".
|
401
|
+
puts "No arguments or files don't exist".pastel(:red)
|
355
402
|
puts 'Usage: greenhat <sos-archive.tgz> <sos-archive2.tgz>'
|
356
|
-
|
403
|
+
cli_help
|
404
|
+
Shell.version
|
357
405
|
end
|
406
|
+
# rubocop:enable Style/GuardClause
|
407
|
+
end
|
358
408
|
|
359
|
-
|
360
|
-
|
361
|
-
#
|
362
|
-
if
|
409
|
+
# Arguments to be handled after general processing
|
410
|
+
def self.post_args(flags)
|
411
|
+
# Run report and exit / Don't Clear for reports
|
412
|
+
if flags?(%i[report r], flags)
|
413
|
+
@quiet = true
|
363
414
|
# Don't Use Pagination
|
364
415
|
GreenHat::Shell.report(['--raw'])
|
365
|
-
|
416
|
+
exit 0
|
417
|
+
else
|
418
|
+
clear_screen
|
366
419
|
end
|
367
420
|
|
368
|
-
|
421
|
+
# CTL Tails need to be parsed for new 'things'
|
422
|
+
Thing.where(kind: :gitlab_tail)&.map(&:process)
|
423
|
+
|
424
|
+
Thing.all.each(&:process) if flags?(%i[load l], flags)
|
425
|
+
end
|
426
|
+
|
427
|
+
# Helper to Simplify checking flags
|
428
|
+
def self.flags?(list = [], flags = {})
|
429
|
+
list.any? { |x| flags.key? x }
|
430
|
+
end
|
431
|
+
|
432
|
+
# If no arguments Supplied Print and quit - rather than nasty exception
|
433
|
+
def self.start(raw)
|
434
|
+
Settings.start
|
435
|
+
files, flags, args = Args.parse(raw)
|
436
|
+
pre_args(flags, files)
|
437
|
+
load_files files
|
438
|
+
run_command(args) if args.any? { |arg| run_command?(arg) }
|
439
|
+
post_args(flags)
|
369
440
|
|
370
441
|
value ||= '' # Empty Start
|
371
442
|
|
@@ -379,11 +450,7 @@ module GreenHat
|
|
379
450
|
next
|
380
451
|
end
|
381
452
|
|
382
|
-
if line =~ /^exit/i
|
383
|
-
Settings.cmd_write
|
384
|
-
|
385
|
-
break
|
386
|
-
end
|
453
|
+
break if line =~ /^exit/i
|
387
454
|
|
388
455
|
Settings.cmd_add(line) unless line.blank?
|
389
456
|
|
@@ -391,18 +458,36 @@ module GreenHat
|
|
391
458
|
run
|
392
459
|
end
|
393
460
|
end
|
394
|
-
|
461
|
+
|
462
|
+
def self.run_command?(arg)
|
463
|
+
%i[command c].any? do |x|
|
464
|
+
arg[:field] == x
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
# Run and Exit Command Helper
|
469
|
+
def self.run_command(args)
|
470
|
+
args.each do |arg|
|
471
|
+
# Quick Validation
|
472
|
+
next unless run_command?(arg) && !arg.value.empty?
|
473
|
+
|
474
|
+
reader.line = ''
|
475
|
+
@list = Shellwords.split arg.value
|
476
|
+
run
|
477
|
+
end
|
478
|
+
exit 0
|
479
|
+
end
|
395
480
|
|
396
481
|
def self.load_files(files)
|
397
482
|
# TODO: Web Helpers?
|
398
483
|
# suppress_output { GreenHat::Web.start }
|
399
484
|
|
400
485
|
# Don't double up on archives / Only Existing files
|
401
|
-
puts 'Loading Archives'.
|
486
|
+
puts 'Loading Archives'.pastel(:blue) unless Cli.quiet
|
402
487
|
files.uniq.each do |file|
|
403
488
|
next unless File.exist?(file)
|
404
489
|
|
405
|
-
puts "- #{file}".
|
490
|
+
puts "- #{file}".pastel(:magenta) unless Cli.quiet
|
406
491
|
ArchiveLoader.load file
|
407
492
|
end
|
408
493
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Top level namespace
|
2
|
+
module GreenHat
|
3
|
+
# Replace Colorize with Pastel Monkey Patch String Shim
|
4
|
+
# https://github.com/piotrmurach/pastel#features
|
5
|
+
|
6
|
+
# Looping in GreenHat to allow disabling of Color
|
7
|
+
module Color
|
8
|
+
def self.pastel
|
9
|
+
@pastel ||= Pastel.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.decorate(args)
|
13
|
+
Settings.color? ? pastel.decorate(*args) : args.first
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Monkey Patch
|
19
|
+
class String
|
20
|
+
def pastel(*args)
|
21
|
+
GreenHat::Color.decorate(args.unshift(self))
|
22
|
+
end
|
23
|
+
|
24
|
+
def unpastel
|
25
|
+
GreenHat::Color.pastel.strip self
|
26
|
+
end
|
27
|
+
end
|
data/lib/greenhat/logbot.rb
CHANGED
@@ -6,11 +6,11 @@ module LogBot
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.output(name, message, level, duration = nil)
|
9
|
-
time = Time.now.to_s.
|
9
|
+
time = Time.now.to_s.pastel(:bright_black)
|
10
10
|
output = time
|
11
11
|
output += " #{color_level(level)}"
|
12
|
-
output += " - #{name.to_s.
|
13
|
-
output += "(#{duration.round(2)}) ".
|
12
|
+
output += " - #{name.to_s.pastel(:bright_blue)} "
|
13
|
+
output += "(#{duration.round(2)}) ".pastel(:magenta) if duration
|
14
14
|
|
15
15
|
output += ' '
|
16
16
|
if message
|
@@ -21,21 +21,21 @@ module LogBot
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
puts output unless ENV['TESTING']
|
24
|
+
puts output unless ENV['TESTING'] || GreenHat::Cli.quiet
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.color_level(level)
|
28
28
|
case level
|
29
29
|
when :debug
|
30
|
-
level.to_s.upcase.
|
30
|
+
level.to_s.upcase.pastel(:bright_cyan)
|
31
31
|
when :info
|
32
|
-
level.to_s.upcase.
|
32
|
+
level.to_s.upcase.pastel(:cyan)
|
33
33
|
when :warn
|
34
|
-
level.to_s.upcase.
|
34
|
+
level.to_s.upcase.pastel(:yellow)
|
35
35
|
when :error
|
36
|
-
level.to_s.upcase.
|
36
|
+
level.to_s.upcase.pastel(:bright_red)
|
37
37
|
when :fatal
|
38
|
-
level.to_s.upcase.
|
38
|
+
level.to_s.upcase.pastel(:red)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|