ix-cli 0.0.20 → 0.0.21
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-sort +35 -0
- data/bin/ix-json-to-table +97 -11
- data/bin/ix-json-transpose +20 -0
- data/bin/ix-snake +1 -1
- data/bin/ix-table +22 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 310ce8e1c17438e6004dd28f1dfe8f4f9501c5c7ecbca7d5efa75c4c5095e290
|
4
|
+
data.tar.gz: 8ac9335f579d2ffbfb5549409308de3250e173c35688f130d5719d2b421acd0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cbf17184a8274e7579e8cbb660f972890f533421840ca0f43c2e7a2538249f5f8f022b766e464b0130ee5735629f1522ea15c0257cfdadaef2f4906cfe5d105
|
7
|
+
data.tar.gz: e5ed936aec0c930d755ff5d267425aaa01473f1220bbf9e2d9424b265e354566de834a0bb967f4e90982e2c7c78bb9e01610fe64fb0d87da81db1d8fc50ee15f
|
data/bin/ix-json-sort
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
|
11
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
12
|
+
|
13
|
+
opts.on('-f', '--field [STRING]', 'Field.') do |value|
|
14
|
+
options[:field] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
end.parse!
|
18
|
+
|
19
|
+
required_options = [:field]
|
20
|
+
required_options.each do |option|
|
21
|
+
unless options[option]
|
22
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
objects = []
|
28
|
+
|
29
|
+
STDIN.each_line do |line|
|
30
|
+
objects << JSON.parse(line)
|
31
|
+
end
|
32
|
+
|
33
|
+
objects.sort_by! { |object| object[options[:field]] }.each do |object|
|
34
|
+
puts object.to_json
|
35
|
+
end
|
data/bin/ix-json-to-table
CHANGED
@@ -1,21 +1,107 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'rubygems'
|
4
3
|
require 'json'
|
5
|
-
require '
|
4
|
+
require 'isna'
|
5
|
+
require 'optparse'
|
6
6
|
|
7
|
-
|
7
|
+
options = {}
|
8
|
+
options[:orient] = 'top'
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
|
12
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
13
|
+
|
14
|
+
opts.on('-o', '--orient [STRING]', 'Orientation for headers: top, bottom, both, or none.') do |value|
|
15
|
+
options[:orient] = value
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('-s', '--search [STRING]', 'Search for a particular string.') do |value|
|
19
|
+
options[:search] = Regexp.new(value, Regexp::IGNORECASE)
|
20
|
+
end
|
21
|
+
|
22
|
+
end.parse!
|
23
|
+
|
24
|
+
required_options = [:orient]
|
25
|
+
required_options.each do |option|
|
26
|
+
unless options[option]
|
27
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
28
|
+
exit 1
|
13
29
|
end
|
14
30
|
end
|
15
31
|
|
16
|
-
|
17
|
-
|
18
|
-
|
32
|
+
data = []
|
33
|
+
|
34
|
+
STDIN.each_line do |line|
|
35
|
+
data << JSON.parse(line)
|
36
|
+
end
|
37
|
+
|
38
|
+
exit if data.empty?
|
39
|
+
|
40
|
+
def print_table(data, options)
|
41
|
+
columns = {}
|
42
|
+
|
43
|
+
data.each do |row|
|
44
|
+
row.each do |key, value|
|
45
|
+
columns[key] ||= key.size
|
46
|
+
columns[key] = value.to_s.size if value.to_s.size > columns[key]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
config = {
|
51
|
+
:top_left => '╭',
|
52
|
+
:top_right => '╮',
|
53
|
+
:bottom_left => '╰',
|
54
|
+
:bottom_right => '╯',
|
55
|
+
:vertical => '│',
|
56
|
+
:horizontal => '─',
|
57
|
+
:cross => '┼',
|
58
|
+
:top => '┬',
|
59
|
+
:bottom => '┴',
|
60
|
+
:left => '├',
|
61
|
+
:right => '┤'
|
62
|
+
}
|
63
|
+
|
64
|
+
cm = columns.keys.sort.map do |key|
|
65
|
+
s = ''
|
66
|
+
value = columns[key]
|
67
|
+
s << key.ljust(value, ' ')
|
68
|
+
s
|
69
|
+
end
|
70
|
+
|
71
|
+
top_ruler = "#{config[:top_left]}#{config[:horizontal]}#{(cm.map { |s| s.gsub(/./, config[:horizontal]) }).join("#{config[:horizontal]}#{config[:top]}#{config[:horizontal]}")}#{config[:horizontal]}#{config[:top_right]}"
|
72
|
+
bottom_ruler = "#{config[:bottom_left]}#{config[:horizontal]}#{(cm.map { |s| s.gsub(/./, config[:horizontal]) }).join("#{config[:horizontal]}#{config[:bottom]}#{config[:horizontal]}")}#{config[:horizontal]}#{config[:bottom_right]}"
|
73
|
+
middle_ruler = "#{config[:left]}#{config[:horizontal]}#{(cm.map { |s| s.gsub(/./, config[:horizontal]) }).join("#{config[:horizontal]}#{config[:cross]}#{config[:horizontal]}")}#{config[:horizontal]}#{config[:right]}"
|
74
|
+
|
75
|
+
headers = "#{config[:vertical]} " + cm.join(" #{config[:vertical]} ") + " #{config[:vertical]}"
|
76
|
+
|
77
|
+
puts top_ruler
|
78
|
+
|
79
|
+
if options[:orient] == 'top' || options[:orient] == 'both'
|
80
|
+
puts headers
|
81
|
+
puts middle_ruler
|
82
|
+
end
|
83
|
+
|
84
|
+
data.each do |row|
|
85
|
+
rm = columns.keys.sort.map do |key|
|
86
|
+
s = ''
|
87
|
+
value = row[key]
|
88
|
+
if options[:search] =~ value.to_s
|
89
|
+
s << value.to_s.ljust(columns[key], ' ').gsub(options[:search]) { |m| m.to_ansi.green.to_s }
|
90
|
+
else
|
91
|
+
s << value.to_s.ljust(columns[key], ' ')
|
92
|
+
end
|
93
|
+
s
|
94
|
+
end
|
95
|
+
puts "#{config[:vertical]} " + rm.join(" #{config[:vertical]} ") + " #{config[:vertical]}"
|
96
|
+
end
|
97
|
+
|
98
|
+
if options[:orient] == 'bottom' || options[:orient] == 'both'
|
99
|
+
puts middle_ruler
|
100
|
+
puts headers
|
101
|
+
end
|
102
|
+
puts bottom_ruler
|
103
|
+
|
104
|
+
puts "Total: #{data.size} rows"
|
19
105
|
end
|
20
106
|
|
21
|
-
|
107
|
+
print_table(data, options)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
transposed = {}
|
6
|
+
|
7
|
+
STDIN.each_line do |line|
|
8
|
+
data = JSON.parse(line)
|
9
|
+
data.each do |key, value|
|
10
|
+
transposed[key] ||= []
|
11
|
+
transposed[key] << value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
transposed.each do |key, values|
|
16
|
+
values.each do |value|
|
17
|
+
puts({ :column => key, :value => value }.to_json)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/bin/ix-snake
CHANGED
data/bin/ix-table
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
|
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.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuyoshi Tlacaelel
|
@@ -156,6 +156,7 @@ executables:
|
|
156
156
|
- ix-json-records-to-array
|
157
157
|
- ix-json-remove-key
|
158
158
|
- ix-json-replace-values
|
159
|
+
- ix-json-sort
|
159
160
|
- ix-json-stats
|
160
161
|
- ix-json-swap
|
161
162
|
- ix-json-template
|
@@ -167,6 +168,7 @@ executables:
|
|
167
168
|
- ix-json-to-table
|
168
169
|
- ix-json-to-table-2
|
169
170
|
- ix-json-to-yaml
|
171
|
+
- ix-json-transpose
|
170
172
|
- ix-json-values
|
171
173
|
- ix-jsonpp
|
172
174
|
- ix-lake
|
@@ -285,6 +287,7 @@ executables:
|
|
285
287
|
- ix-symlink
|
286
288
|
- ix-tab
|
287
289
|
- ix-tabify
|
290
|
+
- ix-table
|
288
291
|
- ix-tac
|
289
292
|
- ix-task
|
290
293
|
- ix-technical
|
@@ -460,6 +463,7 @@ files:
|
|
460
463
|
- bin/ix-json-records-to-array
|
461
464
|
- bin/ix-json-remove-key
|
462
465
|
- bin/ix-json-replace-values
|
466
|
+
- bin/ix-json-sort
|
463
467
|
- bin/ix-json-stats
|
464
468
|
- bin/ix-json-swap
|
465
469
|
- bin/ix-json-template
|
@@ -471,6 +475,7 @@ files:
|
|
471
475
|
- bin/ix-json-to-table
|
472
476
|
- bin/ix-json-to-table-2
|
473
477
|
- bin/ix-json-to-yaml
|
478
|
+
- bin/ix-json-transpose
|
474
479
|
- bin/ix-json-values
|
475
480
|
- bin/ix-jsonpp
|
476
481
|
- bin/ix-lake
|
@@ -589,6 +594,7 @@ files:
|
|
589
594
|
- bin/ix-symlink
|
590
595
|
- bin/ix-tab
|
591
596
|
- bin/ix-tabify
|
597
|
+
- bin/ix-table
|
592
598
|
- bin/ix-tac
|
593
599
|
- bin/ix-task
|
594
600
|
- bin/ix-technical
|