hotdog 0.22.1 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hotdog/application.rb +12 -7
- data/lib/hotdog/expression/semantics.rb +9 -9
- data/lib/hotdog/formatters/plain.rb +3 -44
- data/lib/hotdog/formatters/text.rb +46 -3
- data/lib/hotdog/version.rb +1 -1
- data/spec/formatter/plain_spec.rb +6 -0
- data/spec/formatter/text_spec.rb +6 -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: f79366fbd1f7a1759cf63ebd5b503338a5a0c2d1
|
4
|
+
data.tar.gz: d4fea09cef3558cf3543020c530c0950dd5bc5eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5fa35cc842fdae8a5221fe883797d3c4336e7adde177ac21340d6bfebeccd470110ecf350e6de6c3c65baabe370b3cc8f67ce53079de37bfc666d3008be544e
|
7
|
+
data.tar.gz: bdeae0ef080e8750363939b9018e7be0d3441ac8481763014581645c76aff140e8182169ba3790b45f3ef5da2d67fe06561265c3e54728942f379456a96d8dc5
|
data/lib/hotdog/application.rb
CHANGED
@@ -28,7 +28,7 @@ module Hotdog
|
|
28
28
|
expiry: 3600,
|
29
29
|
fixed_string: false,
|
30
30
|
force: false,
|
31
|
-
format: "
|
31
|
+
format: "text",
|
32
32
|
headers: false,
|
33
33
|
listing: false,
|
34
34
|
logger: @logger,
|
@@ -36,6 +36,7 @@ module Hotdog
|
|
36
36
|
offline: false,
|
37
37
|
print0: false,
|
38
38
|
print1: true,
|
39
|
+
print2: false,
|
39
40
|
primary_tag: nil,
|
40
41
|
tags: [],
|
41
42
|
display_search_tags: false,
|
@@ -96,12 +97,7 @@ module Hotdog
|
|
96
97
|
rescue Errno::EPIPE => error
|
97
98
|
STDERR.puts(error)
|
98
99
|
rescue => error
|
99
|
-
|
100
|
-
if @options[:debug]
|
101
|
-
raise # to show error stacktrace
|
102
|
-
else
|
103
|
-
exit(1)
|
104
|
-
end
|
100
|
+
raise # to show error stacktrace
|
105
101
|
end
|
106
102
|
end
|
107
103
|
|
@@ -144,9 +140,18 @@ module Hotdog
|
|
144
140
|
end
|
145
141
|
@optparse.on("-0", "--null", "Use null character as separator") do |v|
|
146
142
|
options[:print0] = v
|
143
|
+
options[:print1] = !v
|
144
|
+
options[:print2] = !v
|
147
145
|
end
|
148
146
|
@optparse.on("-1", "Use newline as separator") do |v|
|
147
|
+
options[:print0] = !v
|
149
148
|
options[:print1] = v
|
149
|
+
options[:print2] = !v
|
150
|
+
end
|
151
|
+
@optparse.on("-2", "Use space as separator") do |v|
|
152
|
+
options[:print0] = !v
|
153
|
+
options[:print1] = !v
|
154
|
+
options[:print2] = v
|
150
155
|
end
|
151
156
|
@optparse.on("-d", "--[no-]debug", "Enable debug mode") do |v|
|
152
157
|
options[:debug] = v
|
@@ -138,13 +138,13 @@ module Hotdog
|
|
138
138
|
case @op
|
139
139
|
when :AND
|
140
140
|
left_values = @left.evaluate(environment, options).tap do |values|
|
141
|
-
environment.logger.debug("lhs
|
141
|
+
environment.logger.debug("lhs(#{values.length})")
|
142
142
|
end
|
143
143
|
if left_values.empty?
|
144
144
|
[]
|
145
145
|
else
|
146
146
|
right_values = @right.evaluate(environment, options).tap do |values|
|
147
|
-
environment.logger.debug("rhs
|
147
|
+
environment.logger.debug("rhs(#{values.length})")
|
148
148
|
end
|
149
149
|
if right_values.empty?
|
150
150
|
[]
|
@@ -159,16 +159,16 @@ module Hotdog
|
|
159
159
|
"WHERE ? <= id AND id < ? AND ( id IN (%s) AND id IN (%s) );"
|
160
160
|
environment.execute(q % [left_selected.map { "?" }.join(", "), right_selected.map { "?" }.join(", ")], [range.first, range.last] + left_selected + right_selected).map { |row| row.first }
|
161
161
|
}.tap do |values|
|
162
|
-
environment.logger.debug("lhs AND rhs
|
162
|
+
environment.logger.debug("lhs(#{left_values.length}) AND rhs(#{right_values.length}) => #{values.length}")
|
163
163
|
end
|
164
164
|
end
|
165
165
|
end
|
166
166
|
when :OR
|
167
167
|
left_values = @left.evaluate(environment, options).tap do |values|
|
168
|
-
environment.logger.debug("lhs
|
168
|
+
environment.logger.debug("lhs(#{values.length})")
|
169
169
|
end
|
170
170
|
right_values = @right.evaluate(environment, options).tap do |values|
|
171
|
-
environment.logger.debug("rhs
|
171
|
+
environment.logger.debug("rhs(#{values.length})")
|
172
172
|
end
|
173
173
|
if left_values.empty?
|
174
174
|
right_values
|
@@ -186,16 +186,16 @@ module Hotdog
|
|
186
186
|
"WHERE ? <= id AND id < ? AND ( id IN (%s) OR id IN (%s) );"
|
187
187
|
environment.execute(q % [left_selected.map { "?" }.join(", "), right_selected.map { "?" }.join(", ")], [range.first, range.last] + left_selected + right_selected).map { |row| row.first }
|
188
188
|
}.tap do |values|
|
189
|
-
environment.logger.debug("lhs OR rhs
|
189
|
+
environment.logger.debug("lhs(#{left_values.length}) OR rhs(#{right_values.length}) => #{values.length}")
|
190
190
|
end
|
191
191
|
end
|
192
192
|
end
|
193
193
|
when :XOR
|
194
194
|
left_values = @left.evaluate(environment, options).tap do |values|
|
195
|
-
environment.logger.debug("lhs
|
195
|
+
environment.logger.debug("lhs(#{values.length})")
|
196
196
|
end
|
197
197
|
right_values = @right.evaluate(environment, options).tap do |values|
|
198
|
-
environment.logger.debug("rhs
|
198
|
+
environment.logger.debug("rhs(#{values.length})")
|
199
199
|
end
|
200
200
|
if left_values.empty?
|
201
201
|
right_values
|
@@ -215,7 +215,7 @@ module Hotdog
|
|
215
215
|
rq = right_selected.map { "?" }.join(", ")
|
216
216
|
environment.execute(q % [lq, rq, lq, rq], [range.first, range.last] + left_selected + right_selected + left_selected + right_selected).map { |row| row.first }
|
217
217
|
}.tap do |values|
|
218
|
-
environment.logger.debug("lhs XOR rhs
|
218
|
+
environment.logger.debug("lhs(#{left_values.length}) XOR rhs(#{right_values.length}) => #{values.length}")
|
219
219
|
end
|
220
220
|
end
|
221
221
|
end
|
@@ -1,51 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require "hotdog/formatters/text"
|
4
|
+
|
3
5
|
module Hotdog
|
4
6
|
module Formatters
|
5
|
-
class Plain <
|
6
|
-
def format(result, options={})
|
7
|
-
if options[:print0]
|
8
|
-
sep = "\0"
|
9
|
-
elsif options[:print1]
|
10
|
-
sep = newline
|
11
|
-
else
|
12
|
-
sep = " "
|
13
|
-
end
|
14
|
-
result = prepare(result)
|
15
|
-
if options[:print1] and options[:headers] and options[:fields]
|
16
|
-
field_length = (0...result.last.length).map { |field_index|
|
17
|
-
result.reduce(0) { |length, row|
|
18
|
-
[length, row[field_index].to_s.length, options[:fields][field_index].to_s.length].max
|
19
|
-
}
|
20
|
-
}
|
21
|
-
header_fields = options[:fields].zip(field_length).map { |field, length|
|
22
|
-
field.to_s + (" " * (length - field.length))
|
23
|
-
}
|
24
|
-
result = [
|
25
|
-
header_fields,
|
26
|
-
header_fields.map { |field|
|
27
|
-
"-" * field.length
|
28
|
-
},
|
29
|
-
] + result.map { |row|
|
30
|
-
row.zip(field_length).map { |field, length|
|
31
|
-
padding = length - ((field.nil?) ? 0 : field.to_s.length)
|
32
|
-
field.to_s + (" " * padding)
|
33
|
-
}
|
34
|
-
}
|
35
|
-
end
|
36
|
-
s = _format(result, sep, options)
|
37
|
-
if s.empty? or options[:print0]
|
38
|
-
s
|
39
|
-
else
|
40
|
-
s + newline
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def _format(result, sep, options={})
|
45
|
-
result.map { |row|
|
46
|
-
row.join(" ")
|
47
|
-
}.join(sep)
|
48
|
-
end
|
7
|
+
class Plain < Text
|
49
8
|
end
|
50
9
|
end
|
51
10
|
end
|
@@ -1,10 +1,53 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require "hotdog/formatters/plain"
|
4
|
-
|
5
3
|
module Hotdog
|
6
4
|
module Formatters
|
7
|
-
class Text <
|
5
|
+
class Text < BaseFormatter
|
6
|
+
def format(result, options={})
|
7
|
+
if options[:print0]
|
8
|
+
sep = "\0"
|
9
|
+
elsif options[:print1]
|
10
|
+
sep = newline
|
11
|
+
elsif options[:print2]
|
12
|
+
sep = " "
|
13
|
+
else
|
14
|
+
sep = " "
|
15
|
+
end
|
16
|
+
result = prepare(result)
|
17
|
+
if options[:print1] and options[:headers] and options[:fields]
|
18
|
+
field_length = (0...result.last.length).map { |field_index|
|
19
|
+
result.reduce(0) { |length, row|
|
20
|
+
[length, row[field_index].to_s.length, options[:fields][field_index].to_s.length].max
|
21
|
+
}
|
22
|
+
}
|
23
|
+
header_fields = options[:fields].zip(field_length).map { |field, length|
|
24
|
+
field.to_s + (" " * (length - field.length))
|
25
|
+
}
|
26
|
+
result = [
|
27
|
+
header_fields,
|
28
|
+
header_fields.map { |field|
|
29
|
+
"-" * field.length
|
30
|
+
},
|
31
|
+
] + result.map { |row|
|
32
|
+
row.zip(field_length).map { |field, length|
|
33
|
+
padding = length - ((field.nil?) ? 0 : field.to_s.length)
|
34
|
+
field.to_s + (" " * padding)
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
s = _format(result, sep, options)
|
39
|
+
if s.empty? or options[:print0]
|
40
|
+
s
|
41
|
+
else
|
42
|
+
s + newline
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def _format(result, sep, options={})
|
47
|
+
result.map { |row|
|
48
|
+
row.join(" ")
|
49
|
+
}.join(sep)
|
50
|
+
end
|
8
51
|
end
|
9
52
|
end
|
10
53
|
end
|
data/lib/hotdog/version.rb
CHANGED
@@ -12,6 +12,7 @@ describe "plain" do
|
|
12
12
|
headers: false,
|
13
13
|
print0: true,
|
14
14
|
print1: false,
|
15
|
+
print2: false,
|
15
16
|
}
|
16
17
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1\0bar bbb 2\0baz ccc 3")
|
17
18
|
end
|
@@ -22,6 +23,7 @@ describe "plain" do
|
|
22
23
|
fields: ["key1", "key2", "val1"],
|
23
24
|
print0: true,
|
24
25
|
print1: false,
|
26
|
+
print2: false,
|
25
27
|
}
|
26
28
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1\0bar bbb 2\0baz ccc 3")
|
27
29
|
end
|
@@ -31,6 +33,7 @@ describe "plain" do
|
|
31
33
|
headers: false,
|
32
34
|
print0: false,
|
33
35
|
print1: true,
|
36
|
+
print2: false,
|
34
37
|
}
|
35
38
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
36
39
|
foo aaa 1
|
@@ -45,6 +48,7 @@ baz ccc 3
|
|
45
48
|
fields: ["key1", "key2", "val1"],
|
46
49
|
print0: false,
|
47
50
|
print1: true,
|
51
|
+
print2: false,
|
48
52
|
}
|
49
53
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
50
54
|
key1 key2 val1
|
@@ -60,6 +64,7 @@ baz ccc 3
|
|
60
64
|
headers: false,
|
61
65
|
print0: false,
|
62
66
|
print1: false,
|
67
|
+
print2: true,
|
63
68
|
}
|
64
69
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1 bar bbb 2 baz ccc 3\n")
|
65
70
|
end
|
@@ -70,6 +75,7 @@ baz ccc 3
|
|
70
75
|
fields: ["key1", "key2", "val1"],
|
71
76
|
print0: false,
|
72
77
|
print1: false,
|
78
|
+
print2: true,
|
73
79
|
}
|
74
80
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1 bar bbb 2 baz ccc 3\n")
|
75
81
|
end
|
data/spec/formatter/text_spec.rb
CHANGED
@@ -12,6 +12,7 @@ describe "text" do
|
|
12
12
|
headers: false,
|
13
13
|
print0: true,
|
14
14
|
print1: false,
|
15
|
+
print2: false,
|
15
16
|
}
|
16
17
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1\0bar bbb 2\0baz ccc 3")
|
17
18
|
end
|
@@ -22,6 +23,7 @@ describe "text" do
|
|
22
23
|
fields: ["key1", "key2", "val1"],
|
23
24
|
print0: true,
|
24
25
|
print1: false,
|
26
|
+
print2: false,
|
25
27
|
}
|
26
28
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1\0bar bbb 2\0baz ccc 3")
|
27
29
|
end
|
@@ -31,6 +33,7 @@ describe "text" do
|
|
31
33
|
headers: false,
|
32
34
|
print0: false,
|
33
35
|
print1: true,
|
36
|
+
print2: false,
|
34
37
|
}
|
35
38
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
36
39
|
foo aaa 1
|
@@ -45,6 +48,7 @@ baz ccc 3
|
|
45
48
|
fields: ["key1", "key2", "val1"],
|
46
49
|
print0: false,
|
47
50
|
print1: true,
|
51
|
+
print2: false,
|
48
52
|
}
|
49
53
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq(<<-EOS)
|
50
54
|
key1 key2 val1
|
@@ -60,6 +64,7 @@ baz ccc 3
|
|
60
64
|
headers: false,
|
61
65
|
print0: false,
|
62
66
|
print1: false,
|
67
|
+
print2: true,
|
63
68
|
}
|
64
69
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1 bar bbb 2 baz ccc 3\n")
|
65
70
|
end
|
@@ -70,6 +75,7 @@ baz ccc 3
|
|
70
75
|
fields: ["key1", "key2", "val1"],
|
71
76
|
print0: false,
|
72
77
|
print1: false,
|
78
|
+
print2: true,
|
73
79
|
}
|
74
80
|
expect(fmt.format([["foo", "aaa", 1], ["bar", "bbb", 2], ["baz", "ccc", 3]], options)).to eq("foo aaa 1 bar bbb 2 baz ccc 3\n")
|
75
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotdog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yamashita Yuu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|