greenhat 0.5.1 → 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/lib/greenhat/archive.rb +2 -0
- data/lib/greenhat/cli.rb +12 -2
- data/lib/greenhat/entrypoint.rb +36 -33
- 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 +6 -1
- 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 +36 -189
- data/lib/greenhat/shell/log.rb +18 -14
- data/lib/greenhat/shell/markdown.rb +355 -352
- data/lib/greenhat/shell/process.rb +11 -5
- data/lib/greenhat/shell/query.rb +183 -27
- data/lib/greenhat/shell/report.rb +415 -412
- data/lib/greenhat/shell/reports.rb +41 -0
- data/lib/greenhat/shell/shell_helper.rb +92 -34
- data/lib/greenhat/shell.rb +13 -2
- data/lib/greenhat/thing/file_types.rb +14 -0
- data/lib/greenhat/thing/formatters/clean_raw.rb +1 -1
- data/lib/greenhat/thing/formatters/runner_log.rb +70 -0
- data/lib/greenhat/thing/formatters/time_json.rb +12 -1
- data/lib/greenhat/thing/kind.rb +1 -1
- data/lib/greenhat/version.rb +1 -1
- data/lib/greenhat.rb +6 -8
- metadata +31 -4
- data/lib/greenhat/pry_helpers.rb +0 -51
- data/lib/greenhat/thing/super_log.rb +0 -1
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/lib/greenhat/archive.rb
CHANGED
@@ -62,7 +62,9 @@ module GreenHat
|
|
62
62
|
when '.gz'
|
63
63
|
`gzip -d "#{archive_path}"`
|
64
64
|
when '.zip'
|
65
|
+
base_path = archive_path.gsub(File.basename(archive_path), '')
|
65
66
|
`unzip -o -d "#{base_path}" #{archive_path}`
|
67
|
+
FileUtils.rm(archive_path)
|
66
68
|
when '.bz2'
|
67
69
|
`bzip2 -d #{archive_path}`
|
68
70
|
when '.s'
|
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
|
@@ -314,6 +320,11 @@ module GreenHat
|
|
314
320
|
@location = [spot]
|
315
321
|
end
|
316
322
|
|
323
|
+
# Shell Context Location
|
324
|
+
def self.move_shell(spot)
|
325
|
+
@location = [GreenHat::Shell, spot]
|
326
|
+
end
|
327
|
+
|
317
328
|
# Append to Location
|
318
329
|
def self.submodule!
|
319
330
|
spot = @list.shift
|
@@ -332,7 +343,6 @@ module GreenHat
|
|
332
343
|
# Reader to Get Last Location's Available Methods / Keep Helper Methods
|
333
344
|
def self.current_methods
|
334
345
|
current_location.methods(false).map(&:to_s)
|
335
|
-
# .reject { |x| x.include? '_help' }
|
336
346
|
end
|
337
347
|
|
338
348
|
def self.current_submodules
|
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
|
@@ -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
|
-
Cli.quiet!
|
64
|
-
# Don't Use Pagination
|
65
|
-
GreenHat::Shell.report(['--raw'])
|
66
|
-
exit 0
|
67
|
-
elsif flags?(%i[full-report f], flags)
|
68
|
-
Cli.quiet!
|
69
|
-
# Don't Use Pagination
|
70
|
-
GreenHat::Shell.report(['--raw', '--full'])
|
71
|
-
exit 0
|
72
|
-
elsif flags?(%i[markdown m], flags)
|
73
|
-
Cli.quiet!
|
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/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
|
+
# =================================================================
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# GreenHat Namespace
|
2
|
+
module GreenHat
|
3
|
+
# Reports Parent Class
|
4
|
+
module Reports
|
5
|
+
# Method Helper Module
|
6
|
+
module InternalMethods
|
7
|
+
# Archive Header Printer
|
8
|
+
def archive_header(color = :blue)
|
9
|
+
puts archive.friendly_name.pastel(color)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Header Printer
|
13
|
+
def header(text, color = :bright_yellow, bold = :bold)
|
14
|
+
puts text.pastel(color, bold)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Raw Print
|
18
|
+
def cat(name, show_output, block)
|
19
|
+
thing = archive.thing? name
|
20
|
+
return unless thing
|
21
|
+
|
22
|
+
output = instance_exec(thing.raw_full, &block)
|
23
|
+
show output if show_output
|
24
|
+
end
|
25
|
+
|
26
|
+
# Parsed Print
|
27
|
+
def info(name, show_output, block)
|
28
|
+
thing = archive.thing? name
|
29
|
+
return unless thing
|
30
|
+
|
31
|
+
output = instance_exec(thing.data, &block)
|
32
|
+
show output if show_output
|
33
|
+
end
|
34
|
+
|
35
|
+
# Help
|
36
|
+
def help(block)
|
37
|
+
instance_exec(&block)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Log Query
|
41
|
+
def query(query, show_output, block)
|
42
|
+
files, query_flags, query_args = GreenHat::Args.parse(Shellwords.split(query))
|
43
|
+
query_flags[:archive] = [archive.name] # Limit query to archive
|
44
|
+
query_flags[:combine] = true
|
45
|
+
|
46
|
+
# Default to everything
|
47
|
+
files = archive.things if files.empty?
|
48
|
+
|
49
|
+
results = Query.start(files, query_flags, query_args)
|
50
|
+
|
51
|
+
# Print and Exit of No Block / Show
|
52
|
+
return show(results) if block.nil? && show_output
|
53
|
+
|
54
|
+
output = instance_exec(results, &block)
|
55
|
+
show output if show_output
|
56
|
+
end
|
57
|
+
|
58
|
+
# Log Query / Assume Format
|
59
|
+
def query_format(query, show_output, block)
|
60
|
+
files, query_flags, query_args = GreenHat::Args.parse(Shellwords.split(query))
|
61
|
+
query_flags[:archive] = [archive.name] # Limit query to archive
|
62
|
+
query_flags[:combine] = true
|
63
|
+
|
64
|
+
# Default to everything
|
65
|
+
query_flags = archive.things if files.empty?
|
66
|
+
|
67
|
+
# Filter
|
68
|
+
results = GreenHat::Query.start(files, query_flags, query_args)
|
69
|
+
|
70
|
+
# Print and Exit of No Block / Show
|
71
|
+
return show(results) if block.nil? && show_output
|
72
|
+
|
73
|
+
block_output = instance_exec(results, &block)
|
74
|
+
show block_output if show_output
|
75
|
+
end
|
76
|
+
|
77
|
+
def faststats(raw, subcmd)
|
78
|
+
return true unless TTY::Which.exist? 'fast-stats'
|
79
|
+
|
80
|
+
files, _flags, cmd = ShellHelper::Faststats.parse(Shellwords.split(raw))
|
81
|
+
|
82
|
+
results = ShellHelper.file_process(files) do |file|
|
83
|
+
output = `fast-stats #{subcmd} #{cmd} #{file.file} 2>&1`
|
84
|
+
result = $CHILD_STATUS.success?
|
85
|
+
|
86
|
+
next unless result
|
87
|
+
|
88
|
+
[
|
89
|
+
file.name.pastel(:green),
|
90
|
+
output.split("\n"),
|
91
|
+
"\n"
|
92
|
+
]
|
93
|
+
end
|
94
|
+
|
95
|
+
show results.compact.flatten
|
96
|
+
end
|
97
|
+
|
98
|
+
# TODO
|
99
|
+
# results = GreenHat::ShellHelper::Faststats.run(thing, 'top') # JSON FORMAT
|
100
|
+
|
101
|
+
# Paper Render Helper
|
102
|
+
def show(value)
|
103
|
+
if value.instance_of?(Array)
|
104
|
+
value.each do |x|
|
105
|
+
output.push GreenHat::Paper.new(data: x, flags: flags).render
|
106
|
+
end
|
107
|
+
else
|
108
|
+
output.push GreenHat::Paper.new(data: value, flags: flags).render
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Line Break Helper
|
113
|
+
def br(_ = nil)
|
114
|
+
puts
|
115
|
+
end
|
116
|
+
|
117
|
+
# Store for potential Paginated Response
|
118
|
+
def puts(text = '')
|
119
|
+
output.push text
|
120
|
+
end
|
121
|
+
|
122
|
+
# Accessor Helper
|
123
|
+
def archive
|
124
|
+
archive
|
125
|
+
end
|
126
|
+
|
127
|
+
def gitlab_version
|
128
|
+
thing = archive.thing? 'gitlab/version-manifest.json'
|
129
|
+
return unless thing
|
130
|
+
|
131
|
+
puts "#{'GitLab Version'.pastel(:cyan)}: #{thing.data.build_version}"
|
132
|
+
end
|
133
|
+
|
134
|
+
# ==============================================================================
|
135
|
+
# General Helpers
|
136
|
+
# ==============================================================================
|
137
|
+
# Indentation Helper
|
138
|
+
def indent(text, indent_value = 2)
|
139
|
+
if indent_value.zero?
|
140
|
+
text
|
141
|
+
else
|
142
|
+
"#{' ' * indent_value}#{text}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def percent(value, total)
|
147
|
+
((value / total.to_f) * 100).round
|
148
|
+
end
|
149
|
+
|
150
|
+
# Number Helper
|
151
|
+
def human_size_to_number(value)
|
152
|
+
GreenHat::ShellHelper.human_size_to_number value
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|