hotdog 0.1.10 → 0.1.11

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: 004bbaba7b65fb0cc3fba2c01eb465ce997a61a2
4
- data.tar.gz: 09dac6927faae3cc9c74b90ee8a078fec52f79cc
3
+ metadata.gz: 386ea5a2e53080113a7136e39a71a08465e087fa
4
+ data.tar.gz: c69190562efa14c594d20976025d1abd408b47b6
5
5
  SHA512:
6
- metadata.gz: b1bc205cff0d6b97ea4acc5e488ca15df3814cc005366f19ff8fff3ed03b23ad369a077cbed09f02f9f2361d421493163af12622d78d94b180999d3d95c95fcf
7
- data.tar.gz: 1a22434d7e7c906c826327f705935ff354b950c1c46f4f8515e12d16267adf004668c1df6ac549db57bfbc20543b68ed41e3c48279d08fb859433ee158084a02
6
+ metadata.gz: df1751d43d7c69edd34a6a1decb2a4b247a7993c0f0bc0a9277066d90a95364ca5582a3e5c2a30eb103e9fdfccf6d79a63029bbcb796862e766fb31897d74c33
7
+ data.tar.gz: 84178da6939e1066e18062e235caaa0c055e9bd5d28280aa5f60a4d648d8272ac1ae66ceaf1219e8930ea0d70dc78f4ca543d330a960db53d109dd2d8945a55d
@@ -28,6 +28,7 @@ module Hotdog
28
28
  max_time: 5,
29
29
  print0: false,
30
30
  print1: true,
31
+ primary_tag: nil,
31
32
  tags: [],
32
33
  display_search_tags: false,
33
34
  verbose: false,
@@ -108,6 +109,9 @@ module Hotdog
108
109
  @optparse.on("-a TAG", "-t TAG", "--tag TAG", "Use specified tag name/value") do |tag|
109
110
  options[:tags] += [tag]
110
111
  end
112
+ @optparse.on("--primary-tag TAG", "Use specified tag as the primary tag") do |tag|
113
+ options[:primary_tag] = tag
114
+ end
111
115
  @optparse.on("-x", "--display-search-tags", "Show tags used in search expression") do |v|
112
116
  options[:display_search_tags] = v
113
117
  end
@@ -41,8 +41,8 @@ module Hotdog
41
41
  end
42
42
  }
43
43
  identifiers = drilldown.call(node).map(&:to_s)
44
-
45
- get_hosts(result, @options[:display_search_tags] ? identifiers : [])
44
+ tags = @options[:display_search_tags] ? identifiers : nil
45
+ get_hosts(result, tags)
46
46
  end
47
47
 
48
48
  def parse(expression)
@@ -56,14 +56,10 @@ module Hotdog
56
56
  not host_id.nil?
57
57
  end
58
58
 
59
- def get_hosts(hosts=[], identifiers=[])
59
+ def get_hosts(hosts, tags=nil)
60
+ tags ||= @options[:tags]
60
61
  update_db
61
- if 0 < @options[:tags].length || 0 < identifiers.length
62
- tags = if 0 < @options[:tags].length
63
- @options[:tags] + identifiers
64
- else
65
- ["host"] + identifiers
66
- end
62
+ if 0 < tags.length
67
63
  result = hosts.map { |host_id|
68
64
  tags.map { |tag|
69
65
  tag_name, tag_value = tag.split(":", 2)
@@ -82,6 +78,7 @@ module Hotdog
82
78
  fields = tags
83
79
  else
84
80
  if @options[:listing]
81
+ # TODO: should respect `:primary_tag`
85
82
  fields = []
86
83
  hosts = execute("SELECT id, name FROM hosts WHERE id IN (%s)" % hosts.map { "?" }.join(", "), hosts)
87
84
  result = hosts.map { |host_id, host_name|
@@ -95,8 +92,21 @@ module Hotdog
95
92
  }
96
93
  fields = ["host"] + fields
97
94
  else
98
- fields = ["host"]
99
- result = execute("SELECT name FROM hosts WHERE id IN (%s)" % hosts.map { "?" }.join(", "), hosts)
95
+ if @options[:primary_tag]
96
+ fields = [@options[:primary_tag]]
97
+ tag_name, tag_value = @options[:primary_tag].split(":", 2)
98
+ case tag_name
99
+ when "host"
100
+ result = execute("SELECT name FROM hosts WHERE id IN (%s)" % hosts.map { "?" }.join(", "), hosts)
101
+ else
102
+ result = hosts.map { |host_id|
103
+ [select_tag_values_from_hosts_tags_by_host_id_and_tag_name_glob(@db, host_id, tag_name)]
104
+ }
105
+ end
106
+ else
107
+ fields = ["host"]
108
+ result = execute("SELECT name FROM hosts WHERE id IN (%s)" % hosts.map { "?" }.join(", "), hosts)
109
+ end
100
110
  end
101
111
  end
102
112
  [result, fields]
@@ -305,7 +315,7 @@ module Hotdog
305
315
  end
306
316
 
307
317
  def select_tag_values_from_hosts_tags_by_host_id_and_tag_name_glob(db, host_id, tag_name)
308
- logger.debug("select_tag_values_from_hosts_tags_by_host_id_and_tag_name_glob(%s, %s)", host_id.inspect, tag_name.inspect)
318
+ logger.debug("select_tag_values_from_hosts_tags_by_host_id_and_tag_name_glob(%s, %s)" % [host_id.inspect, tag_name.inspect])
309
319
  db.execute(<<-EOS, host_id, tag_name).map { |row| row.first }.join(",")
310
320
  SELECT tags.value FROM hosts_tags
311
321
  INNER JOIN tags ON hosts_tags.tag_id = tags.id
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
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.1.10
4
+ version: 0.1.11
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-04-21 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler