greenhat 0.2.0 → 0.3.3
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 +13 -13
- data/lib/greenhat/accessors/gitlab.rb +75 -0
- data/lib/greenhat/accessors/memory.rb +10 -10
- data/lib/greenhat/accessors/process.rb +4 -0
- data/lib/greenhat/cli.rb +147 -58
- data/lib/greenhat/color.rb +27 -0
- data/lib/greenhat/logbot.rb +9 -9
- data/lib/greenhat/settings.rb +27 -7
- data/lib/greenhat/shell/args.rb +146 -0
- data/lib/greenhat/shell/cat.rb +25 -73
- data/lib/greenhat/shell/color_string.rb +8 -8
- data/lib/greenhat/shell/disk.rb +31 -4
- data/lib/greenhat/shell/faststats.rb +103 -56
- 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 +118 -104
- data/lib/greenhat/shell/page.rb +11 -5
- data/lib/greenhat/shell/process.rb +29 -17
- data/lib/greenhat/shell/report.rb +37 -47
- data/lib/greenhat/shell/shell_helper.rb +661 -0
- data/lib/greenhat/shell.rb +23 -9
- data/lib/greenhat/thing/file_types.rb +31 -5
- data/lib/greenhat/thing/formatters/json_shellwords.rb +0 -3
- data/lib/greenhat/thing/formatters/nginx.rb +44 -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 +4 -0
- data/lib/greenhat/version.rb +1 -1
- data/lib/greenhat.rb +15 -14
- metadata +38 -18
- data/lib/greenhat/shell/filter.rb +0 -128
- data/lib/greenhat/shell/helper.rb +0 -584
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac7b0e70e5a13dc6f8f88a4f12fec812e38e7d838537abe83b7d4dc2e8b43663
|
4
|
+
data.tar.gz: 84246bc31bd38af74e9f4f8d95f2f7ffa1ca33978dc0d0862ec0b50eaff20196
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba104ea8d7b4e52babf8bdf27ea4f3dbdb9e92820589881bab639a01e8558c355389a0f10b3c17dbe5c7ac881f10364ad06ec0c973934f06d735f948bb57fbd3
|
7
|
+
data.tar.gz: a2013229826758ca61335f5cf8d58c3a4a4206e656dce084f90781c264e4930c5c3fd09b7475a43dd31819bc2562e85e5799de775cc5db9dfaa3f73c0228ac3a
|
@@ -48,30 +48,30 @@ module GreenHat
|
|
48
48
|
|
49
49
|
# Headers
|
50
50
|
output << [
|
51
|
-
'Mount'.ljust(pad_mount).
|
52
|
-
'Size'.ljust(pad_size).
|
53
|
-
'Used'.ljust(pad_used).
|
54
|
-
'Avail'.ljust(pad_avail).
|
55
|
-
'% Use'.ljust(pad_avail).
|
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
56
|
].join
|
57
57
|
|
58
58
|
# Table Summary
|
59
59
|
disks.map do |disk|
|
60
60
|
# Pretty Disk Use
|
61
61
|
use = [
|
62
|
-
disk.use.rjust(5).ljust(5).
|
63
|
-
' ['.
|
64
|
-
('=' * (disk.use.to_i / 2)).
|
62
|
+
disk.use.rjust(5).ljust(5).pastel(:green),
|
63
|
+
' ['.pastel(:blue),
|
64
|
+
('=' * (disk.use.to_i / 2)).pastel(:green),
|
65
65
|
' ' * (50 - disk.use.to_i / 2),
|
66
|
-
']'.
|
66
|
+
']'.pastel(:blue)
|
67
67
|
].join
|
68
68
|
|
69
69
|
# Whole Thing
|
70
70
|
output << [
|
71
|
-
disk.mounted_on.ljust(pad_mount).
|
72
|
-
disk[:size].to_s.ljust(pad_size).
|
73
|
-
disk.used.to_s.ljust(pad_used).
|
74
|
-
disk.avail.to_s.ljust(pad_avail).
|
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
75
|
use
|
76
76
|
].join
|
77
77
|
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
|
|
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
|
371
|
+
|
372
|
+
puts ' --command, -c'.pastel(:green)
|
373
|
+
puts ' Run and then exit a GreenHat Shell command'
|
374
|
+
puts
|
338
375
|
|
339
|
-
|
340
|
-
|
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
|
|
@@ -387,18 +458,36 @@ module GreenHat
|
|
387
458
|
run
|
388
459
|
end
|
389
460
|
end
|
390
|
-
|
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
|
391
480
|
|
392
481
|
def self.load_files(files)
|
393
482
|
# TODO: Web Helpers?
|
394
483
|
# suppress_output { GreenHat::Web.start }
|
395
484
|
|
396
485
|
# Don't double up on archives / Only Existing files
|
397
|
-
puts 'Loading Archives'.
|
486
|
+
puts 'Loading Archives'.pastel(:blue) unless Cli.quiet
|
398
487
|
files.uniq.each do |file|
|
399
488
|
next unless File.exist?(file)
|
400
489
|
|
401
|
-
puts "- #{file}".
|
490
|
+
puts "- #{file}".pastel(:magenta) unless Cli.quiet
|
402
491
|
ArchiveLoader.load file
|
403
492
|
end
|
404
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
|
|
data/lib/greenhat/settings.rb
CHANGED
@@ -5,14 +5,25 @@ module GreenHat
|
|
5
5
|
def self.settings
|
6
6
|
@settings ||= {
|
7
7
|
history: [],
|
8
|
+
assume_json: true,
|
9
|
+
fuzzy_file_match: true,
|
8
10
|
|
9
11
|
# round: [2],
|
10
12
|
# page: [:true] Automatic,
|
11
|
-
truncate:
|
12
|
-
|
13
|
+
truncate: TTY::Screen.width * 4,
|
14
|
+
color: true
|
13
15
|
}
|
14
16
|
end
|
15
17
|
|
18
|
+
def self.assume_json?
|
19
|
+
settings.assume_json
|
20
|
+
end
|
21
|
+
|
22
|
+
# Allow for future disabling of color output
|
23
|
+
def self.color?
|
24
|
+
settings.color
|
25
|
+
end
|
26
|
+
|
16
27
|
# Load User Settings and drop them into settings
|
17
28
|
def self.settings_load
|
18
29
|
return true unless File.exist?(settings_file)
|
@@ -26,12 +37,21 @@ module GreenHat
|
|
26
37
|
"#{dir}/settings.json"
|
27
38
|
end
|
28
39
|
|
29
|
-
# Set any Log Arguments that weren't set otherwise
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
40
|
+
# Set any Log Arguments that weren't set otherwise | Conditional assign applied on bool
|
41
|
+
# rubocop:disable Style/GuardClause
|
42
|
+
def self.default_log_flags(flags, skip_flags)
|
43
|
+
flags[:round] = settings.round if !(skip_flags.include?(:round) || flags.key?(:round)) && settings.round
|
44
|
+
|
45
|
+
flags[:page] = settings.page if !(skip_flags.include?(:page) || flags.key?(:page)) && settings.page
|
46
|
+
|
47
|
+
flags[:truncate] = settings.truncate unless skip_flags.include?(:truncate) || flags.key?(:truncate)
|
48
|
+
|
49
|
+
# Fuzzy File Match
|
50
|
+
unless skip_flags.include?(:fuzzy_file_match) || flags.key?(:fuzzy_file_match)
|
51
|
+
flags[:fuzzy_file_match] = settings.fuzzy_file_match
|
52
|
+
end
|
34
53
|
end
|
54
|
+
# rubocop:enable Style/GuardClause
|
35
55
|
|
36
56
|
def self.start
|
37
57
|
Dir.mkdir dir unless Dir.exist? dir
|