dldinternet-mixlib-thor 0.3.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -5
- data/dldinternet-mixlib-thor.gemspec +1 -0
- data/lib/dldinternet/formatters/awesome.rb +4 -5
- data/lib/dldinternet/formatters/basic.rb +203 -7
- data/lib/dldinternet/formatters/table.rb +14 -57
- data/lib/dldinternet/thor/command.rb +12 -4
- data/lib/dldinternet/thor/mixins/no_commands.rb +125 -69
- data/lib/dldinternet/thor/version.rb +1 -1
- metadata +16 -3
- data/atlassian-ide-plugin.xml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e514a24e53b9e7fcb0f1fa73351a0dd13094728f
|
4
|
+
data.tar.gz: e84ce7160a7bb7c8f830ad1372341e44da96107f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddaf17824e3cb6444869eb9d1248e06ef4c629b910b8adbaed403249156f34654f9c5c0f5e2c219364c82160909fc5c92fb338c63449a2c9f294e44376e0eeea
|
7
|
+
data.tar.gz: 295010865bc6e1373a7b5f1268a38bbff5fc6066126024d8ce1874fa538de18251b90c0c44f921e1241cf3baec54d6a09b1620e280d0011b6744e3594b2825d1
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dldinternet-mixlib-thor (0.
|
4
|
+
dldinternet-mixlib-thor (0.6.0)
|
5
5
|
awesome_print
|
6
6
|
command_line_reporter (~> 3.3, >= 3.3.6)
|
7
|
+
config-factory
|
7
8
|
dldinternet-mixlib-logging (>= 0.7.0)
|
8
9
|
hashie
|
9
10
|
inifile
|
@@ -13,11 +14,12 @@ PATH
|
|
13
14
|
GEM
|
14
15
|
remote: https://rubygems.org/
|
15
16
|
specs:
|
16
|
-
awesome_print (1.
|
17
|
+
awesome_print (1.8.0)
|
17
18
|
builder (3.2.3)
|
18
19
|
colored (1.2)
|
19
20
|
command_line_reporter (3.3.6)
|
20
21
|
colored (>= 1.2)
|
22
|
+
config-factory (0.0.9)
|
21
23
|
cucumber (0.10.7)
|
22
24
|
builder (>= 2.1.2)
|
23
25
|
diff-lcs (>= 1.1.2)
|
@@ -29,11 +31,11 @@ GEM
|
|
29
31
|
logging (~> 2.1, >= 2.1.0)
|
30
32
|
gherkin (2.4.21)
|
31
33
|
json (>= 1.4.6)
|
32
|
-
hashie (3.5.
|
34
|
+
hashie (3.5.6)
|
33
35
|
inifile (3.0.0)
|
34
36
|
json (2.0.3)
|
35
37
|
little-plugger (1.1.4)
|
36
|
-
logging (2.2.
|
38
|
+
logging (2.2.2)
|
37
39
|
little-plugger (~> 1.1)
|
38
40
|
multi_json (~> 1.10)
|
39
41
|
multi_json (1.12.1)
|
@@ -44,7 +46,7 @@ GEM
|
|
44
46
|
rubygems-tasks (0.2.4)
|
45
47
|
term-ansicolor (1.4.0)
|
46
48
|
tins (~> 1.0)
|
47
|
-
thor (0.
|
49
|
+
thor (0.20.0)
|
48
50
|
tins (1.13.2)
|
49
51
|
|
50
52
|
PLATFORMS
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_dependency 'hashie' #, '~> '
|
25
25
|
gem.add_dependency 'command_line_reporter', '~> 3.3', '>= 3.3.6'
|
26
26
|
gem.add_dependency 'dldinternet-mixlib-logging', '>= 0.7.0'
|
27
|
+
gem.add_dependency 'config-factory' #, '~> '
|
27
28
|
|
28
29
|
gem.add_development_dependency 'bundler', '~> 1.0'
|
29
30
|
gem.add_development_dependency 'rake', '~> 10'
|
@@ -1,19 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'awesome_print'
|
4
|
+
require 'dldinternet/formatters/basic'
|
4
5
|
|
5
6
|
module DLDInternet
|
6
7
|
module Formatters
|
7
8
|
# Awesome formatter
|
8
|
-
class Awesome
|
9
|
+
class Awesome < DLDInternet::Formatters::Basic
|
9
10
|
attr_reader :format
|
10
11
|
attr_reader :object
|
11
12
|
attr_reader :title
|
12
13
|
|
13
|
-
def initialize(obj, format,
|
14
|
-
|
15
|
-
@format = format
|
16
|
-
@title = title
|
14
|
+
def initialize(obj, format, options)
|
15
|
+
super
|
17
16
|
end
|
18
17
|
|
19
18
|
def format_it
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
require 'yaml'
|
5
|
+
require 'awesome_print'
|
6
|
+
require 'hashie/mash'
|
5
7
|
|
6
8
|
module DLDInternet
|
7
9
|
module Formatters
|
@@ -10,25 +12,219 @@ module DLDInternet
|
|
10
12
|
attr_reader :format
|
11
13
|
attr_reader :object
|
12
14
|
attr_reader :title
|
15
|
+
attr_reader :columns
|
16
|
+
attr_reader :is_a_hash
|
17
|
+
attr_reader :widths
|
18
|
+
attr_reader :options
|
13
19
|
|
14
|
-
def initialize(obj, format,
|
20
|
+
def initialize(obj, format, options)
|
21
|
+
@options = options
|
15
22
|
@object = obj
|
16
23
|
@format = format
|
17
|
-
@title = title
|
24
|
+
@title = options[:title] || nil
|
25
|
+
@is_a_hash = @object.is_a?(Hash)
|
26
|
+
@columns = options[:columns] || nil
|
27
|
+
if @columns
|
28
|
+
@columns = Hashie::Mash.new(Hash[@columns.split(/\s*,\s*/).map{ |c| [c, nil]}])
|
29
|
+
@columns.dup.map{ |h,v|
|
30
|
+
submap(h, v)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def header_it(item=nil)
|
36
|
+
item ||=
|
37
|
+
if @is_a_hash
|
38
|
+
if @columns.nil?
|
39
|
+
object.keys
|
40
|
+
else
|
41
|
+
@columns.keys
|
42
|
+
end
|
43
|
+
else
|
44
|
+
object.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
format_item item, true
|
18
48
|
end
|
19
49
|
|
20
|
-
def format_it
|
50
|
+
def format_it(item=nil)
|
51
|
+
item ||=
|
52
|
+
if @is_a_hash
|
53
|
+
if @columns.nil?
|
54
|
+
object
|
55
|
+
else
|
56
|
+
hsh = {}
|
57
|
+
object.each do |key,val|
|
58
|
+
hsh[key] = val if @columns.keys.include?(key)
|
59
|
+
end
|
60
|
+
hsh
|
61
|
+
end
|
62
|
+
else
|
63
|
+
object
|
64
|
+
end
|
65
|
+
|
66
|
+
format_item item
|
67
|
+
end
|
68
|
+
|
69
|
+
# :reek:DuplicateMethodCall {enabled: false}
|
70
|
+
def widths
|
71
|
+
unless @widths
|
72
|
+
@widths = Hashie::Mash.new
|
73
|
+
if @is_a_hash
|
74
|
+
widths_hash
|
75
|
+
else
|
76
|
+
widths_array
|
77
|
+
end
|
78
|
+
end
|
79
|
+
@widths
|
80
|
+
end
|
81
|
+
|
82
|
+
# :reek:DuplicateMethodCall {enabled: false}
|
83
|
+
def widths=(w)
|
84
|
+
@widths = w
|
85
|
+
end
|
86
|
+
|
87
|
+
# :reek:DuplicateMethodCall {enabled: false}
|
88
|
+
def table_widths
|
89
|
+
if object.is_a?(Array) && object.size > 0 && object[0].is_a?(Hash)
|
90
|
+
tws = nil
|
91
|
+
object.each do |obj|
|
92
|
+
fmt = self.class.new(obj, format, options)
|
93
|
+
tws ||= fmt.widths
|
94
|
+
fmt.widths.each { |c,w|
|
95
|
+
if tws[c] < w
|
96
|
+
tws[c] = w
|
97
|
+
end
|
98
|
+
}
|
99
|
+
end
|
100
|
+
@widths = tws
|
101
|
+
else
|
102
|
+
widths
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def format_item(item, header=false)
|
21
109
|
case format.to_s.downcase
|
22
110
|
when 'json'
|
23
|
-
JSON.pretty_generate(
|
111
|
+
JSON.pretty_generate(item)
|
24
112
|
when 'yaml'
|
25
|
-
|
113
|
+
item.to_yaml
|
26
114
|
when 'none'
|
27
|
-
|
115
|
+
item
|
116
|
+
else
|
117
|
+
if item.is_a?(Array) # header ||
|
118
|
+
if widths.is_a?(Hash)
|
119
|
+
if @columns.nil?
|
120
|
+
wdths = widths.map { |c,w| w }
|
121
|
+
else
|
122
|
+
wdths = widths.map { |c,w| w if @columns.include?(c) }.select{ |w| !w.nil? }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
i = -1
|
126
|
+
nitm = item.map{ |c|
|
127
|
+
i += 1
|
128
|
+
w = wdths[i]
|
129
|
+
sprintf("%-#{w}s", c.to_s)
|
130
|
+
}
|
131
|
+
nitm.join(" ")
|
132
|
+
elsif item.is_a?(Hash)
|
133
|
+
item.map do |key, val|
|
134
|
+
if @columns.nil? || (@columns.keys.include?(key) && @columns[key].nil?)
|
135
|
+
sprintf("%-#{widths[key]}s", val.to_s)
|
136
|
+
else
|
137
|
+
sprintf("%-#{widths[key]}s", subcolumn(key, val))
|
138
|
+
end
|
139
|
+
end
|
140
|
+
else
|
141
|
+
item.to_s
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def submap(col, val, sub=nil)
|
147
|
+
sub ||= @columns
|
148
|
+
m = col.match(/^([^.]+)\.(.*)$/)
|
149
|
+
if m
|
150
|
+
val = sub[m[1]]
|
151
|
+
val ||= Hashie::Mash.new
|
152
|
+
submap(m[2], val, val)
|
153
|
+
sub[m[1]] = val
|
154
|
+
sub.delete(col)
|
28
155
|
else
|
29
|
-
|
156
|
+
if val
|
157
|
+
val[col] = nil
|
158
|
+
else
|
159
|
+
sub[col] = val
|
160
|
+
end
|
30
161
|
end
|
31
162
|
end
|
163
|
+
|
164
|
+
def widths_array
|
165
|
+
idx = 0
|
166
|
+
@object.each do |val|
|
167
|
+
set_width(idx, val)
|
168
|
+
idx += 1
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def widths_hash
|
173
|
+
@object.each do |key, _|
|
174
|
+
klen = key.to_s.length
|
175
|
+
wid = @widths[key]
|
176
|
+
@widths[key] = klen if !wid || wid < klen
|
177
|
+
end
|
178
|
+
obj_width(@object)
|
179
|
+
end
|
180
|
+
|
181
|
+
def set_width(idx, val)
|
182
|
+
vlen = val.to_s.length
|
183
|
+
wid = @widths[idx] || 0
|
184
|
+
@widths[idx] = vlen if wid < vlen
|
185
|
+
end
|
186
|
+
|
187
|
+
def obj_width(obj)
|
188
|
+
obj.each do |key, val|
|
189
|
+
set_width(key, val)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def subcolumn(key, val, sub=nil)
|
194
|
+
sub ||= @columns
|
195
|
+
if sub[key]
|
196
|
+
if sub[key].is_a?(Hash)
|
197
|
+
vals = subvalues(key, val, sub)
|
198
|
+
if vals.is_a?(Array)
|
199
|
+
vals.flatten!
|
200
|
+
# vals = vals[0] if vals.size == 1
|
201
|
+
end
|
202
|
+
column(vals.to_s)
|
203
|
+
else
|
204
|
+
column(val.to_s) if sub.has_key?(m[1]) && sub[m[1]].nil?
|
205
|
+
end
|
206
|
+
else
|
207
|
+
column(val.to_s) if sub.has_key?(key) # && sub[key].nil?)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def subvalues(key, val, sub)
|
212
|
+
if sub[key].is_a?(Hash)
|
213
|
+
sub[key].keys.map {|k|
|
214
|
+
case val.class.name
|
215
|
+
when /^Hash/
|
216
|
+
val[k]
|
217
|
+
when /^Array/
|
218
|
+
val.map {|v|
|
219
|
+
subvalues(k, v[k], sub[key])
|
220
|
+
}
|
221
|
+
end
|
222
|
+
}
|
223
|
+
else
|
224
|
+
val
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
32
228
|
end
|
33
229
|
end
|
34
230
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'dldinternet/formatters/basic'
|
3
4
|
require 'dldinternet/formatters/colors'
|
4
|
-
require 'awesome_print'
|
5
5
|
require 'command_line_reporter'
|
6
6
|
|
7
7
|
module DLDInternet
|
@@ -11,25 +11,22 @@ module DLDInternet
|
|
11
11
|
class Table < DLDInternet::Formatters::Basic
|
12
12
|
include CommandLineReporter
|
13
13
|
|
14
|
-
|
15
|
-
attr_reader :is_a_hash
|
16
|
-
|
17
|
-
def initialize(obj, format, title)
|
14
|
+
def initialize(obj, format, options)
|
18
15
|
super
|
19
|
-
#
|
20
|
-
@
|
21
|
-
@is_a_hash = @object[0].is_a?(Hash)
|
16
|
+
# @object = [@object] unless @object.is_a?(Array)
|
17
|
+
@values = Hashie::Mash.new
|
22
18
|
end
|
23
19
|
|
24
20
|
def run
|
25
21
|
suppress_output
|
26
22
|
|
27
|
-
header(title: @title, align: 'center') if @title
|
23
|
+
header(title: @title, align: 'center') if @title #&& !@title.empty?
|
28
24
|
|
29
25
|
table border: true, encoding: :ascii do
|
30
26
|
header_row
|
31
27
|
idx = 0
|
32
|
-
@object.
|
28
|
+
list = @object.is_a?(Array) ? @object : [@object]
|
29
|
+
list.each do |obj|
|
33
30
|
obj_row(idx, obj)
|
34
31
|
end
|
35
32
|
end
|
@@ -44,7 +41,7 @@ module DLDInternet
|
|
44
41
|
if @is_a_hash
|
45
42
|
row color: 'light_yellow', bold: true, encoding: :ascii do
|
46
43
|
@object[0].each do |key, _|
|
47
|
-
column key.to_s, width: widths[key]
|
44
|
+
column key.to_s, width: widths[key] if (@columns.nil? || @columns.keys.include?(key))
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
@@ -53,8 +50,12 @@ module DLDInternet
|
|
53
50
|
def obj_row(idx, obj)
|
54
51
|
row color: 'white', bold: false do
|
55
52
|
if @is_a_hash
|
56
|
-
obj.each do |
|
57
|
-
|
53
|
+
obj.each do |key, val|
|
54
|
+
if @columns.nil? || (@columns.keys.include?(key) && @columns[key].nil?)
|
55
|
+
column val.to_s
|
56
|
+
else
|
57
|
+
subcolumn(key, val)
|
58
|
+
end
|
58
59
|
end
|
59
60
|
else
|
60
61
|
column obj.to_s, width: widths[idx]
|
@@ -63,50 +64,6 @@ module DLDInternet
|
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
|
-
# :reek:DuplicateMethodCall {enabled: false}
|
67
|
-
def widths
|
68
|
-
unless @widths
|
69
|
-
@widths = Hashie::Mash.new
|
70
|
-
if @is_a_hash
|
71
|
-
widths_hash
|
72
|
-
else
|
73
|
-
widths_array
|
74
|
-
end
|
75
|
-
end
|
76
|
-
@widths
|
77
|
-
end
|
78
|
-
|
79
|
-
def widths_array
|
80
|
-
idx = 0
|
81
|
-
@object.each do |val|
|
82
|
-
set_width(idx, val)
|
83
|
-
idx += 1
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def widths_hash
|
88
|
-
@object[0].each do |key, _|
|
89
|
-
klen = key.to_s.length
|
90
|
-
wid = @widths[key]
|
91
|
-
@widths[key] = klen if !wid || wid < klen
|
92
|
-
end
|
93
|
-
@object.each do |obj|
|
94
|
-
obj_width(obj)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def set_width(idx, val)
|
99
|
-
vlen = val.to_s.length
|
100
|
-
wid = @widths[idx] || 0
|
101
|
-
@widths[idx] = vlen if wid < vlen
|
102
|
-
end
|
103
|
-
|
104
|
-
def obj_width(obj)
|
105
|
-
obj.each do |key, val|
|
106
|
-
set_width(key, val)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
67
|
def format_it
|
111
68
|
run
|
112
69
|
end
|
@@ -56,10 +56,18 @@ module DLDInternet
|
|
56
56
|
def initialize(args = [], local_options = {}, config = {})
|
57
57
|
super(args,local_options,config)
|
58
58
|
@log_level = :warn #|| @config[:log_level].to_sym
|
59
|
-
@formatter ||= ->(hsh,
|
60
|
-
|
61
|
-
|
62
|
-
@
|
59
|
+
@formatter ||= ->(hsh, opts) {
|
60
|
+
default_formatter(hsh, opts)
|
61
|
+
}
|
62
|
+
@writer ||= ->(str) {
|
63
|
+
puts str
|
64
|
+
}
|
65
|
+
@header ||= ->(res, fmtr=nil) {
|
66
|
+
default_header(res, fmtr)
|
67
|
+
}
|
68
|
+
@format ||= ->(res, fmtr=nil) {
|
69
|
+
default_format(res, nil, fmtr)
|
70
|
+
}
|
63
71
|
end
|
64
72
|
|
65
73
|
desc "help [COMMAND]", "Describe available commands or one specific command"
|
@@ -5,6 +5,7 @@ require 'dldinternet/formatters'
|
|
5
5
|
require 'hashie/mash'
|
6
6
|
require 'dldinternet/thor/version'
|
7
7
|
require 'inifile'
|
8
|
+
require 'config/factory'
|
8
9
|
|
9
10
|
module DLDInternet
|
10
11
|
module Thor
|
@@ -30,6 +31,76 @@ module DLDInternet
|
|
30
31
|
@options[:output] ||= @options[:format]
|
31
32
|
end
|
32
33
|
|
34
|
+
def load_inifile
|
35
|
+
unless File.exist?(@options[:inifile])
|
36
|
+
raise "#{@options[:inifile]} not found!"
|
37
|
+
end
|
38
|
+
begin
|
39
|
+
ini = ::IniFile.load(@options[:inifile])
|
40
|
+
ini['global'].each{ |key,value|
|
41
|
+
@options[key.to_s]=value
|
42
|
+
ENV[key.to_s]=value
|
43
|
+
}
|
44
|
+
def _expand(k,v,regex,rerun)
|
45
|
+
matches = v.match(regex)
|
46
|
+
if matches
|
47
|
+
var = matches[1]
|
48
|
+
if options[var]
|
49
|
+
options[k]=v.gsub(/\%\(#{var}\)/,options[var]).gsub(/\%#{var}/,options[var])
|
50
|
+
else
|
51
|
+
rerun[var] = 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
pending = nil
|
57
|
+
rerun = {}
|
58
|
+
begin
|
59
|
+
pending = rerun
|
60
|
+
rerun = {}
|
61
|
+
options.to_hash.each{|k,v|
|
62
|
+
if v.to_s.match(/\%/)
|
63
|
+
_expand(k,v,%r'[^\\]\%\((\w+)\)', rerun)
|
64
|
+
_expand(k,v,%r'[^\\]\%(\w+)', rerun)
|
65
|
+
end
|
66
|
+
}
|
67
|
+
# Should break out the first time that we make no progress!
|
68
|
+
end while pending != rerun
|
69
|
+
rescue ::IniFile::Error => e
|
70
|
+
# noop
|
71
|
+
rescue ::Exception => e
|
72
|
+
@logger.error "#{e.class.name} #{e.message}"
|
73
|
+
raise e
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def load_config
|
78
|
+
if File.exist?(@options[:config])
|
79
|
+
begin
|
80
|
+
envs = ::Config::Factory::Environments.load_file(@options[:config])
|
81
|
+
if envs and envs.is_a?(Hash) and @options[:environment]
|
82
|
+
@options[:environments] = ::Hashie::Mash.new(envs)
|
83
|
+
else
|
84
|
+
yaml = ::YAML.load(File.read(@options[:config]))
|
85
|
+
if yaml
|
86
|
+
yaml.each {|key, value|
|
87
|
+
@options[key.to_s.gsub(%r{[-]}, '_').to_sym]=value
|
88
|
+
}
|
89
|
+
else
|
90
|
+
msg = "#{options.config} is not a valid configuration!"
|
91
|
+
@logger.error msg
|
92
|
+
raise StandardError.new(msg)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
rescue ::Exception => e
|
96
|
+
@logger.error "#{e.class.name} #{e.message}"
|
97
|
+
raise e
|
98
|
+
end
|
99
|
+
else
|
100
|
+
@logger.warn "#{options.config} not found"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
33
104
|
def parse_options
|
34
105
|
validate_options
|
35
106
|
|
@@ -60,63 +131,20 @@ module DLDInternet
|
|
60
131
|
}
|
61
132
|
}
|
62
133
|
@config[:log_levels] ||= LOG_LEVELS
|
134
|
+
@options[:log_config] = @config
|
63
135
|
# initLogging(@config)
|
64
136
|
@logger = getLogger(@config)
|
65
137
|
|
66
138
|
if @options[:inifile]
|
67
139
|
@options[:inifile] = File.expand_path(@options[:inifile])
|
68
|
-
|
69
|
-
raise "#{@options[:inifile]} not found!"
|
70
|
-
end
|
71
|
-
begin
|
72
|
-
ini = ::IniFile.load(@options[:inifile])
|
73
|
-
ini['global'].each{ |key,value|
|
74
|
-
@options[key.to_s]=value
|
75
|
-
ENV[key.to_s]=value
|
76
|
-
}
|
77
|
-
def _expand(k,v,regex,rerun)
|
78
|
-
matches = v.match(regex)
|
79
|
-
if matches
|
80
|
-
var = matches[1]
|
81
|
-
if options[var]
|
82
|
-
options[k]=v.gsub(/\%\(#{var}\)/,options[var]).gsub(/\%#{var}/,options[var])
|
83
|
-
else
|
84
|
-
rerun[var] = 1
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
pending = nil
|
90
|
-
rerun = {}
|
91
|
-
begin
|
92
|
-
pending = rerun
|
93
|
-
rerun = {}
|
94
|
-
options.to_hash.each{|k,v|
|
95
|
-
if v.to_s.match(/\%/)
|
96
|
-
_expand(k,v,%r'[^\\]\%\((\w+)\)', rerun)
|
97
|
-
_expand(k,v,%r'[^\\]\%(\w+)', rerun)
|
98
|
-
end
|
99
|
-
}
|
100
|
-
# Should break out the first time that we make no progress!
|
101
|
-
end while pending != rerun
|
102
|
-
rescue ::IniFile::Error => e
|
103
|
-
# noop
|
104
|
-
rescue ::Exception => e
|
105
|
-
@logger.error "#{e.class.name} #{e.message}"
|
106
|
-
raise e
|
107
|
-
end
|
140
|
+
load_inifile
|
108
141
|
elsif @options[:config]
|
109
142
|
@options[:config] = File.expand_path(@options[:config])
|
110
|
-
if
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
116
|
-
rescue ::Exception => e
|
117
|
-
@logger.error "#{e.class.name} #{e.message}"
|
118
|
-
raise e
|
119
|
-
end
|
143
|
+
if @options[:config] =~ /\.ini/i
|
144
|
+
@options[:inifile] = @options[:config]
|
145
|
+
load_inifile
|
146
|
+
else
|
147
|
+
load_config
|
120
148
|
end
|
121
149
|
end
|
122
150
|
if options[:debug]
|
@@ -134,22 +162,33 @@ module DLDInternet
|
|
134
162
|
@config[:output] || :none
|
135
163
|
end
|
136
164
|
|
137
|
-
def default_formatter(obj,
|
138
|
-
|
165
|
+
def default_formatter(obj, opts=nil)
|
166
|
+
opts ||= Hashie::Mash.new(options.to_h)
|
167
|
+
format_helper = DLDInternet::Formatters::Basic.new(obj, notation, title: opts[:title], columns: opts[:columns])
|
139
168
|
case notation.to_sym
|
169
|
+
when :json
|
170
|
+
when :yaml
|
140
171
|
when :none
|
141
172
|
when :basic
|
142
173
|
when :text
|
143
174
|
# noop
|
144
175
|
when :awesome
|
145
|
-
format_helper = DLDInternet::Formatters::Awesome.new(obj, notation, title)
|
146
|
-
when :json
|
147
|
-
when :yaml
|
176
|
+
format_helper = DLDInternet::Formatters::Awesome.new(obj, notation, title: opts[:title], columns: opts[:columns])
|
148
177
|
when :table
|
149
|
-
format_helper = DLDInternet::Formatters::Table.new(obj, notation, title)
|
178
|
+
format_helper = DLDInternet::Formatters::Table.new(obj, notation, title: opts[:title], columns: opts[:columns])
|
150
179
|
else
|
151
180
|
raise DLDInternet::Formatters::Error, "Unknown format requested: #{notation}"
|
152
181
|
end
|
182
|
+
format_helper
|
183
|
+
end
|
184
|
+
|
185
|
+
def default_header(obj, format_helper=nil)
|
186
|
+
format_helper ||= default_formatter(obj)
|
187
|
+
format_helper.header_it
|
188
|
+
end
|
189
|
+
|
190
|
+
def default_format(obj, opts=nil, format_helper=nil)
|
191
|
+
format_helper ||= default_formatter(obj, opts || options)
|
153
192
|
format_helper.format_it
|
154
193
|
end
|
155
194
|
|
@@ -176,18 +215,19 @@ module DLDInternet
|
|
176
215
|
end
|
177
216
|
end
|
178
217
|
|
179
|
-
def
|
180
|
-
formatter.call(obj,
|
218
|
+
def string_it(obj, fmtr=nil, header=false)
|
219
|
+
fmtr ||= @formatter.call(obj, options)
|
220
|
+
fmtr.send(header ? :header_it : :format_it, obj)
|
181
221
|
end
|
182
222
|
|
183
223
|
def write(obj)
|
184
224
|
writer.call(obj)
|
185
225
|
end
|
186
226
|
|
187
|
-
def output(obj)
|
227
|
+
def output(obj, fmtr=nil, header=false)
|
188
228
|
unless obj.nil?
|
189
229
|
hash = obj.is_a?(Array) ? obj.map { |o| hash_it(o) } : (obj.is_a?(String) ? obj : hash_it(obj))
|
190
|
-
str =
|
230
|
+
str = string_it(hash, fmtr, header)
|
191
231
|
write str
|
192
232
|
end
|
193
233
|
end
|
@@ -197,30 +237,46 @@ module DLDInternet
|
|
197
237
|
@logger.info @_invocations.map{ |_,v| v[0]}.join(' ') if options[:verbose]
|
198
238
|
end
|
199
239
|
|
200
|
-
def command_out(res)
|
240
|
+
def command_out(res, fmtr=nil)
|
241
|
+
unless fmtr
|
242
|
+
fmtr = formatter.call(res, options)
|
243
|
+
fmtr.table_widths
|
244
|
+
end
|
201
245
|
case options[:format]
|
202
|
-
when /text|none/
|
203
|
-
output
|
246
|
+
when /text|none|plain/
|
247
|
+
output(header_line(res, fmtr), fmtr, true) unless options[:header] === false
|
204
248
|
case res.class.name
|
205
249
|
when /Array/
|
206
250
|
res.each do |obj|
|
207
|
-
output format_line(obj)
|
251
|
+
output format_line(obj, fmtr)
|
208
252
|
end
|
209
253
|
# when /Hash|String/
|
210
254
|
else
|
211
|
-
output format_line(res)
|
255
|
+
output format_line(res, fmtr)
|
212
256
|
end
|
213
257
|
else
|
214
258
|
output res
|
215
259
|
end
|
216
260
|
end
|
217
261
|
|
218
|
-
def header_line()
|
219
|
-
|
262
|
+
def header_line(obj, fmtr=nil)
|
263
|
+
if obj.is_a?(String)
|
264
|
+
obj
|
265
|
+
elsif obj.is_a?(Hash)
|
266
|
+
@header.call(obj, fmtr)
|
267
|
+
elsif obj.is_a?(Array)
|
268
|
+
if obj.size > 0
|
269
|
+
header_line(obj[0], fmtr)
|
270
|
+
else
|
271
|
+
header_line({}, fmtr)
|
272
|
+
end
|
273
|
+
else
|
274
|
+
raise "Cannot produce header from this object: #{obj.class.name}"
|
275
|
+
end
|
220
276
|
end
|
221
277
|
|
222
|
-
def format_line(obj)
|
223
|
-
@format.call(obj)
|
278
|
+
def format_line(obj, fmtr=nil)
|
279
|
+
@format.call(obj, fmtr)
|
224
280
|
end
|
225
281
|
|
226
282
|
def invoke_command(command, *args) #:nodoc:
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dldinternet-mixlib-thor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christo De Lange
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -120,6 +120,20 @@ dependencies:
|
|
120
120
|
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: 0.7.0
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: config-factory
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
type: :runtime
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
123
137
|
- !ruby/object:Gem::Dependency
|
124
138
|
name: bundler
|
125
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,7 +190,6 @@ files:
|
|
176
190
|
- LICENSE.txt
|
177
191
|
- README.md
|
178
192
|
- Rakefile
|
179
|
-
- atlassian-ide-plugin.xml
|
180
193
|
- dldinternet-mixlib-thor.gemspec
|
181
194
|
- lib/dldinternet/formatters.rb
|
182
195
|
- lib/dldinternet/formatters/awesome.rb
|