greenhat 0.4.0 → 0.6.1
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/bin/greenhat +1 -2
- data/lib/greenhat/accessors/disk.rb +1 -1
- data/lib/greenhat/accessors/gitlab.rb +4 -2
- data/lib/greenhat/archive.rb +7 -1
- data/lib/greenhat/cli.rb +24 -11
- data/lib/greenhat/entrypoint.rb +37 -34
- data/lib/greenhat/host.rb +1 -1
- data/lib/greenhat/logbot.rb +1 -1
- data/lib/greenhat/paper/flag_helper.rb +18 -0
- data/lib/greenhat/paper/paper_helper.rb +118 -0
- data/lib/greenhat/paper.rb +34 -0
- data/lib/greenhat/reports/builder.rb +98 -0
- data/lib/greenhat/reports/helpers.rb +101 -0
- data/lib/greenhat/reports/internal_methods.rb +156 -0
- data/lib/greenhat/reports/reports/errors.rb +49 -0
- data/lib/greenhat/reports/reports/faststats.rb +42 -0
- data/lib/greenhat/reports/reports/full.rb +143 -0
- data/lib/greenhat/reports/runner.rb +58 -0
- data/lib/greenhat/reports/shared.rb +37 -0
- data/lib/greenhat/reports/shell_helper.rb +34 -0
- data/lib/greenhat/reports.rb +79 -0
- data/lib/greenhat/settings.rb +35 -8
- data/lib/greenhat/shell/args.rb +9 -9
- data/lib/greenhat/shell/color_string.rb +1 -1
- data/lib/greenhat/shell/faststats.rb +24 -5
- data/lib/greenhat/shell/field_helper.rb +1 -1
- data/lib/greenhat/shell/filter_help.rb +65 -185
- data/lib/greenhat/shell/gitlab.rb +1 -0
- data/lib/greenhat/shell/log.rb +24 -30
- data/lib/greenhat/shell/markdown.rb +355 -352
- data/lib/greenhat/shell/process.rb +11 -5
- data/lib/greenhat/shell/query.rb +534 -0
- data/lib/greenhat/shell/report.rb +415 -410
- data/lib/greenhat/shell/reports.rb +41 -0
- data/lib/greenhat/shell/shell_helper.rb +95 -387
- data/lib/greenhat/shell.rb +22 -3
- data/lib/greenhat/thing/file_types.rb +30 -1
- data/lib/greenhat/thing/formatters/api_json.rb +4 -2
- data/lib/greenhat/thing/formatters/bracket_log.rb +1 -1
- data/lib/greenhat/thing/formatters/clean_raw.rb +1 -1
- data/lib/greenhat/thing/formatters/colon_split_strip.rb +2 -2
- data/lib/greenhat/thing/formatters/dotenv.rb +1 -1
- data/lib/greenhat/thing/formatters/format.rb +0 -11
- data/lib/greenhat/thing/formatters/free_m.rb +2 -2
- data/lib/greenhat/thing/formatters/json.rb +41 -17
- data/lib/greenhat/thing/formatters/json_shellwords.rb +3 -2
- data/lib/greenhat/thing/formatters/kube_json.rb +3 -2
- data/lib/greenhat/thing/formatters/multiline_json.rb +1 -1
- data/lib/greenhat/thing/formatters/nginx.rb +5 -1
- data/lib/greenhat/thing/formatters/runner_log.rb +70 -0
- data/lib/greenhat/thing/formatters/table.rb +17 -3
- data/lib/greenhat/thing/formatters/time_json.rb +12 -1
- data/lib/greenhat/thing/helpers.rb +0 -11
- data/lib/greenhat/thing/info_format.rb +4 -4
- data/lib/greenhat/thing/kind.rb +1 -1
- data/lib/greenhat/thing.rb +21 -25
- data/lib/greenhat/version.rb +1 -1
- data/lib/greenhat.rb +6 -8
- metadata +32 -4
- data/lib/greenhat/pry_helpers.rb +0 -51
- data/lib/greenhat/thing/super_log.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4787b5c739b568b8f6f5d22bab609f685ed4e4ed725085c432809102174e9dd5
|
4
|
+
data.tar.gz: 7fcedca5675835ae177c58418dc2ddcaf25bae27333aeea9430e5a36d92a0b01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c54a1054bd1c38b8514d4cd4c2b38f1c851a463134399c6c5c1af4c81ae9ffe6dbde083856b4dcabd1f09b9b68c5632240fdce5f135b5f8c763d5c72dc7047b0
|
7
|
+
data.tar.gz: 894307efe02d22b50a4a6ca8674700409611e24cf8b46b9653b7f4b24f242b65a0f1649f4fd881bc636c92afea4d42085043b4a8cf3c4662b4535127f9e70b85
|
data/bin/greenhat
CHANGED
@@ -35,11 +35,13 @@ module GreenHat
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# Show GitLab Services in a grid / include versions
|
38
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
38
|
+
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
39
39
|
def self.services(archive, indent = 0)
|
40
40
|
manifest = archive.things.find { |x| x.type == 'gitlab/version-manifest.json' }
|
41
41
|
gitlab_status = archive.things.find { |x| x.name == 'gitlab_status' }
|
42
42
|
|
43
|
+
# Dont' show invalid
|
44
|
+
return nil if gitlab_status.data.to_s.include? "Could not find 'bundler'"
|
43
45
|
return nil unless gitlab_status
|
44
46
|
|
45
47
|
list = gitlab_status.data.keys.sort.map do |service|
|
@@ -73,7 +75,7 @@ module GreenHat
|
|
73
75
|
|
74
76
|
table.render(:unicode, padding: [0, 1, 0, 1], indent: indent)
|
75
77
|
end
|
76
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
78
|
+
# rubocop:enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
77
79
|
|
78
80
|
def self.services_markdown(archive)
|
79
81
|
# manifest = archive.things.find { |x| x.type == 'gitlab/version-manifest.json' }
|
data/lib/greenhat/archive.rb
CHANGED
@@ -61,6 +61,12 @@ module GreenHat
|
|
61
61
|
FileUtils.rm(archive_path)
|
62
62
|
when '.gz'
|
63
63
|
`gzip -d "#{archive_path}"`
|
64
|
+
when '.zip'
|
65
|
+
base_path = archive_path.gsub(File.basename(archive_path), '')
|
66
|
+
`unzip -o -d "#{base_path}" #{archive_path}`
|
67
|
+
FileUtils.rm(archive_path)
|
68
|
+
when '.bz2'
|
69
|
+
`bzip2 -d #{archive_path}`
|
64
70
|
when '.s'
|
65
71
|
# Find Original Directory, Split Path, Rename to .gz
|
66
72
|
base_path = archive_path.gsub(File.basename(archive_path), '')
|
@@ -77,7 +83,7 @@ module GreenHat
|
|
77
83
|
end
|
78
84
|
|
79
85
|
def self.archive_types
|
80
|
-
%w[s gz tar tgz]
|
86
|
+
%w[s gz tar tgz zip bz2]
|
81
87
|
end
|
82
88
|
# -- Archive Loader ----------------------------------------------
|
83
89
|
end
|
data/lib/greenhat/cli.rb
CHANGED
@@ -35,8 +35,14 @@ module GreenHat
|
|
35
35
|
@reader ||= reader_setup
|
36
36
|
end
|
37
37
|
|
38
|
+
# Context matters on which ones to autocomplete / Not saving in memory to allow better tab / auto complete
|
38
39
|
def self.files
|
39
|
-
|
40
|
+
case current_location
|
41
|
+
when GreenHat::Shell::Log
|
42
|
+
Thing.all.select(&:log).map(&:name.uniq)
|
43
|
+
else
|
44
|
+
Thing.all.map(&:name).uniq
|
45
|
+
end
|
40
46
|
end
|
41
47
|
|
42
48
|
def self.reader_setup
|
@@ -109,19 +115,19 @@ module GreenHat
|
|
109
115
|
if submodule?
|
110
116
|
submodule!
|
111
117
|
reader.breaker = true
|
112
|
-
|
118
|
+
# Only one Match!
|
113
119
|
elsif matches.count == 1
|
114
120
|
auto_update(matches.first, word)
|
115
121
|
|
116
|
-
|
122
|
+
# Print List of Options
|
117
123
|
elsif matches.count > 1
|
118
124
|
puts matches.join("\t").pastel(:bright_green)
|
119
125
|
|
120
|
-
|
126
|
+
# General Filename Matching
|
121
127
|
elsif !file_matches(word).empty?
|
122
128
|
auto_files(file_matches(word), word)
|
123
129
|
|
124
|
-
|
130
|
+
# Submodule Autocompletion
|
125
131
|
elsif current_methods.include?('auto_complete')
|
126
132
|
update_text = current_location.auto_complete(@list, word)
|
127
133
|
auto_update(update_text, word) unless update_text.blank?
|
@@ -133,7 +139,7 @@ module GreenHat
|
|
133
139
|
if matches.count == 1
|
134
140
|
auto_update(matches.first, word)
|
135
141
|
|
136
|
-
|
142
|
+
# Print List of Options
|
137
143
|
elsif matches.count > 1
|
138
144
|
auto_update(common_substr(matches), word)
|
139
145
|
puts matches.join("\t").pastel(:bright_green)
|
@@ -245,12 +251,11 @@ module GreenHat
|
|
245
251
|
run!
|
246
252
|
|
247
253
|
return true # End Early
|
248
|
-
|
249
254
|
elsif current_submodule?
|
250
255
|
@list.shift
|
251
256
|
elsif submodule?
|
252
257
|
submodule!
|
253
|
-
|
258
|
+
# Prepend Default if exists
|
254
259
|
elsif default?
|
255
260
|
@list.unshift 'default'
|
256
261
|
else
|
@@ -284,7 +289,6 @@ module GreenHat
|
|
284
289
|
|
285
290
|
puts "=> #{item.to_s.pastel(:blue)}"
|
286
291
|
end
|
287
|
-
|
288
292
|
end
|
289
293
|
|
290
294
|
puts ''
|
@@ -316,6 +320,11 @@ module GreenHat
|
|
316
320
|
@location = [spot]
|
317
321
|
end
|
318
322
|
|
323
|
+
# Shell Context Location
|
324
|
+
def self.move_shell(spot)
|
325
|
+
@location = [GreenHat::Shell, spot]
|
326
|
+
end
|
327
|
+
|
319
328
|
# Append to Location
|
320
329
|
def self.submodule!
|
321
330
|
spot = @list.shift
|
@@ -334,7 +343,6 @@ module GreenHat
|
|
334
343
|
# Reader to Get Last Location's Available Methods / Keep Helper Methods
|
335
344
|
def self.current_methods
|
336
345
|
current_location.methods(false).map(&:to_s)
|
337
|
-
# .reject { |x| x.include? '_help' }
|
338
346
|
end
|
339
347
|
|
340
348
|
def self.current_submodules
|
@@ -366,8 +374,12 @@ module GreenHat
|
|
366
374
|
@quiet
|
367
375
|
end
|
368
376
|
|
369
|
-
# Toggle Quiet Settings
|
370
377
|
def self.quiet!
|
378
|
+
@quiet = true
|
379
|
+
end
|
380
|
+
|
381
|
+
# Toggle Quiet Settings
|
382
|
+
def self.quiet_toggle
|
371
383
|
@quiet = !@quiet
|
372
384
|
end
|
373
385
|
|
@@ -427,5 +439,6 @@ module GreenHat
|
|
427
439
|
exit 1
|
428
440
|
end
|
429
441
|
end
|
442
|
+
|
430
443
|
# rubocop:enable Metrics/ModuleLength
|
431
444
|
end
|
data/lib/greenhat/entrypoint.rb
CHANGED
@@ -4,23 +4,25 @@ module GreenHat
|
|
4
4
|
# Command Line Args / File Parsing etc
|
5
5
|
module Entrypoint
|
6
6
|
# If no arguments Supplied Print and quit - rather than nasty exception
|
7
|
-
def self.start(raw)
|
8
|
-
@clear =
|
7
|
+
def self.start(raw, clear = true, cli = true)
|
8
|
+
@clear = clear # Reset screen by default
|
9
9
|
Settings.start
|
10
10
|
files, flags, args = Args.parse(raw)
|
11
11
|
pre_args(flags, files)
|
12
12
|
load_files files
|
13
13
|
Cli.run_command(args) if args.any? { |arg| Cli.run_command?(arg) }
|
14
|
+
|
15
|
+
report_runner(args: args, files: files, raw: raw, flags: flags)
|
14
16
|
post_args(flags)
|
15
17
|
post_setup(flags)
|
16
18
|
|
17
|
-
Cli.start # Kick over to CLI
|
19
|
+
Cli.start if cli # Kick over to CLI
|
18
20
|
end
|
19
21
|
|
20
22
|
# Arguments before general processing
|
21
23
|
def self.pre_args(flags, files)
|
22
24
|
# Help
|
23
|
-
if flags?(%i[help h], flags)
|
25
|
+
if flags?(%i[help h], flags) && !ENV['GREENHAT_REPORT']
|
24
26
|
cli_help
|
25
27
|
exit 0
|
26
28
|
end
|
@@ -36,7 +38,7 @@ module GreenHat
|
|
36
38
|
Settings.settings[:assume_raw] = false if flags?(%i[prompt p], flags)
|
37
39
|
|
38
40
|
# Quiet Flag
|
39
|
-
|
41
|
+
Cli.quiet! if flags?(%i[quiet q], flags)
|
40
42
|
|
41
43
|
if flags?(%i[load-local ll], flags)
|
42
44
|
# Hook in loading local
|
@@ -53,30 +55,37 @@ module GreenHat
|
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
58
|
+
# Helper to allow running any kind of report with arguments directly with greenhat
|
59
|
+
def self.report_runner(args:, files:, raw:, flags:)
|
60
|
+
if flags.report || flags.r
|
61
|
+
GreenHat::Shell::Reports.default(['full'])
|
62
|
+
exit 0
|
63
|
+
end
|
64
|
+
|
65
|
+
# See if Param was passed
|
66
|
+
report = args.find { |x| %i[report r].include? x.field }
|
67
|
+
return false unless report
|
68
|
+
|
69
|
+
Cli.quiet! # Hush
|
70
|
+
|
71
|
+
# Filter for additional params for Reports
|
72
|
+
raw_filter = raw.reject do |entry|
|
73
|
+
entry.include?('--report') || files.include?(entry)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Prepend report name
|
77
|
+
raw_filter.unshift(report.value)
|
78
|
+
|
79
|
+
GreenHat::Shell::Reports.default([report.value])
|
80
|
+
|
81
|
+
exit 0
|
82
|
+
end
|
83
|
+
|
56
84
|
# Arguments to be handled after general processing
|
57
85
|
def self.post_args(flags)
|
58
86
|
# Supress Color
|
59
87
|
GreenHat::Settings.settings[:color] = false if flags?(%i[no-color n], flags)
|
60
|
-
|
61
|
-
# Run report and exit / Don't Clear for reports
|
62
|
-
if flags?(%i[report r], flags)
|
63
|
-
@quiet = true
|
64
|
-
# Don't Use Pagination
|
65
|
-
GreenHat::Shell.report(['--raw'])
|
66
|
-
exit 0
|
67
|
-
elsif flags?(%i[full-report f], flags)
|
68
|
-
@quiet = true
|
69
|
-
# Don't Use Pagination
|
70
|
-
GreenHat::Shell.report(['--raw', '--full'])
|
71
|
-
exit 0
|
72
|
-
elsif flags?(%i[markdown m], flags)
|
73
|
-
@quiet = true
|
74
|
-
# Don't Use Pagination
|
75
|
-
GreenHat::Shell.markdown_report(['--raw'])
|
76
|
-
exit 0
|
77
|
-
elsif @clear
|
78
|
-
Cli.clear_screen
|
79
|
-
end
|
88
|
+
Cli.clear_screen if @clear
|
80
89
|
end
|
81
90
|
|
82
91
|
def self.post_setup(flags)
|
@@ -116,15 +125,9 @@ module GreenHat
|
|
116
125
|
|
117
126
|
puts 'Options'.pastel(:yellow)
|
118
127
|
puts ' --report, -r'.pastel(:green)
|
119
|
-
puts ' Run `report` against archives and exit'
|
120
|
-
puts
|
121
|
-
|
122
|
-
puts ' --full-report, -f'.pastel(:green)
|
123
|
-
puts ' Run `report` with all details. e.g. include fast-stats top/errors'
|
124
|
-
puts
|
125
|
-
|
126
|
-
puts ' --markdown, -m'.pastel(:green)
|
127
|
-
puts ' Run `markdown_report` against archives and exit'
|
128
|
+
puts ' Run default or specified `report` against archives and exit'
|
129
|
+
puts ' Default report "full", --report, --report=demo, --report=errors'
|
130
|
+
puts ' See reportable.md/wiki or the `reports` submodule'
|
128
131
|
puts
|
129
132
|
|
130
133
|
puts ' --quiet, -r'.pastel(:green)
|
data/lib/greenhat/host.rb
CHANGED
data/lib/greenhat/logbot.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module GreenHat
|
2
|
+
# Helpers for Paper Render
|
3
|
+
module PaperFlagHelper
|
4
|
+
# --------------------------------------------------------------------------
|
5
|
+
def truncate
|
6
|
+
flags[:truncate]
|
7
|
+
end
|
8
|
+
|
9
|
+
def table_style
|
10
|
+
flags[:table_style]&.to_sym || :unicode
|
11
|
+
end
|
12
|
+
|
13
|
+
def stats
|
14
|
+
flags[:stats]
|
15
|
+
end
|
16
|
+
# --------------------------------------------------------------------------
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module GreenHat
|
2
|
+
# Helpers for Paper Render
|
3
|
+
module PaperHelpers
|
4
|
+
# =========================================================================
|
5
|
+
# Entrypoint
|
6
|
+
# =========================================================================
|
7
|
+
def process
|
8
|
+
LogBot.debug('Entry Show', data.class) if ENV['DEBUG']
|
9
|
+
case data
|
10
|
+
when Hash then render_table
|
11
|
+
when Float, Integer
|
12
|
+
self.output = format_table_entry(data)
|
13
|
+
# Ignore Special Formatting for Strings / Usually already formatted
|
14
|
+
when String
|
15
|
+
self.output = data
|
16
|
+
when Array
|
17
|
+
# Check for Nested Arrays (Array Table)
|
18
|
+
if data.first.instance_of? Array
|
19
|
+
render_array_table(data)
|
20
|
+
else
|
21
|
+
self.output = data
|
22
|
+
end
|
23
|
+
else
|
24
|
+
LogBot.warn('Shell Show', "Unknown #{data.class}")
|
25
|
+
self.output = data
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# --------------------------------------------------------------------------
|
30
|
+
def render_table
|
31
|
+
formatted = data.to_h { |key, entry| [key, format_table_entry(entry, key)] }
|
32
|
+
|
33
|
+
# Pre-format Entry
|
34
|
+
table = TTY::Table.new(header: formatted.keys, rows: [formatted], orientation: :vertical)
|
35
|
+
|
36
|
+
LogBot.debug('Rendering Entries') if ENV['DEBUG']
|
37
|
+
self.output = table.render(table_style, padding: [0, 1, 0, 1], multiline: true) do |renderer|
|
38
|
+
renderer.border.style = :cyan
|
39
|
+
end
|
40
|
+
|
41
|
+
# Line breaks for basic tables
|
42
|
+
self.output += "\n" if table_style == :basic
|
43
|
+
rescue StandardError => e
|
44
|
+
if ENV['DEBUG']
|
45
|
+
LogBot.warn('Table', message: e.message)
|
46
|
+
ap e.backtrace
|
47
|
+
end
|
48
|
+
|
49
|
+
self.output = [
|
50
|
+
data.ai,
|
51
|
+
('_' * (TTY::Screen.width / 3)).pastel(:cyan),
|
52
|
+
"\n"
|
53
|
+
].join("\n")
|
54
|
+
end
|
55
|
+
|
56
|
+
# --------------------------------------------------------------------------
|
57
|
+
# Format Table Entries
|
58
|
+
def format_table_entry(entry, key = nil)
|
59
|
+
formatted_entry = case entry
|
60
|
+
# Rounding
|
61
|
+
when Float, Integer || entry.numeric?
|
62
|
+
flags.key?(:round) ? entry.to_f.round(flags.round).ai : entry.ai
|
63
|
+
|
64
|
+
# General Inspecting
|
65
|
+
when Hash then entry.ai(ruby19_syntax: true)
|
66
|
+
|
67
|
+
# Arrays often contain Hashes. Dangerous Recursive?
|
68
|
+
when Array
|
69
|
+
entry.map { |x| format_table_entry(x) }.join("\n")
|
70
|
+
when Time
|
71
|
+
entry.to_s.pastel(:bright_white)
|
72
|
+
|
73
|
+
# Default String Formatting
|
74
|
+
else
|
75
|
+
ShellHelper::StringColor.do(key, entry)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Stats truncation handled separately
|
79
|
+
if truncate && !stats
|
80
|
+
entry_truncate(formatted_entry)
|
81
|
+
else
|
82
|
+
formatted_entry
|
83
|
+
end
|
84
|
+
rescue StandardError => e
|
85
|
+
if ENV['DEBUG']
|
86
|
+
LogBot.warn('Table Format Entry', message: e.message)
|
87
|
+
ap e.backtrace
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# --------------------------------------------------------------------------
|
92
|
+
def entry_truncate(entry)
|
93
|
+
# Ignore if Truncation Off
|
94
|
+
return entry if truncate.zero?
|
95
|
+
|
96
|
+
# Only truncate large strings
|
97
|
+
return entry unless entry.instance_of?(String) && entry.size > truncate
|
98
|
+
|
99
|
+
# Include '...' to indicate truncation
|
100
|
+
"#{entry.to_s[0..truncate]} #{'...'.pastel(:bright_blue)}"
|
101
|
+
end
|
102
|
+
|
103
|
+
# --------------------------------------------------------------------------
|
104
|
+
def render_array_table(entry)
|
105
|
+
header, rows = entry
|
106
|
+
table = TTY::Table.new(header: header, rows: rows)
|
107
|
+
|
108
|
+
LogBot.debug('Rendering Entries') if ENV['DEBUG']
|
109
|
+
self.output = table.render(table_style, padding: [0, 1, 0, 1], multiline: true) do |renderer|
|
110
|
+
renderer.border.style = :cyan
|
111
|
+
end
|
112
|
+
|
113
|
+
# Line breaks for basic tables
|
114
|
+
self.output += "\n" if table_style == :basic
|
115
|
+
end
|
116
|
+
# --------------------------------------------------------------------------
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module GreenHat
|
2
|
+
# Output Helper
|
3
|
+
class Paper
|
4
|
+
include PaperHelpers
|
5
|
+
include PaperFlagHelper
|
6
|
+
attr_accessor :task, :output, :flags, :data, :done, :mutex
|
7
|
+
|
8
|
+
def initialize(data:, flags:)
|
9
|
+
self.mutex = Mutex.new
|
10
|
+
self.data = data
|
11
|
+
self.flags = flags
|
12
|
+
end
|
13
|
+
|
14
|
+
def async
|
15
|
+
return if done # Don't attempt lock if already done
|
16
|
+
|
17
|
+
mutex.synchronize do
|
18
|
+
return if done # Turn if was waiting on lock
|
19
|
+
|
20
|
+
process
|
21
|
+
|
22
|
+
self.output ||= '' # If Empty
|
23
|
+
|
24
|
+
self.done = true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def render
|
29
|
+
async unless done
|
30
|
+
|
31
|
+
output
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# GreenHat Namespace
|
2
|
+
module GreenHat
|
3
|
+
# Reports Parent Class
|
4
|
+
module Reports
|
5
|
+
# Used for within GreenHat Use
|
6
|
+
class Builder
|
7
|
+
include GreenHat::Reports::Shared
|
8
|
+
|
9
|
+
attr_accessor :store, :flags, :args
|
10
|
+
|
11
|
+
def initialize(file:, flags:, args:)
|
12
|
+
self.store = []
|
13
|
+
self.flags = flags
|
14
|
+
self.args = args
|
15
|
+
instance_eval File.read(file)
|
16
|
+
rescue StandardError => e
|
17
|
+
print "#{e.message}\n"
|
18
|
+
print e.backtrace[0..4].join("\n").pastel(:red)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Adding Methods
|
22
|
+
def add(*params)
|
23
|
+
store.push params
|
24
|
+
end
|
25
|
+
|
26
|
+
# ------------------------------------------------------------------------
|
27
|
+
# Store Methods
|
28
|
+
# ------------------------------------------------------------------------
|
29
|
+
|
30
|
+
def quiet!
|
31
|
+
GreenHat::Cli.quiet!
|
32
|
+
end
|
33
|
+
|
34
|
+
def no_prompt!
|
35
|
+
# TODO: Should this do anything?
|
36
|
+
end
|
37
|
+
|
38
|
+
# Default Header
|
39
|
+
def header(text, color = :bright_yellow)
|
40
|
+
add(:header, text, color)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Archive Header
|
44
|
+
def archive_header(color = :blue)
|
45
|
+
add(:archive_header, color)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Raw
|
49
|
+
def cat(name, show_output = true, &block)
|
50
|
+
add(:cat, name, show_output, block)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Parsed
|
54
|
+
def info(name, show_output = true, &block)
|
55
|
+
add(:info, name, show_output, block)
|
56
|
+
end
|
57
|
+
|
58
|
+
# New Line Helepr
|
59
|
+
def br
|
60
|
+
add :br
|
61
|
+
end
|
62
|
+
|
63
|
+
def puts(text = '')
|
64
|
+
add :puts, text
|
65
|
+
end
|
66
|
+
|
67
|
+
# Helper to Print GitLab Version
|
68
|
+
def gitlab_version
|
69
|
+
add :gitlab_version
|
70
|
+
end
|
71
|
+
|
72
|
+
# Help
|
73
|
+
def help(&block)
|
74
|
+
add(:help, block)
|
75
|
+
end
|
76
|
+
|
77
|
+
def show(text = '')
|
78
|
+
add :show, text
|
79
|
+
end
|
80
|
+
|
81
|
+
# Log Query
|
82
|
+
def query(query, show_output = true, &block)
|
83
|
+
add(:query, query, show_output, block)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Log Query / Assume Format
|
87
|
+
def query_format(query, show_output = true, &block)
|
88
|
+
add(:query_format, query, show_output, block)
|
89
|
+
end
|
90
|
+
|
91
|
+
# FastStats Helper
|
92
|
+
def faststats(query, subcmd = '')
|
93
|
+
add(:faststats, query, subcmd)
|
94
|
+
end
|
95
|
+
# ------------------------------------------------------------------------
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# Disable for executor
|
2
|
+
# rubocop:disable Style/MixinUsage
|
3
|
+
include ActionView::Helpers::DateHelper
|
4
|
+
include ActionView::Helpers::NumberHelper
|
5
|
+
include GreenHat::Reports::Shared
|
6
|
+
# rubocop:enable Style/MixinUsage
|
7
|
+
|
8
|
+
def add(*params)
|
9
|
+
GreenHat::Reports.add(*params)
|
10
|
+
end
|
11
|
+
|
12
|
+
# ==============================================================================
|
13
|
+
# General Report Helpers
|
14
|
+
# ==============================================================================
|
15
|
+
# Supress output
|
16
|
+
def quiet!
|
17
|
+
GreenHat::Cli.quiet!
|
18
|
+
end
|
19
|
+
|
20
|
+
# Supress output
|
21
|
+
def page(value = true)
|
22
|
+
ENV['GREENHAT_PAGE'] = value == true ? 'true' : 'false'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Attempt Autoload raw/json
|
26
|
+
def no_prompt!
|
27
|
+
Settings.settings[:assume_raw] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
# Default Header
|
31
|
+
def header(text, color = :bright_yellow)
|
32
|
+
add(:header, text, color)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Archive Header
|
36
|
+
def archive_header(color = :blue)
|
37
|
+
add(:archive_header, color)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Raw
|
41
|
+
def cat(name, show_output = true, &block)
|
42
|
+
add(:cat, name, show_output, block)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Parsed
|
46
|
+
def info(name, show_output = true, &block)
|
47
|
+
add(:info, name, show_output, block)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Log Query
|
51
|
+
def query(query, show_output = true, &block)
|
52
|
+
add(:query, query, show_output, block)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Log Query / Assume Format
|
56
|
+
def query_format(query, show_output = true, &block)
|
57
|
+
add(:query_format, query, show_output, block)
|
58
|
+
end
|
59
|
+
|
60
|
+
# FastStats Helper
|
61
|
+
def faststats(query, subcmd = '')
|
62
|
+
add(:faststats, query, subcmd)
|
63
|
+
end
|
64
|
+
|
65
|
+
# New Line Helper
|
66
|
+
def br
|
67
|
+
add :br
|
68
|
+
end
|
69
|
+
|
70
|
+
def puts(text = '')
|
71
|
+
add :puts, text
|
72
|
+
end
|
73
|
+
|
74
|
+
def show(text = '')
|
75
|
+
add :show, text
|
76
|
+
end
|
77
|
+
|
78
|
+
# Help
|
79
|
+
def help(&block)
|
80
|
+
add(:help, block)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Helper to Print GitLab Version
|
84
|
+
def gitlab_version
|
85
|
+
add :gitlab_version
|
86
|
+
end
|
87
|
+
|
88
|
+
# =================================================================
|
89
|
+
# These are here to allow flags/args to be used outside of blocks
|
90
|
+
# =================================================================
|
91
|
+
def args
|
92
|
+
_file_list, _flags, args = GreenHat::Args.parse(ARGV)
|
93
|
+
args
|
94
|
+
end
|
95
|
+
|
96
|
+
def flags
|
97
|
+
_file_list, flags, _args = GreenHat::Args.parse(ARGV)
|
98
|
+
|
99
|
+
flags
|
100
|
+
end
|
101
|
+
# =================================================================
|