command_line_reporter 4.0.3 → 5.0.0
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/command_line_reporter/column.rb +12 -8
- data/lib/command_line_reporter/formatter/nested.rb +5 -2
- data/lib/command_line_reporter/formatter/progress.rb +2 -2
- data/lib/command_line_reporter/row.rb +4 -2
- data/lib/command_line_reporter/table.rb +28 -25
- data/lib/command_line_reporter/version.rb +1 -1
- data/lib/command_line_reporter.rb +12 -5
- metadata +15 -50
- data/spec/column_spec.rb +0 -521
- data/spec/command_line_reporter_spec.rb +0 -693
- data/spec/nested_formatter_spec.rb +0 -301
- data/spec/options_validator_spec.rb +0 -24
- data/spec/progress_formatter_spec.rb +0 -74
- data/spec/row_spec.rb +0 -131
- data/spec/spec_helper.rb +0 -6
- data/spec/support/helpers/stdout.rb +0 -8
- data/spec/support/matchers/argument.rb +0 -5
- data/spec/table_spec.rb +0 -171
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cafca0188c1a52d2b617fed16ad2d87614871c868b520c9a59aad259d5470bc5
|
|
4
|
+
data.tar.gz: 15ac742903e4e3e1f1ebf4259603a761ce8414bdbb35c223113b38891b3a4d5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 790b13f4b33f7db239e785b28e96dfdd99357c0d1adfebdbf031ed865ce497373cbb4733d721f217d4c93f502b4427a8f354bfb00c120cb5b00c5ffa04d0bb8d
|
|
7
|
+
data.tar.gz: cdf0cc92fe84f449df6e8244f713f72afe242c6754b47f4bf61ccf95a86da4e9b14e2d4b1c290fe78625fe20e283fe790e939c08507e3b1511a9efa3d456f741
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'colorize'
|
|
2
2
|
|
|
3
3
|
module CommandLineReporter
|
|
4
4
|
class Column
|
|
5
5
|
include OptionsValidator
|
|
6
6
|
|
|
7
7
|
VALID_OPTIONS = %i[width padding align color bold underline reversed span wrap].freeze
|
|
8
|
-
attr_accessor :text,
|
|
8
|
+
attr_accessor :text, *VALID_OPTIONS
|
|
9
9
|
|
|
10
10
|
def initialize(text = nil, options = {})
|
|
11
11
|
validate_options(options, *VALID_OPTIONS)
|
|
@@ -14,8 +14,8 @@ module CommandLineReporter
|
|
|
14
14
|
|
|
15
15
|
self.text = text.to_s
|
|
16
16
|
|
|
17
|
-
self.wrap =
|
|
18
|
-
raise(ArgumentError, ":wrap must be word or character (got #{options[:wrap].inspect})") unless %w
|
|
17
|
+
self.wrap = options.fetch(:wrap, :character).to_s
|
|
18
|
+
raise(ArgumentError, ":wrap must be word or character (got #{options[:wrap].inspect})") unless %w[word character].include?(wrap)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def size
|
|
@@ -23,7 +23,7 @@ module CommandLineReporter
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def required_width
|
|
26
|
-
text.to_s.size + 2 * padding
|
|
26
|
+
text.to_s.size + (2 * padding)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def screen_rows
|
|
@@ -36,10 +36,11 @@ module CommandLineReporter
|
|
|
36
36
|
|
|
37
37
|
private
|
|
38
38
|
|
|
39
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
39
40
|
def reformat_wrapped(text)
|
|
40
41
|
lines = []
|
|
41
42
|
text.lines.each do |line|
|
|
42
|
-
line_words =
|
|
43
|
+
line_words = wrap == 'word' ? line.split(/\s+/) : [line]
|
|
43
44
|
line_words.each do |word|
|
|
44
45
|
current_line = lines.last
|
|
45
46
|
if current_line.nil? || current_line.size + word.size >= size
|
|
@@ -55,7 +56,9 @@ module CommandLineReporter
|
|
|
55
56
|
end
|
|
56
57
|
lines[0..-2]
|
|
57
58
|
end
|
|
59
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
58
60
|
|
|
61
|
+
# rubocop:disable Metrics/AbcSize
|
|
59
62
|
def assign_alignment_defaults(options)
|
|
60
63
|
self.span = options[:span] || 1
|
|
61
64
|
|
|
@@ -68,6 +71,7 @@ module CommandLineReporter
|
|
|
68
71
|
self.padding = options[:padding] || 0
|
|
69
72
|
self.padding = Integer(padding)
|
|
70
73
|
end
|
|
74
|
+
# rubocop:enable Metrics/AbcSize
|
|
71
75
|
|
|
72
76
|
def assign_color_defaults(options)
|
|
73
77
|
self.color = options[:color] || nil
|
|
@@ -80,7 +84,7 @@ module CommandLineReporter
|
|
|
80
84
|
# NOTE: For making underline and reversed work Change so that based on the
|
|
81
85
|
# unformatted text it determines how much spacing to add left and right
|
|
82
86
|
# then colorize the cell text
|
|
83
|
-
cell =
|
|
87
|
+
cell = str.empty? ? blank_cell : aligned_cell(str)
|
|
84
88
|
padding_str = ' ' * padding
|
|
85
89
|
padding_str + colorize(cell) + padding_str
|
|
86
90
|
end
|
|
@@ -96,7 +100,7 @@ module CommandLineReporter
|
|
|
96
100
|
when 'right'
|
|
97
101
|
str.rjust(size)
|
|
98
102
|
when 'center'
|
|
99
|
-
str.ljust((size - str.size) / 2.0 + str.size).rjust(size)
|
|
103
|
+
str.ljust(((size - str.size) / 2.0) + str.size).rjust(size)
|
|
100
104
|
end
|
|
101
105
|
end
|
|
102
106
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'singleton'
|
|
2
|
-
require '
|
|
2
|
+
require 'colorize'
|
|
3
3
|
|
|
4
4
|
module CommandLineReporter
|
|
5
5
|
class NestedFormatter
|
|
@@ -7,8 +7,10 @@ module CommandLineReporter
|
|
|
7
7
|
include OptionsValidator
|
|
8
8
|
|
|
9
9
|
VALID_OPTIONS = %i[message type complete indent_size color bold].freeze
|
|
10
|
-
attr_accessor :
|
|
10
|
+
attr_accessor :color, :bold
|
|
11
|
+
attr_writer :indent_size, :complete_string, :message_string
|
|
11
12
|
|
|
13
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
12
14
|
def format(options, block)
|
|
13
15
|
validate_options(options, *VALID_OPTIONS)
|
|
14
16
|
|
|
@@ -32,6 +34,7 @@ module CommandLineReporter
|
|
|
32
34
|
|
|
33
35
|
indent_level :decr
|
|
34
36
|
end
|
|
37
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
35
38
|
|
|
36
39
|
def message_string
|
|
37
40
|
@message_string ||= 'working'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'singleton'
|
|
2
|
-
require '
|
|
2
|
+
require 'colorize'
|
|
3
3
|
|
|
4
4
|
module CommandLineReporter
|
|
5
5
|
class ProgressFormatter
|
|
@@ -7,7 +7,7 @@ module CommandLineReporter
|
|
|
7
7
|
include OptionsValidator
|
|
8
8
|
|
|
9
9
|
VALID_OPTIONS = %i[indicator color bold].freeze
|
|
10
|
-
attr_accessor
|
|
10
|
+
attr_accessor(*VALID_OPTIONS)
|
|
11
11
|
|
|
12
12
|
def format(options, block)
|
|
13
13
|
validate_options(options, *VALID_OPTIONS)
|
|
@@ -22,6 +22,7 @@ module CommandLineReporter
|
|
|
22
22
|
columns << column
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
25
26
|
def output
|
|
26
27
|
screen_count.times do |sr|
|
|
27
28
|
border_char = use_utf8? ? "\u2503" : '|'
|
|
@@ -50,7 +51,7 @@ module CommandLineReporter
|
|
|
50
51
|
# | xxxxxxxxxxx | | (4)
|
|
51
52
|
# +-------------+------------+
|
|
52
53
|
if col.screen_rows[sr].nil?
|
|
53
|
-
line << ' ' * col.width << ' '
|
|
54
|
+
line << (' ' * col.width) << ' '
|
|
54
55
|
else
|
|
55
56
|
line << columns[mc].screen_rows[sr] << ' '
|
|
56
57
|
end
|
|
@@ -64,11 +65,12 @@ module CommandLineReporter
|
|
|
64
65
|
puts line
|
|
65
66
|
end
|
|
66
67
|
end
|
|
68
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
67
69
|
|
|
68
70
|
private
|
|
69
71
|
|
|
70
72
|
def screen_count
|
|
71
|
-
@
|
|
73
|
+
@screen_count ||= columns.map { |column| column.screen_rows.size }.max.to_i
|
|
72
74
|
end
|
|
73
75
|
|
|
74
76
|
def use_utf8?
|
|
@@ -29,9 +29,9 @@ module CommandLineReporter
|
|
|
29
29
|
|
|
30
30
|
# rubocop:disable Metrics/AbcSize
|
|
31
31
|
# rubocop:disable Metrics/CyclomaticComplexity
|
|
32
|
-
# rubocop:disable Metrics/MethodLength
|
|
33
32
|
def output
|
|
34
33
|
return if rows.empty? # we got here with nothing to print to the screen
|
|
34
|
+
|
|
35
35
|
auto_adjust_widths if width == :auto
|
|
36
36
|
|
|
37
37
|
puts separator('first') if border
|
|
@@ -43,23 +43,28 @@ module CommandLineReporter
|
|
|
43
43
|
|
|
44
44
|
puts separator('last') if border
|
|
45
45
|
end
|
|
46
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
46
47
|
|
|
47
48
|
# TODO: This doesn't appear to be used and if it is, it will not handle span appropriately
|
|
49
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
48
50
|
def auto_adjust_widths
|
|
49
51
|
column_widths = []
|
|
50
52
|
|
|
51
53
|
rows.each do |row|
|
|
52
54
|
row.columns.each_with_index do |col, i|
|
|
53
|
-
column_widths[i] = [col.required_width,
|
|
55
|
+
column_widths[i] = [col.required_width, column_widths[i] || 0].max
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
|
|
59
|
+
# rubocop:disable Style/CombinableLoops
|
|
57
60
|
rows.each do |row|
|
|
58
61
|
row.columns.each_with_index do |col, i|
|
|
59
62
|
col.width = column_widths[i]
|
|
60
63
|
end
|
|
61
64
|
end
|
|
65
|
+
# rubocop:enable Style/CombinableLoops
|
|
62
66
|
end
|
|
67
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
63
68
|
|
|
64
69
|
private
|
|
65
70
|
|
|
@@ -82,34 +87,32 @@ module CommandLineReporter
|
|
|
82
87
|
def utf8_separator(type)
|
|
83
88
|
bar = "\u2501"
|
|
84
89
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
["\u2517", "\u253B", "\u251B"]
|
|
92
|
-
end
|
|
90
|
+
parts = {
|
|
91
|
+
'first' => ["\u250F", "\u2533", "\u2513"],
|
|
92
|
+
'middle' => ["\u2523", "\u254A", "\u252B"],
|
|
93
|
+
'last' => ["\u2517", "\u253B", "\u251B"]
|
|
94
|
+
}
|
|
95
|
+
left, center, right = parts.fetch(type)
|
|
93
96
|
|
|
94
97
|
[left, center, right, bar]
|
|
95
98
|
end
|
|
96
99
|
|
|
97
100
|
def inherit_column_attrs(row)
|
|
98
|
-
row.columns.each_with_index do |
|
|
99
|
-
use_positional_attrs(
|
|
100
|
-
use_color(row,
|
|
101
|
-
use_bold(row,
|
|
101
|
+
row.columns.each_with_index do |column, index|
|
|
102
|
+
use_positional_attrs(column, index)
|
|
103
|
+
use_color(row, column, index)
|
|
104
|
+
use_bold(row, column, index)
|
|
102
105
|
end
|
|
103
106
|
end
|
|
104
107
|
|
|
105
|
-
def use_positional_attrs(
|
|
106
|
-
return if
|
|
108
|
+
def use_positional_attrs(column, index)
|
|
109
|
+
return if column.span > 1
|
|
107
110
|
|
|
108
111
|
# The positional attributes are always required to inherit to make sure the table
|
|
109
112
|
# displays properly
|
|
110
113
|
%w[align padding width].each do |attr|
|
|
111
|
-
val = rows[0].columns[
|
|
112
|
-
|
|
114
|
+
val = rows[0].columns[index].send(attr)
|
|
115
|
+
column.public_send("#{attr}=", val)
|
|
113
116
|
end
|
|
114
117
|
|
|
115
118
|
# spanning columns overrides inheritance for width
|
|
@@ -121,21 +124,21 @@ module CommandLineReporter
|
|
|
121
124
|
rows[0].header ? 1 : 0
|
|
122
125
|
end
|
|
123
126
|
|
|
124
|
-
def use_color(row,
|
|
125
|
-
if
|
|
127
|
+
def use_color(row, column, index)
|
|
128
|
+
if column.color
|
|
126
129
|
# keep default
|
|
127
130
|
elsif row.color
|
|
128
|
-
|
|
131
|
+
column.color = row.color
|
|
129
132
|
elsif inherit_from != 1
|
|
130
|
-
|
|
133
|
+
column.color = rows[inherit_from].columns[index].color
|
|
131
134
|
end
|
|
132
135
|
end
|
|
133
136
|
|
|
134
|
-
def use_bold(row,
|
|
137
|
+
def use_bold(row, column, index)
|
|
135
138
|
if row.bold
|
|
136
|
-
|
|
139
|
+
column.bold = row.bold
|
|
137
140
|
elsif inherit_from != 1
|
|
138
|
-
|
|
141
|
+
column.bold = rows[inherit_from].columns[index].bold
|
|
139
142
|
end
|
|
140
143
|
end
|
|
141
144
|
end
|
|
@@ -37,13 +37,17 @@ module CommandLineReporter
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def formatter=(type = 'nested')
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
unless type.is_a?(String)
|
|
41
|
+
@formatter = type
|
|
42
|
+
return
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
name = "#{type.capitalize}Formatter"
|
|
42
46
|
klass = %W[CommandLineReporter #{name}].inject(Kernel) { |a, e| a.const_get(e) }
|
|
43
47
|
|
|
44
48
|
# Each formatter is a singleton that responds to #instance
|
|
45
49
|
@formatter = klass.instance
|
|
46
|
-
rescue
|
|
50
|
+
rescue StandardError
|
|
47
51
|
raise ArgumentError, 'Invalid formatter specified'
|
|
48
52
|
end
|
|
49
53
|
|
|
@@ -103,7 +107,7 @@ module CommandLineReporter
|
|
|
103
107
|
options[:width] = default_options_width(options[:width])
|
|
104
108
|
options[:bold] = default_options_bold(options[:bold])
|
|
105
109
|
|
|
106
|
-
raise
|
|
110
|
+
raise ArgumentError, 'Text is wider than the available width' if text.size > options[:width]
|
|
107
111
|
|
|
108
112
|
line = align_line(text, options)
|
|
109
113
|
|
|
@@ -137,7 +141,7 @@ module CommandLineReporter
|
|
|
137
141
|
when 'right'
|
|
138
142
|
text.rjust(options[:width])
|
|
139
143
|
when 'center'
|
|
140
|
-
text.rjust((options[:width] - text.size) / 2 + text.size)
|
|
144
|
+
text.rjust(((options[:width] - text.size) / 2) + text.size)
|
|
141
145
|
end
|
|
142
146
|
end
|
|
143
147
|
|
|
@@ -170,6 +174,7 @@ module CommandLineReporter
|
|
|
170
174
|
|
|
171
175
|
def print_header(type, options)
|
|
172
176
|
return unless type == :header
|
|
177
|
+
|
|
173
178
|
vertical_spacing(options[:lines])
|
|
174
179
|
horizontal_rule(char: options[:rule], width: options[:width], color: options[:color], bold: options[:bold]) if options[:rule]
|
|
175
180
|
end
|
|
@@ -181,6 +186,7 @@ module CommandLineReporter
|
|
|
181
186
|
|
|
182
187
|
def print_footer(type, options)
|
|
183
188
|
return unless type == :footer
|
|
189
|
+
|
|
184
190
|
horizontal_rule(char: options[:rule], width: options[:width], color: options[:color], bold: options[:bold]) if options[:rule]
|
|
185
191
|
vertical_spacing(options[:lines])
|
|
186
192
|
end
|
|
@@ -225,3 +231,4 @@ module CommandLineReporter
|
|
|
225
231
|
raise ArgumentError unless %i[left center right].include?(align.to_sym)
|
|
226
232
|
end
|
|
227
233
|
end
|
|
234
|
+
# rubocop:enable Metrics/ModuleLength
|
metadata
CHANGED
|
@@ -1,44 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: command_line_reporter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 5.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wes
|
|
8
8
|
- Bailey
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name:
|
|
14
|
+
name: colorize
|
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
|
17
16
|
requirements:
|
|
18
|
-
- - "
|
|
17
|
+
- - "~>"
|
|
19
18
|
- !ruby/object:Gem::Version
|
|
20
|
-
version: 1.
|
|
21
|
-
type: :development
|
|
22
|
-
prerelease: false
|
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
-
requirements:
|
|
25
|
-
- - ">="
|
|
26
|
-
- !ruby/object:Gem::Version
|
|
27
|
-
version: 1.0.0
|
|
28
|
-
- !ruby/object:Gem::Dependency
|
|
29
|
-
name: colored
|
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
|
31
|
-
requirements:
|
|
32
|
-
- - ">="
|
|
33
|
-
- !ruby/object:Gem::Version
|
|
34
|
-
version: '1.2'
|
|
19
|
+
version: '1.1'
|
|
35
20
|
type: :runtime
|
|
36
21
|
prerelease: false
|
|
37
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
23
|
requirements:
|
|
39
|
-
- - "
|
|
24
|
+
- - "~>"
|
|
40
25
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '1.
|
|
26
|
+
version: '1.1'
|
|
42
27
|
description: This gem makes it easy to provide a report while your ruby script is
|
|
43
28
|
executing
|
|
44
29
|
email: baywes@gmail.com
|
|
@@ -56,20 +41,11 @@ files:
|
|
|
56
41
|
- lib/command_line_reporter/row.rb
|
|
57
42
|
- lib/command_line_reporter/table.rb
|
|
58
43
|
- lib/command_line_reporter/version.rb
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- spec/row_spec.rb
|
|
65
|
-
- spec/spec_helper.rb
|
|
66
|
-
- spec/support/helpers/stdout.rb
|
|
67
|
-
- spec/support/matchers/argument.rb
|
|
68
|
-
- spec/table_spec.rb
|
|
69
|
-
homepage: http://github.com/wbailey/command_line_reporter
|
|
70
|
-
licenses: []
|
|
71
|
-
metadata: {}
|
|
72
|
-
post_install_message:
|
|
44
|
+
homepage: https://github.com/wbailey/command_line_reporter
|
|
45
|
+
licenses:
|
|
46
|
+
- MIT
|
|
47
|
+
metadata:
|
|
48
|
+
rubygems_mfa_required: 'true'
|
|
73
49
|
rdoc_options: []
|
|
74
50
|
require_paths:
|
|
75
51
|
- lib
|
|
@@ -77,25 +53,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
77
53
|
requirements:
|
|
78
54
|
- - ">="
|
|
79
55
|
- !ruby/object:Gem::Version
|
|
80
|
-
version:
|
|
56
|
+
version: 3.4.0
|
|
81
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
58
|
requirements:
|
|
83
59
|
- - ">="
|
|
84
60
|
- !ruby/object:Gem::Version
|
|
85
61
|
version: '0'
|
|
86
62
|
requirements: []
|
|
87
|
-
rubygems_version: 3.
|
|
88
|
-
signing_key:
|
|
63
|
+
rubygems_version: 3.6.9
|
|
89
64
|
specification_version: 4
|
|
90
65
|
summary: A tool for providing interactive command line applications
|
|
91
|
-
test_files:
|
|
92
|
-
- spec/column_spec.rb
|
|
93
|
-
- spec/command_line_reporter_spec.rb
|
|
94
|
-
- spec/nested_formatter_spec.rb
|
|
95
|
-
- spec/options_validator_spec.rb
|
|
96
|
-
- spec/progress_formatter_spec.rb
|
|
97
|
-
- spec/row_spec.rb
|
|
98
|
-
- spec/spec_helper.rb
|
|
99
|
-
- spec/support/helpers/stdout.rb
|
|
100
|
-
- spec/support/matchers/argument.rb
|
|
101
|
-
- spec/table_spec.rb
|
|
66
|
+
test_files: []
|