ltsview 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/ltsview/parse.rb +16 -2
- data/lib/ltsview/version.rb +1 -1
- data/spec/ltsview/parse_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26f2c6952fbf7437d766d27807410ccfa7ce1e92
|
4
|
+
data.tar.gz: e0b2354decd27f2a6fc59f156ce82bdb7c36b89a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a11948b6213430c8a6ea4aa86606f8bca5613006c977cd17c614483239931056247ad104d1e4b9833aeb09d54661b74467179bd1df468a2836c6a8248c9e8ede
|
7
|
+
data.tar.gz: c9b90d58b2818b659a77d5238b8dcb1804ac860fe2ffce55dec553a078f55559b13ab7b182825e5302e867550be754250c7f2ee42093c4bb62553ff31dbe1476
|
data/README.md
CHANGED
@@ -36,6 +36,10 @@ Or install it yourself as:
|
|
36
36
|
|
37
37
|
$ cat logfile.ltsv | ltsview -k firstkey,therdkey
|
38
38
|
|
39
|
+
key select and reorder
|
40
|
+
|
41
|
+
$ cat logfile.ltsv | ltsview -k firstkey,therdkey --reorder
|
42
|
+
|
39
43
|
ignore key select
|
40
44
|
|
41
45
|
$ cat logfile.ltsv | ltsview -i firstkey,secondkey
|
@@ -69,6 +73,7 @@ Or install it yourself as:
|
|
69
73
|
* `-j`, `--json` to render json format
|
70
74
|
* `-t`, `--tag` to append tag
|
71
75
|
* `-l`, `--ltsv` to raw format
|
76
|
+
* `-o`, `--reorder` to reorder keys with `--keys` option
|
72
77
|
* `--no-colors` to no color
|
73
78
|
|
74
79
|
## Contributing
|
data/lib/ltsview/parse.rb
CHANGED
@@ -8,7 +8,8 @@ module Ltsview
|
|
8
8
|
:file => nil,
|
9
9
|
:keys => nil,
|
10
10
|
:ignore_key => nil,
|
11
|
-
:regex => nil
|
11
|
+
:regex => nil,
|
12
|
+
:reorder => false
|
12
13
|
}
|
13
14
|
option_parse options
|
14
15
|
end
|
@@ -16,7 +17,7 @@ module Ltsview
|
|
16
17
|
def print
|
17
18
|
file_or_stdin do |ltsv|
|
18
19
|
next if ltsv.nil?
|
19
|
-
line = formatter(filter(ltsv))
|
20
|
+
line = formatter(reorder(filter(ltsv)))
|
20
21
|
puts "#{tag}#{line}" unless line.nil?
|
21
22
|
$stdout.flush
|
22
23
|
end
|
@@ -36,6 +37,7 @@ module Ltsview
|
|
36
37
|
option.on('-l', '--ltsv') { |v| @options[:mode] = :ltsv }
|
37
38
|
option.on('-t', '--tag VAL'){ |v| @options[:tag] = v }
|
38
39
|
option.on('--[no-]colors'){ |v| @options[:color] = v }
|
40
|
+
option.on('-o', '--[no-]reorder') { |v| @options[:reorder] = v }
|
39
41
|
option.on('-v','--version'){ |v|
|
40
42
|
puts "LTSView version: #{Ltsview::VERSION}"
|
41
43
|
exit
|
@@ -74,6 +76,18 @@ module Ltsview
|
|
74
76
|
"@[#{@options[:tag]}] " if @options[:tag]
|
75
77
|
end
|
76
78
|
|
79
|
+
def reorder(ltsv)
|
80
|
+
if @options[:reorder] && !@options[:keys].nil?
|
81
|
+
@options[:keys].inject({}) do |hash, key|
|
82
|
+
key_sym = key.to_sym
|
83
|
+
hash[key_sym] = ltsv[key_sym]
|
84
|
+
hash
|
85
|
+
end
|
86
|
+
else
|
87
|
+
ltsv
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
77
91
|
def filter(ltsv)
|
78
92
|
matcher(ltsv).delete_if do |key, val|
|
79
93
|
!keys?(key) || ignore?(key)
|
data/lib/ltsview/version.rb
CHANGED
data/spec/ltsview/parse_spec.rb
CHANGED
@@ -117,5 +117,27 @@ describe Ltsview::Parse do
|
|
117
117
|
|
118
118
|
end
|
119
119
|
|
120
|
+
describe 'when reorder mode on' do
|
121
|
+
it 'should reorder key-value pairs with --keys option' do
|
122
|
+
parse = Ltsview::Parse.new(['--reorder', '--keys', 'foo,hoge'])
|
123
|
+
capture(:stdout){
|
124
|
+
$stdin = StringIO.new
|
125
|
+
$stdin << "hoge:fuga hago\tfoo:barbaz\n"
|
126
|
+
$stdin.rewind
|
127
|
+
parse.print
|
128
|
+
}.should eq(color("---\n:foo: barbaz\n:hoge: fuga hago\n"))
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should not reorder key-value pairs without --keys option' do
|
132
|
+
parse = Ltsview::Parse.new(['--reorder'])
|
133
|
+
capture(:stdout){
|
134
|
+
$stdin = StringIO.new
|
135
|
+
$stdin << "hoge:fuga hago\tfoo:barbaz\n"
|
136
|
+
$stdin.rewind
|
137
|
+
parse.print
|
138
|
+
}.should eq(color("---\n:hoge: fuga hago\n:foo: barbaz\n"))
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
120
142
|
end
|
121
143
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ltsview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoto SHINGAKI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ltsv
|