ix-cli 0.0.19 → 0.0.21

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: 8dba21b61d4f6c800ecc40c3042d115e06b73fecfc3665314492c1dd5a69ce36
4
- data.tar.gz: 76211ce91d07872dc0823aeb12a1cf81fdab5e050b371c7bca8e5d0431c6d5f7
3
+ metadata.gz: 310ce8e1c17438e6004dd28f1dfe8f4f9501c5c7ecbca7d5efa75c4c5095e290
4
+ data.tar.gz: 8ac9335f579d2ffbfb5549409308de3250e173c35688f130d5719d2b421acd0d
5
5
  SHA512:
6
- metadata.gz: 383c703e9ed1c0d5c81fb9f61a316e4593890768d6751f4464c54d028dfbf5ffa40156e5f102e4914f3b37ea84e86b66ba6d38dca1ddea841e8e7d0b34f20729
7
- data.tar.gz: cff65c1d968fa28866110238d0c6e57e3fa9a82da8fa8a9f5cbd188bbcb5104c284b54d4bcf358111da3e3c1f104b9398902a38ef0ebc304f08d345f0b71298a
6
+ metadata.gz: 4cbf17184a8274e7579e8cbb660f972890f533421840ca0f43c2e7a2538249f5f8f022b766e464b0130ee5735629f1522ea15c0257cfdadaef2f4906cfe5d105
7
+ data.tar.gz: e5ed936aec0c930d755ff5d267425aaa01473f1220bbf9e2d9424b265e354566de834a0bb967f4e90982e2c7c78bb9e01610fe64fb0d87da81db1d8fc50ee15f
data/bin/ix-file-exists CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  STDIN.each_line do |line|
4
4
 
5
- if File.exists?(line.chomp)
5
+ if File.exist?(line.chomp)
6
6
  puts "yes #{line.chomp}"
7
7
  else
8
8
  puts " no #{line.chomp}"
data/bin/ix-files CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  STDIN.each_line do |line|
4
4
  fname = line.chomp
5
- if File.exists?(fname)
5
+ if File.exist?(fname)
6
6
  puts fname
7
7
  end
8
8
  end
data/bin/ix-json-filter CHANGED
@@ -10,17 +10,22 @@ OptionParser.new do |opts|
10
10
 
11
11
  opts.banner = "Usage: #{$0} [OPTIONS]"
12
12
 
13
- opts.on('-f', '--field [NAME]', 'Field.') do |value|
13
+ opts.on('-f', '--field [STRING]', 'Field.') do |value|
14
14
  options[:field] = value
15
15
  end
16
16
 
17
+ opts.on('-v', '--value [STRING]', 'Field.') do |value|
18
+ options[:field] = value
19
+ end
20
+
21
+
17
22
  opts.on('-m', '--match [REGEX]', 'Match.') do |value|
18
23
  options[:match] = value
19
24
  end
20
25
 
21
26
  end.parse!
22
27
 
23
- required_options = [:field, :match]
28
+ required_options = [:match]
24
29
  required_options.each do |option|
25
30
  unless options[option]
26
31
  $stderr.puts "Can not run #{option.to_s} was not given."
@@ -28,11 +33,23 @@ required_options.each do |option|
28
33
  end
29
34
  end
30
35
 
36
+ if options[:field].nil? && options[:value].nil?
37
+ $stderr.puts "Can not run without field or value."
38
+ exit 1
39
+ end
40
+
31
41
  STDIN.each_line do |line|
32
42
  begin
33
43
  json = JSON.parse(line)
34
- if json[options[:field]].to_s =~ /#{options[:match]}/
35
- puts line
44
+ if options[:field]
45
+ if json[options[:field]].to_s =~ /#{options[:match]}/
46
+ puts line
47
+ end
48
+ end
49
+ if options[:value]
50
+ if json.values.any? { |v| v.to_s =~ /#{options[:match]}/ }
51
+ puts line
52
+ end
36
53
  end
37
54
  rescue JSON::ParserError => e
38
55
  $stderr.puts "Error parsing line: #{line}"
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-template CHANGED
@@ -240,7 +240,7 @@ require 'digest/md5'
240
240
  source = ARGV[0]
241
241
  target = ARGV[1]
242
242
 
243
- unless File.exists?(source)
243
+ unless File.exist?(source)
244
244
  $stderr.puts "File not found: #{source}"
245
245
  exit 0
246
246
  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 'hirb'
4
+ require 'isna'
5
+ require 'optparse'
6
6
 
7
- hashes = []
7
+ options = {}
8
+ options[:orient] = 'top'
8
9
 
9
- STDIN.each_line do |line|
10
- if line.include? '}'
11
- hash = JSON.parse(line)
12
- hashes.push(hash)
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
- vertical = false
17
- if ARGV[0] == '-v'
18
- vertical = true
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
- puts Hirb::Helpers::Table.render(hashes, :resize => false, :vertical => vertical)
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-slider CHANGED
@@ -149,7 +149,7 @@ end
149
149
  $stdout.sync = true
150
150
  puts legend
151
151
 
152
- if File.exists?($options[:file])
152
+ if File.exist?($options[:file])
153
153
  $options[:current_value] = File.read($options[:file]).to_i
154
154
  end
155
155
 
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
 
data/bin/ix-stack CHANGED
@@ -10,7 +10,7 @@ STDIN.each do |line|
10
10
  line_number = chunks[1].to_i
11
11
  spacer = file.scan(/^\s*/)[0]
12
12
  file.gsub!(/^\s+/, '')
13
- unless File.exists? file
13
+ unless File.exist? file
14
14
  puts line
15
15
  next
16
16
  end
data/bin/ix-stack-2 CHANGED
@@ -14,7 +14,7 @@ STDIN.each_line do |stack_line|
14
14
  range_right = (line..(line + 5)).to_a
15
15
  full_range = (range_left + range_right).sort
16
16
 
17
- if File.exists?(filepath)
17
+ if File.exist?(filepath)
18
18
  file_line = 0
19
19
  File.read(filepath).each_line do |fline|
20
20
  file_line += 1
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
+
data/bin/ix-template CHANGED
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  if ARGV[0]
19
19
  template = "#{ARGV[0]}"
20
- if File.exists?(template)
20
+ if File.exist?(template)
21
21
  template = File.read(template)
22
22
  end
23
23
  end
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.19
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