ix-cli 0.0.21 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ix-json-to-table +137 -10
- data/bin/ix-json-transpose +11 -8
- data/bin/ix-remove +12 -12
- metadata +1 -3
- data/bin/ix-table +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 710d6adea721d5d968afcbd10b0ccec144106320bf3b1aa80adfc6ba785e7626
|
4
|
+
data.tar.gz: e6f7c467e70d58e3f81fd9daf5822707379ffb9a4daac60440f53eceee4dd39a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 183eaf434866fd17fa8d72c3a02bd8df8fb9b62277a1ab582d2ebad74592376368ed68b604d01d1980b40b324bb8ed78fad8f1cb201666d8ddcf19aa38bf3bdd
|
7
|
+
data.tar.gz: 890df17fbfbfe03773aa9b456c4ca3d3603cca13db3a0b49fc5ab1d50d42506dd6ba4babe241285dc0ab67c7e30565561f5293302473e54b322a57198ae29bda
|
data/bin/ix-json-to-table
CHANGED
@@ -6,6 +6,9 @@ require 'optparse'
|
|
6
6
|
|
7
7
|
options = {}
|
8
8
|
options[:orient] = 'top'
|
9
|
+
options[:transpose] = false
|
10
|
+
options[:adjust] = false
|
11
|
+
options[:skin] = 'round'
|
9
12
|
|
10
13
|
OptionParser.new do |opts|
|
11
14
|
|
@@ -19,6 +22,18 @@ OptionParser.new do |opts|
|
|
19
22
|
options[:search] = Regexp.new(value, Regexp::IGNORECASE)
|
20
23
|
end
|
21
24
|
|
25
|
+
opts.on('-t', '--transpose', 'Transponse the table and print the output vertically.') do |value|
|
26
|
+
options[:transpose] = value
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on('-a', '--adjust', 'Adjust width of tables when in transpose mode.') do |value|
|
30
|
+
options[:adjust] = value
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on('-i', '--skin [NAME]', 'Change the skin, can be: [round, none, ascii].') do |value|
|
34
|
+
options[:skin] = value
|
35
|
+
end
|
36
|
+
|
22
37
|
end.parse!
|
23
38
|
|
24
39
|
required_options = [:orient]
|
@@ -29,14 +44,6 @@ required_options.each do |option|
|
|
29
44
|
end
|
30
45
|
end
|
31
46
|
|
32
|
-
data = []
|
33
|
-
|
34
|
-
STDIN.each_line do |line|
|
35
|
-
data << JSON.parse(line)
|
36
|
-
end
|
37
|
-
|
38
|
-
exit if data.empty?
|
39
|
-
|
40
47
|
def print_table(data, options)
|
41
48
|
columns = {}
|
42
49
|
|
@@ -47,7 +54,9 @@ def print_table(data, options)
|
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
50
|
-
|
57
|
+
skin = {}
|
58
|
+
|
59
|
+
skin['round'] = {
|
51
60
|
:top_left => '╭',
|
52
61
|
:top_right => '╮',
|
53
62
|
:bottom_left => '╰',
|
@@ -61,6 +70,64 @@ def print_table(data, options)
|
|
61
70
|
:right => '┤'
|
62
71
|
}
|
63
72
|
|
73
|
+
skin['none'] = {
|
74
|
+
:top_left => ' ',
|
75
|
+
:top_right => ' ',
|
76
|
+
:bottom_left => ' ',
|
77
|
+
:bottom_right => ' ',
|
78
|
+
:vertical => ' ',
|
79
|
+
:horizontal => ' ',
|
80
|
+
:cross => ' ',
|
81
|
+
:top => ' ',
|
82
|
+
:bottom => ' ',
|
83
|
+
:left => ' ',
|
84
|
+
:right => ' '
|
85
|
+
}
|
86
|
+
|
87
|
+
skin['ascii'] = {
|
88
|
+
:top_left => '+',
|
89
|
+
:top_right => '+',
|
90
|
+
:bottom_left => '+',
|
91
|
+
:bottom_right => '+',
|
92
|
+
:vertical => '|',
|
93
|
+
:horizontal => '-',
|
94
|
+
:cross => '+',
|
95
|
+
:top => '+',
|
96
|
+
:bottom => '+',
|
97
|
+
:left => '+',
|
98
|
+
:right => '+'
|
99
|
+
}
|
100
|
+
|
101
|
+
skin['square'] = {
|
102
|
+
:top_left => '┌',
|
103
|
+
:top_right => '┐',
|
104
|
+
:bottom_left => '└',
|
105
|
+
:bottom_right => '┘',
|
106
|
+
:vertical => '│',
|
107
|
+
:horizontal => '─',
|
108
|
+
:cross => '┼',
|
109
|
+
:top => '┬',
|
110
|
+
:bottom => '┴',
|
111
|
+
:left => '├',
|
112
|
+
:right => '┤'
|
113
|
+
}
|
114
|
+
|
115
|
+
skin['double'] = {
|
116
|
+
:top_left => '╔',
|
117
|
+
:top_right => '╗',
|
118
|
+
:bottom_left => '╚',
|
119
|
+
:bottom_right => '╝',
|
120
|
+
:vertical => '║',
|
121
|
+
:horizontal => '═',
|
122
|
+
:cross => '╬',
|
123
|
+
:top => '╦',
|
124
|
+
:bottom => '╩',
|
125
|
+
:left => '╠',
|
126
|
+
:right => '╣'
|
127
|
+
}
|
128
|
+
|
129
|
+
config = skin[options[:skin]]
|
130
|
+
|
64
131
|
cm = columns.keys.sort.map do |key|
|
65
132
|
s = ''
|
66
133
|
value = columns[key]
|
@@ -104,4 +171,64 @@ def print_table(data, options)
|
|
104
171
|
puts "Total: #{data.size} rows"
|
105
172
|
end
|
106
173
|
|
107
|
-
|
174
|
+
def transpose(hash)
|
175
|
+
transposed = {}
|
176
|
+
hash.each do |key, value|
|
177
|
+
transposed[key] ||= []
|
178
|
+
transposed[key] << value
|
179
|
+
end
|
180
|
+
transposed
|
181
|
+
end
|
182
|
+
|
183
|
+
if options[:transpose]
|
184
|
+
|
185
|
+
data = []
|
186
|
+
|
187
|
+
STDIN.each_line do |line|
|
188
|
+
begin
|
189
|
+
data << JSON.parse(line)
|
190
|
+
rescue => e
|
191
|
+
$stderr.puts e.message
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
max_length = 0
|
196
|
+
|
197
|
+
if options[:adjust]
|
198
|
+
data.each do |object|
|
199
|
+
object.values.each do |value|
|
200
|
+
max_length = value.to_s.size if value.to_s.size > max_length
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
data.each do |object|
|
206
|
+
transposed = transpose(object)
|
207
|
+
new_data = []
|
208
|
+
transposed.each do |key, values|
|
209
|
+
values.each do |value|
|
210
|
+
new_data.push({ 'column' => key, 'value' => value.to_s.ljust(max_length, ' ')})
|
211
|
+
end
|
212
|
+
end
|
213
|
+
puts ''
|
214
|
+
print_table(new_data, options)
|
215
|
+
end
|
216
|
+
|
217
|
+
else
|
218
|
+
|
219
|
+
data = []
|
220
|
+
|
221
|
+
STDIN.each_line do |line|
|
222
|
+
begin
|
223
|
+
data << JSON.parse(line)
|
224
|
+
rescue => e
|
225
|
+
$stderr.puts e.message
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
exit if data.empty?
|
230
|
+
|
231
|
+
print_table(data, options)
|
232
|
+
|
233
|
+
end
|
234
|
+
|
data/bin/ix-json-transpose
CHANGED
@@ -2,19 +2,22 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
data = JSON.parse(line)
|
9
|
-
data.each do |key, value|
|
5
|
+
def transpose(hash)
|
6
|
+
transposed = {}
|
7
|
+
hash.each do |key, value|
|
10
8
|
transposed[key] ||= []
|
11
9
|
transposed[key] << value
|
12
10
|
end
|
11
|
+
transposed
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
STDIN.each_line do |line|
|
15
|
+
data = JSON.parse(line)
|
16
|
+
transposed = transpose(data)
|
17
|
+
transposed.each do |key, values|
|
18
|
+
values.each do |value|
|
19
|
+
puts({ :column => key, :value => value }.to_json)
|
20
|
+
end
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
data/bin/ix-remove
CHANGED
@@ -9,13 +9,13 @@ OptionParser.new do |opts|
|
|
9
9
|
|
10
10
|
opts.banner = "Usage: #{$0} [OPTIONS]"
|
11
11
|
|
12
|
-
opts.on('-
|
13
|
-
options[:
|
12
|
+
opts.on('-r', '--remove [FILEPATH]', 'File with entries that will be removed.') do |value|
|
13
|
+
options[:remove] = value
|
14
14
|
end
|
15
15
|
|
16
16
|
end.parse!
|
17
17
|
|
18
|
-
required_options = [:
|
18
|
+
required_options = [:remove]
|
19
19
|
required_options.each do |option|
|
20
20
|
unless options[option]
|
21
21
|
$stderr.puts "Can not run #{option.to_s} was not given."
|
@@ -23,24 +23,24 @@ required_options.each do |option|
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
unless File.exist?(options[:
|
27
|
-
$stderr.puts "File #{options[:
|
26
|
+
unless File.exist?(options[:remove])
|
27
|
+
$stderr.puts "File #{options[:remove]} does not exist."
|
28
28
|
exit 1
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
source_list = []
|
32
|
+
remove_list = []
|
33
33
|
|
34
34
|
|
35
|
-
File.read(options[:
|
36
|
-
|
35
|
+
File.read(options[:remove]).each_line do |line|
|
36
|
+
remove_list << line.chomp
|
37
37
|
end
|
38
38
|
|
39
39
|
STDIN.each_line do |line|
|
40
|
-
|
40
|
+
source_list << line.chomp
|
41
41
|
end
|
42
42
|
|
43
|
-
(
|
44
|
-
puts item
|
43
|
+
(source_list - remove_list).each do |item|
|
44
|
+
puts item
|
45
45
|
end
|
46
46
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ix-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuyoshi Tlacaelel
|
@@ -287,7 +287,6 @@ executables:
|
|
287
287
|
- ix-symlink
|
288
288
|
- ix-tab
|
289
289
|
- ix-tabify
|
290
|
-
- ix-table
|
291
290
|
- ix-tac
|
292
291
|
- ix-task
|
293
292
|
- ix-technical
|
@@ -594,7 +593,6 @@ files:
|
|
594
593
|
- bin/ix-symlink
|
595
594
|
- bin/ix-tab
|
596
595
|
- bin/ix-tabify
|
597
|
-
- bin/ix-table
|
598
596
|
- bin/ix-tac
|
599
597
|
- bin/ix-task
|
600
598
|
- bin/ix-technical
|
data/bin/ix-table
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
|
5
|
-
options = {}
|
6
|
-
|
7
|
-
OptionParser.new do |opts|
|
8
|
-
|
9
|
-
opts.banner = "Usage: #{$0} [OPTIONS]"
|
10
|
-
|
11
|
-
opts.on('-v', '--vertical', 'Vertical.') do |value|
|
12
|
-
options[:vertical] = value
|
13
|
-
end
|
14
|
-
|
15
|
-
end.parse!
|
16
|
-
|
17
|
-
if options[:vertical]
|
18
|
-
system 'ruby ./ix-json-transpose | ruby ./ix-json-to-table'
|
19
|
-
else
|
20
|
-
system 'ruby ./ix-json-to-table'
|
21
|
-
end
|
22
|
-
|