ix-cli 0.0.20 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3db8ee07cb2484805653a3cabccc1f4d6a63859a5bc3783fc295e8e4d4582276
4
- data.tar.gz: 3a0bf595a3177363edf3b6439158db59515b9697b5c118646207e090b356355d
3
+ metadata.gz: e6201f592feb8666f1617290e1475d0c2c2763f3d9e9fffdc6fe22b764c54602
4
+ data.tar.gz: 351cd99558c3e85c47599dea7bb938d6c19c07b1a39eedcd079549772ba53b26
5
5
  SHA512:
6
- metadata.gz: 52067dcdbc79ead6819d26e4c35bf6dbc625ffbd6c5e1d0f6177799d214b9a8ad5742a1b0f2b3102d628090a3c8ee492da82f84ad7b5612b7dc3c0d9e7506062
7
- data.tar.gz: 7f9eb41d5c9e2d552a5c7e8bb775d91cd6e08709b642180f3bb836e5687dfd474fe4a1c4b441f09ed533daaaa72ea46c1c2de7237e1c483e94433b717f8c5363
6
+ metadata.gz: 59aaabd4241f214b5f95152b69075cf78cb6b6f7c57c3a2a44960cd245d3343f240078c341a11143716e401b33fccdcc4640b708190b3be419410fcf641a6548
7
+ data.tar.gz: ea63c41c3955f956af5df4122a1e93d0853ce6e4eff83aa90050addbad2f67497163f0872c45b1805ff20ffe9daf3b9aac23bec2e519f32c1e03b37f6624c4f9
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,169 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rubygems'
4
3
  require 'json'
5
- require 'hirb'
4
+ require 'isna'
5
+ require 'optparse'
6
6
 
7
- hashes = []
7
+ options = {}
8
+ options[:orient] = 'top'
9
+ options[:transpose] = false
10
+ options[:adjust] = false
8
11
 
9
- STDIN.each_line do |line|
10
- if line.include? '}'
11
- hash = JSON.parse(line)
12
- hashes.push(hash)
12
+ OptionParser.new do |opts|
13
+
14
+ opts.banner = "Usage: #{$0} [OPTIONS]"
15
+
16
+ opts.on('-o', '--orient [STRING]', 'Orientation for headers: top, bottom, both, or none.') do |value|
17
+ options[:orient] = value
18
+ end
19
+
20
+ opts.on('-s', '--search [STRING]', 'Search for a particular string.') do |value|
21
+ options[:search] = Regexp.new(value, Regexp::IGNORECASE)
22
+ end
23
+
24
+ opts.on('-t', '--transpose', 'Transponse the table and print the output vertically.') do |value|
25
+ options[:transpose] = value
26
+ end
27
+
28
+ opts.on('-a', '--adjust', 'Adjust width of tables when in transpose mode.') do |value|
29
+ options[:adjust] = value
30
+ end
31
+
32
+ end.parse!
33
+
34
+ required_options = [:orient]
35
+ required_options.each do |option|
36
+ unless options[option]
37
+ $stderr.puts "Can not run #{option.to_s} was not given."
38
+ exit 1
39
+ end
40
+ end
41
+
42
+ def print_table(data, options)
43
+ columns = {}
44
+
45
+ data.each do |row|
46
+ row.each do |key, value|
47
+ columns[key] ||= key.size
48
+ columns[key] = value.to_s.size if value.to_s.size > columns[key]
49
+ end
50
+ end
51
+
52
+ config = {
53
+ :top_left => '╭',
54
+ :top_right => '╮',
55
+ :bottom_left => '╰',
56
+ :bottom_right => '╯',
57
+ :vertical => '│',
58
+ :horizontal => '─',
59
+ :cross => '┼',
60
+ :top => '┬',
61
+ :bottom => '┴',
62
+ :left => '├',
63
+ :right => '┤'
64
+ }
65
+
66
+ cm = columns.keys.sort.map do |key|
67
+ s = ''
68
+ value = columns[key]
69
+ s << key.ljust(value, ' ')
70
+ s
71
+ end
72
+
73
+ 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]}"
74
+ 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]}"
75
+ middle_ruler = "#{config[:left]}#{config[:horizontal]}#{(cm.map { |s| s.gsub(/./, config[:horizontal]) }).join("#{config[:horizontal]}#{config[:cross]}#{config[:horizontal]}")}#{config[:horizontal]}#{config[:right]}"
76
+
77
+ headers = "#{config[:vertical]} " + cm.join(" #{config[:vertical]} ") + " #{config[:vertical]}"
78
+
79
+ puts top_ruler
80
+
81
+ if options[:orient] == 'top' || options[:orient] == 'both'
82
+ puts headers
83
+ puts middle_ruler
13
84
  end
85
+
86
+ data.each do |row|
87
+ rm = columns.keys.sort.map do |key|
88
+ s = ''
89
+ value = row[key]
90
+ if options[:search] =~ value.to_s
91
+ s << value.to_s.ljust(columns[key], ' ').gsub(options[:search]) { |m| m.to_ansi.green.to_s }
92
+ else
93
+ s << value.to_s.ljust(columns[key], ' ')
94
+ end
95
+ s
96
+ end
97
+ puts "#{config[:vertical]} " + rm.join(" #{config[:vertical]} ") + " #{config[:vertical]}"
98
+ end
99
+
100
+ if options[:orient] == 'bottom' || options[:orient] == 'both'
101
+ puts middle_ruler
102
+ puts headers
103
+ end
104
+ puts bottom_ruler
105
+
106
+ puts "Total: #{data.size} rows"
107
+ end
108
+
109
+ def transpose(hash)
110
+ transposed = {}
111
+ hash.each do |key, value|
112
+ transposed[key] ||= []
113
+ transposed[key] << value
114
+ end
115
+ transposed
14
116
  end
15
117
 
16
- vertical = false
17
- if ARGV[0] == '-v'
18
- vertical = true
118
+ if options[:transpose]
119
+
120
+ data = []
121
+
122
+ STDIN.each_line do |line|
123
+ begin
124
+ data << JSON.parse(line)
125
+ rescue => e
126
+ $stderr.puts e.message
127
+ end
128
+ end
129
+
130
+ max_length = 0
131
+
132
+ if options[:adjust]
133
+ data.each do |object|
134
+ object.values.each do |value|
135
+ max_length = value.to_s.size if value.to_s.size > max_length
136
+ end
137
+ end
138
+ end
139
+
140
+ data.each do |object|
141
+ transposed = transpose(object)
142
+ new_data = []
143
+ transposed.each do |key, values|
144
+ values.each do |value|
145
+ new_data.push({ 'column' => key, 'value' => value.to_s.ljust(max_length, ' ')})
146
+ end
147
+ end
148
+ puts ''
149
+ print_table(new_data, options)
150
+ end
151
+
152
+ else
153
+
154
+ data = []
155
+
156
+ STDIN.each_line do |line|
157
+ begin
158
+ data << JSON.parse(line)
159
+ rescue => e
160
+ $stderr.puts e.message
161
+ end
162
+ end
163
+
164
+ exit if data.empty?
165
+
166
+ print_table(data, options)
167
+
19
168
  end
20
169
 
21
- puts Hirb::Helpers::Table.render(hashes, :resize => false, :vertical => vertical)
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+
5
+ def transpose(hash)
6
+ transposed = {}
7
+ hash.each do |key, value|
8
+ transposed[key] ||= []
9
+ transposed[key] << value
10
+ end
11
+ transposed
12
+ end
13
+
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
21
+ end
22
+ end
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('-f', '--file []', 'File with entries to be removed.') do |value|
13
- options[:file] = value
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 = [:file]
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[:file])
27
- $stderr.puts "File #{options[:file]} does not exist."
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
- inputs = []
32
- entries = []
31
+ source_list = []
32
+ remove_list = []
33
33
 
34
34
 
35
- File.read(options[:file]).each_line do |line|
36
- entries << line
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
- inputs << line
40
+ source_list << line.chomp
41
41
  end
42
42
 
43
- (inputs - entries).each do |item|
44
- puts item.chomp
43
+ (source_list - remove_list).each do |item|
44
+ puts item
45
45
  end
46
46
 
data/bin/ix-snake CHANGED
@@ -20,6 +20,6 @@ STDIN.each_line do |line|
20
20
  padding = padding[1..(padding.size - 1)]
21
21
  end
22
22
 
23
- puts padding + words.map { |word| word.downcase } * '_'
23
+ puts padding.to_s + words.map { |word| word.downcase } * '_'
24
24
  end
25
25
 
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.20
4
+ version: 0.0.22
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
@@ -460,6 +462,7 @@ files:
460
462
  - bin/ix-json-records-to-array
461
463
  - bin/ix-json-remove-key
462
464
  - bin/ix-json-replace-values
465
+ - bin/ix-json-sort
463
466
  - bin/ix-json-stats
464
467
  - bin/ix-json-swap
465
468
  - bin/ix-json-template
@@ -471,6 +474,7 @@ files:
471
474
  - bin/ix-json-to-table
472
475
  - bin/ix-json-to-table-2
473
476
  - bin/ix-json-to-yaml
477
+ - bin/ix-json-transpose
474
478
  - bin/ix-json-values
475
479
  - bin/ix-jsonpp
476
480
  - bin/ix-lake