hotdog 0.6.0 → 0.6.1

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
  SHA1:
3
- metadata.gz: f3bcc93be20391d227013b6c05bb9113d68bc404
4
- data.tar.gz: 3a8bc479c3122dc4b18ecf37d575e7b49dd8c1f8
3
+ metadata.gz: 1b087123acdf59f344d374145bdf0915f57757f6
4
+ data.tar.gz: 0f22b57543b9b6d83e904d9f643eac3ccc3a6a52
5
5
  SHA512:
6
- metadata.gz: 8c9646d739e72b331cdfdf145da4e93b0c44598b64618a20db48eff13185a9bc277550581f2288e20ee548c8001466c454d30d43df900d9cef8e773bcf5f4bef
7
- data.tar.gz: d51c0697ca67251ded20b0c2807af26ead5d4f7ed87b3c189ee109ff464c2a5cfccc82efeff20ec8f6cdcd0a2a07ab4ee5c1f374d1df4c14cdf9d5b98994fe03
6
+ metadata.gz: 51f9b047b0bc2cf02ae5abb013d02e1c0c52e5e7530ec7b27e313663a5e2022214d578a7bb58531e1f8c6e7833de1f2b4205e8c78bd319659c4499b67eb5edf1
7
+ data.tar.gz: f6017f78210111e9bc19492b0a2b0724c15cfebe568e68d2902d71f5b2861428a3665caff8c25794d1ce07cbe057eb2ca05338a02a598b32b39611fd03514d9d
@@ -80,6 +80,17 @@ module Hotdog
80
80
 
81
81
  cmd.run(args, @options)
82
82
  end
83
+ rescue OptionParser::ParseError => error
84
+ STDERR.puts("hotdog: #{error.message}")
85
+ require "hotdog/commands/help"
86
+ get_command(command).tap do |cmd|
87
+ if Hotdog::Commands::Help === cmd
88
+ STDERR.puts("hotdog: '#{command}' is not a hotdog command.")
89
+ else
90
+ cmd.parse_options(@optparse, ["--help"])
91
+ end
92
+ end
93
+ exit(1)
83
94
  rescue Errno::EPIPE
84
95
  # nop
85
96
  end
@@ -78,21 +78,21 @@ module Hotdog
78
78
  end
79
79
  end
80
80
 
81
+ private
81
82
  def exec_command(result0, options={})
82
83
  result, fields = get_hosts(result0)
83
84
  hosts = result.flatten
84
85
  threads = options[:max_parallelism] || hosts.size
86
+ use_color_p = use_color?
85
87
  stats = Parallel.map(hosts.zip(hosts), in_threads: threads) { |host, name|
86
- if use_color?
87
- header = "\e[0;36m#{name}\e[00m"
88
- else
89
- header = name
90
- end
91
88
  cmdline = build_command_string(host, options)
92
89
  logger.debug("execute: #{cmdline}")
93
90
  IO.popen(cmdline, in: :close, err: [:child, :out]) do |io|
94
- io.each_line do |line|
95
- STDOUT.write("#{header}: #{line}")
91
+ io.each_with_index do |s, i|
92
+ STDOUT.write("\e[0;36m") if use_color_p
93
+ STDOUT.write("#{name}:#{i}:")
94
+ STDOUT.write("\e[0m") if use_color_p
95
+ STDOUT.write(s)
96
96
  end
97
97
  end
98
98
  $?.success? # $? is thread-local variable
@@ -128,7 +128,6 @@ module Hotdog
128
128
  Shellwords.join(cmdline)
129
129
  end
130
130
 
131
- private
132
131
  def use_color?
133
132
  case options[:color]
134
133
  when :always
@@ -213,10 +213,18 @@ module Hotdog
213
213
  end
214
214
  }
215
215
  rule(identifier_regexp: simple(:identifier_regexp), separator: simple(:separator)) {
216
- RegexpTagNameNode.new(identifier_regexp.to_s, separator)
216
+ if "host" == identifier_regexp
217
+ AnyHostNode.new(separator)
218
+ else
219
+ RegexpTagNameNode.new(identifier_regexp.to_s, separator)
220
+ end
217
221
  }
218
222
  rule(identifier_regexp: simple(:identifier_regexp)) {
219
- RegexpNode.new(identifier_regexp.to_s)
223
+ if "host" == identifier_regexp
224
+ AnyHostNode.new(separator)
225
+ else
226
+ RegexpNode.new(identifier_regexp.to_s)
227
+ end
220
228
  }
221
229
  rule(identifier_glob: simple(:identifier_glob), separator: simple(:separator), attribute_glob: simple(:attribute_glob)) {
222
230
  if "host" == identifier_glob
@@ -233,10 +241,18 @@ module Hotdog
233
241
  end
234
242
  }
235
243
  rule(identifier_glob: simple(:identifier_glob), separator: simple(:separator)) {
236
- GlobTagNameNode.new(identifier_glob.to_s, separator)
244
+ if "host" == identifier_glob
245
+ AnyHostNode.new(separator)
246
+ else
247
+ GlobTagNameNode.new(identifier_glob.to_s, separator)
248
+ end
237
249
  }
238
250
  rule(identifier_glob: simple(:identifier_glob)) {
239
- GlobNode.new(identifier_glob.to_s)
251
+ if "host" == identifier_glob
252
+ AnyHostNode.new(separator)
253
+ else
254
+ GlobNode.new(identifier_glob.to_s)
255
+ end
240
256
  }
241
257
  rule(identifier: simple(:identifier), separator: simple(:separator), attribute_glob: simple(:attribute_glob)) {
242
258
  if "host" == identifier
@@ -253,10 +269,18 @@ module Hotdog
253
269
  end
254
270
  }
255
271
  rule(identifier: simple(:identifier), separator: simple(:separator)) {
256
- StringTagNameNode.new(identifier.to_s, separator)
272
+ if "host" == identifier
273
+ AnyHostNode.new(separator)
274
+ else
275
+ StringTagNameNode.new(identifier.to_s, separator)
276
+ end
257
277
  }
258
278
  rule(identifier: simple(:identifier)) {
259
- StringNode.new(identifier.to_s)
279
+ if "host" == identifier
280
+ AnyHostNode.new(separator)
281
+ else
282
+ StringNode.new(identifier.to_s)
283
+ end
260
284
  }
261
285
  rule(separator: simple(:separator), attribute_regexp: simple(:attribute_regexp)) {
262
286
  RegexpTagValueNode.new(attribute_regexp.to_s, separator)
@@ -622,7 +646,7 @@ module Hotdog
622
646
  if expressions.all? { |expression| TagExpressionNode === expression }
623
647
  values = expressions.group_by { |expression| expression.class }.values.flat_map { |expressions|
624
648
  if query_without_condition = expressions.first.maybe_query_without_condition(options)
625
- condition_length = expressions.first.condition_values(options).length
649
+ condition_length = expressions.map { |expression| expression.condition_values(options).length }.max
626
650
  expressions.each_slice(SQLITE_LIMIT_COMPOUND_SELECT / condition_length).flat_map { |expressions|
627
651
  q = query_without_condition.sub(/\s*;\s*\z/, "") + " WHERE " + expressions.map { |expression| "( %s )" % expression.condition(options) }.join(" OR ") + ";"
628
652
  environment.execute(q, expressions.flat_map { |expression| expression.condition_values(options) }).map { |row| row.first }
@@ -836,6 +860,42 @@ module Hotdog
836
860
  end
837
861
  end
838
862
 
863
+ class AnyHostNode < TagExpressionNode
864
+ def initialize(separator=nil)
865
+ super("host", nil, separator)
866
+ end
867
+
868
+ def condition(options={})
869
+ "1"
870
+ end
871
+
872
+ def condition_tables(options={})
873
+ [:hosts]
874
+ end
875
+
876
+ def condition_values(options={})
877
+ []
878
+ end
879
+ end
880
+
881
+ class AnyTagNode < TagExpressionNode
882
+ def initialize(separator=nil)
883
+ super(nil, nil, separator)
884
+ end
885
+
886
+ def condition(options={})
887
+ "1"
888
+ end
889
+
890
+ def condition_tables(options={})
891
+ [:tags]
892
+ end
893
+
894
+ def condition_values(options={})
895
+ []
896
+ end
897
+ end
898
+
839
899
  class StringExpressionNode < TagExpressionNode
840
900
  end
841
901
 
@@ -857,7 +917,7 @@ module Hotdog
857
917
  end
858
918
 
859
919
  def maybe_fallback(options={})
860
- fallback = GlobHostNode.new(maybe_glob(attribute), separator)
920
+ fallback = GlobHostNode.new(to_glob(attribute), separator)
861
921
  if query = fallback.maybe_query(options)
862
922
  QueryExpressionNode.new(query, fallback.condition_values(options))
863
923
  else
@@ -884,7 +944,7 @@ module Hotdog
884
944
  end
885
945
 
886
946
  def maybe_fallback(options={})
887
- fallback = GlobTagNode.new(maybe_glob(identifier), maybe_glob(attribute), separator)
947
+ fallback = GlobTagNode.new(to_glob(identifier), to_glob(attribute), separator)
888
948
  if query = fallback.maybe_query(options)
889
949
  QueryExpressionNode.new(query, fallback.condition_values(options))
890
950
  else
@@ -911,7 +971,7 @@ module Hotdog
911
971
  end
912
972
 
913
973
  def maybe_fallback(options={})
914
- fallback = GlobTagNameNode.new(maybe_glob(identifier), separator)
974
+ fallback = GlobTagNameNode.new(to_glob(identifier), separator)
915
975
  if query = fallback.maybe_query(options)
916
976
  QueryExpressionNode.new(query, fallback.condition_values(options))
917
977
  else
@@ -926,19 +986,19 @@ module Hotdog
926
986
  end
927
987
 
928
988
  def condition(options={})
929
- "tags.value = ?"
989
+ "hosts.name = ? OR tags.value = ?"
930
990
  end
931
991
 
932
992
  def condition_tables(options={})
933
- [:tags]
993
+ [:hosts, :tags]
934
994
  end
935
995
 
936
996
  def condition_values(options={})
937
- [attribute]
997
+ [attribute, attribute]
938
998
  end
939
999
 
940
1000
  def maybe_fallback(options={})
941
- fallback = GlobTagValueNode.new(maybe_glob(attribute), separator)
1001
+ fallback = GlobTagValueNode.new(to_glob(attribute), separator)
942
1002
  if query = fallback.maybe_query(options)
943
1003
  QueryExpressionNode.new(query, fallback.condition_values(options))
944
1004
  else
@@ -965,7 +1025,7 @@ module Hotdog
965
1025
  end
966
1026
 
967
1027
  def maybe_fallback(options={})
968
- fallback = GlobNode.new(maybe_glob(identifier), separator)
1028
+ fallback = GlobNode.new(to_glob(identifier), separator)
969
1029
  if query = fallback.maybe_query(options)
970
1030
  QueryExpressionNode.new(query, fallback.condition_values(options))
971
1031
  else
@@ -1003,7 +1063,7 @@ module Hotdog
1003
1063
  end
1004
1064
 
1005
1065
  def maybe_fallback(options={})
1006
- fallback = GlobHostNode.new(maybe_glob(attribute), separator)
1066
+ fallback = GlobHostNode.new(to_glob(attribute), separator)
1007
1067
  if query = fallback.maybe_query(options)
1008
1068
  QueryExpressionNode.new(query, fallback.condition_values(options))
1009
1069
  else
@@ -1030,7 +1090,7 @@ module Hotdog
1030
1090
  end
1031
1091
 
1032
1092
  def maybe_fallback(options={})
1033
- fallback = GlobTagNode.new(maybe_glob(identifier), maybe_glob(attribute), separator)
1093
+ fallback = GlobTagNode.new(to_glob(identifier), to_glob(attribute), separator)
1034
1094
  if query = fallback.maybe_query(options)
1035
1095
  QueryExpressionNode.new(query, fallback.condition_values(options))
1036
1096
  else
@@ -1057,7 +1117,7 @@ module Hotdog
1057
1117
  end
1058
1118
 
1059
1119
  def maybe_fallback(options={})
1060
- fallback = GlobTagNameNode.new(maybe_glob(identifier), separator)
1120
+ fallback = GlobTagNameNode.new(to_glob(identifier), separator)
1061
1121
  if query = fallback.maybe_query(options)
1062
1122
  QueryExpressionNode.new(query, fallback.condition_values(options))
1063
1123
  else
@@ -1072,19 +1132,19 @@ module Hotdog
1072
1132
  end
1073
1133
 
1074
1134
  def condition(options={})
1075
- "LOWER(tags.value) GLOB LOWER(?)"
1135
+ "LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?)"
1076
1136
  end
1077
1137
 
1078
1138
  def condition_tables(options={})
1079
- [:tags]
1139
+ [:hosts, :tags]
1080
1140
  end
1081
1141
 
1082
1142
  def condition_values(options={})
1083
- [attribute]
1143
+ [attribute, attribute]
1084
1144
  end
1085
1145
 
1086
1146
  def maybe_fallback(options={})
1087
- fallback = GlobTagValueNode.new(maybe_glob(attribute), separator)
1147
+ fallback = GlobTagValueNode.new(to_glob(attribute), separator)
1088
1148
  if query = fallback.maybe_query(options)
1089
1149
  QueryExpressionNode.new(query, fallback.condition_values(options))
1090
1150
  else
@@ -1111,7 +1171,7 @@ module Hotdog
1111
1171
  end
1112
1172
 
1113
1173
  def maybe_fallback(options={})
1114
- fallback = GlobNode.new(maybe_glob(identifier), separator)
1174
+ fallback = GlobNode.new(to_glob(identifier), separator)
1115
1175
  if query = fallback.maybe_query(options)
1116
1176
  QueryExpressionNode.new(query, fallback.condition_values(options))
1117
1177
  else
@@ -1191,15 +1251,15 @@ module Hotdog
1191
1251
  end
1192
1252
 
1193
1253
  def condition(options={})
1194
- "tags.value REGEXP ?"
1254
+ "hosts.name REGEXP ? OR tags.value REGEXP ?"
1195
1255
  end
1196
1256
 
1197
1257
  def condition_tables(options={})
1198
- [:tags]
1258
+ [:hosts, :tags]
1199
1259
  end
1200
1260
 
1201
1261
  def condition_values(options={})
1202
- [attribute]
1262
+ [attribute, attribute]
1203
1263
  end
1204
1264
  end
1205
1265
 
@@ -90,6 +90,7 @@ module Hotdog
90
90
  exit(127)
91
91
  end
92
92
 
93
+ private
93
94
  def exec_command(result0, options={})
94
95
  result, fields = get_hosts(result0)
95
96
  hosts = result.flatten
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  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.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-06 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler