hotdog 0.5.3 → 0.5.4

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: 994ffc110fca456fa2aafe2c680b5336fb469989
4
- data.tar.gz: 2a68fa27a1dab929c0b9ff5e63d031bd7747dbef
3
+ metadata.gz: dad54741d7b612af34df19f0ae934c938411a941
4
+ data.tar.gz: 951a0d2bafcf5edbc3262e9f1552b4aade13fc0c
5
5
  SHA512:
6
- metadata.gz: 5afa560d648757a26676dadce8fb39aac67e43ae92aa707467b1bb681e1465b1303a7937a86ba8e9f64e1a5b07a6570715704aab9dfd8db02f25b064c47093ad
7
- data.tar.gz: 1f747ae6f4e3cd107484c09372051e2dcc60e837c9c5faa00479acef6895a4cca791730d0349e4341f915469753e217f8dffa5a213ad229a8e3db99da72dda2e
6
+ metadata.gz: 9c4fdc6b65e2caa37150c2e47bf207cacfec32d775e7f23b9e7b79298935853b5c34dc094d75ee21b48187d9440b3d4d9ae787a212387a5ae3415e1e5caac7df
7
+ data.tar.gz: 8e71095cbea2abee8f03173cfda463b289326a4a2a0fa187bd45040856e32e287f8ab84c270bacaa785f15ec6dddb052e126941438c6a353ed9d5e417b74140c
@@ -54,7 +54,8 @@ module Hotdog
54
54
  begin
55
55
  command = ( args.shift || "help" )
56
56
  get_command(command).new(self).tap do |cmd|
57
- cmd.define_options(@optparse)
57
+ @optparse.banner = "Usage: hotdog #{command} [options]"
58
+ cmd.define_options(@optparse, @options)
58
59
  args = cmd.parse_options(@optparse, args)
59
60
  unless options[:api_key]
60
61
  raise("DATADOG_API_KEY is not set")
@@ -76,7 +77,7 @@ module Hotdog
76
77
  options[:logger].level = Logger::INFO
77
78
  end
78
79
 
79
- cmd.run(args)
80
+ cmd.run(args, @options)
80
81
  end
81
82
  rescue Errno::EPIPE
82
83
  # nop
@@ -5,7 +5,7 @@ require "fileutils"
5
5
  module Hotdog
6
6
  module Commands
7
7
  class Down < BaseCommand
8
- def define_options(optparse)
8
+ def define_options(optparse, options={})
9
9
  @downtime = 86400
10
10
  @start = Time.new
11
11
  optparse.on("--downtime DURATION") do |v|
@@ -16,7 +16,7 @@ module Hotdog
16
16
  end
17
17
  end
18
18
 
19
- def run(args=[])
19
+ def run(args=[], options={})
20
20
  args.each do |arg|
21
21
  if arg.index(":").nil?
22
22
  scope = "host:#{arg}"
@@ -5,7 +5,7 @@ require "rbconfig"
5
5
  module Hotdog
6
6
  module Commands
7
7
  class Help < BaseCommand
8
- def run(args=[])
8
+ def run(args=[], options={})
9
9
  ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
10
10
  exit(system(ruby, $0, "--help") ? 0 : 1)
11
11
  end
@@ -3,7 +3,7 @@
3
3
  module Hotdog
4
4
  module Commands
5
5
  class Hosts < BaseCommand
6
- def run(args=[])
6
+ def run(args=[], options={})
7
7
  if args.empty?
8
8
  result = execute("SELECT id FROM hosts").to_a.reduce(:+)
9
9
  show_hosts(result)
@@ -9,37 +9,31 @@ require "parallel"
9
9
  module Hotdog
10
10
  module Commands
11
11
  class Pssh < Search
12
- def define_options(optparse)
13
- @ssh_options = @options.merge({
14
- options: [],
15
- user: nil,
16
- port: nil,
17
- identity_file: nil,
18
- max_parallelism: nil,
19
- })
12
+ def define_options(optparse, options={})
13
+ options[:options] = []
14
+ options[:user] = nil
15
+ options[:port] = nil
16
+ options[:identity_file] = nil
17
+ options[:max_parallelism] = nil
20
18
 
21
19
  optparse.on("-o SSH_OPTION", "Passes this string to ssh command through shell. This option may be given multiple times") do |option|
22
- @ssh_options[:options] += [option]
20
+ options[:options] += [option]
23
21
  end
24
22
  optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path|
25
- @ssh_options[:identity_file] = path
23
+ options[:identity_file] = path
26
24
  end
27
25
  optparse.on("-p PORT", "Port of the remote host", Integer) do |port|
28
- @ssh_options[:port] = port
26
+ options[:port] = port
29
27
  end
30
28
  optparse.on("-u SSH_USER", "SSH login user name") do |user|
31
- @ssh_options[:user] = user
29
+ options[:user] = user
32
30
  end
33
31
  optparse.on("-P PARALLELISM", "Max parallelism", Integer) do |n|
34
- @ssh_options[:max_parallelism] = n
32
+ options[:max_parallelism] = n
35
33
  end
36
34
  end
37
35
 
38
- def parse_options(optparse, args=[])
39
- optparse.order(args)
40
- end
41
-
42
- def run(args=[])
36
+ def run(args=[], options={})
43
37
  use_color = STDOUT.tty?
44
38
  expression = args.join(" ").strip
45
39
  if expression.empty? || args.empty?
@@ -65,24 +59,24 @@ module Hotdog
65
59
 
66
60
  # build ssh command
67
61
  cmdline = ["ssh"]
68
- @ssh_options[:options].each do |option|
62
+ options[:options].each do |option|
69
63
  cmdline << "-o" << option
70
64
  end
71
- if path = @ssh_options[:identity_file]
65
+ if path = options[:identity_file]
72
66
  cmdline << "-i" << Shellwords.escape(path)
73
67
  end
74
- if port = @ssh_options[:port]
68
+ if port = options[:port]
75
69
  cmdline << "-p" << port.to_s
76
70
  end
77
- if @ssh_options[:forward_agent]
71
+ if options[:forward_agent]
78
72
  cmdline << "-A"
79
73
  end
80
74
 
81
75
  cmdline << "-o" << "BatchMode=yes"
82
76
 
83
- user = @ssh_options[:user]
77
+ user = options[:user]
84
78
 
85
- threads = @ssh_options[:max_parallelism] || addresses.size
79
+ threads = options[:max_parallelism] || addresses.size
86
80
  stats = Parallel.map(addresses, in_threads: threads) { |address,name|
87
81
  if use_color
88
82
  header = "\e[0;36m#{name}\e[00m"
@@ -6,15 +6,13 @@ require "parslet"
6
6
  module Hotdog
7
7
  module Commands
8
8
  class Search < BaseCommand
9
- def define_options(optparse)
10
- @search_options = @options.merge({
11
- })
9
+ def define_options(optparse, options={})
12
10
  optparse.on("-n", "--limit LIMIT", "Limit result set to specified size at most", Integer) do |limit|
13
- @search_options[:limit] = limit
11
+ options[:limit] = limit
14
12
  end
15
13
  end
16
14
 
17
- def run(args=[])
15
+ def run(args=[], options={})
18
16
  expression = args.join(" ").strip
19
17
  if expression.empty?
20
18
  # return everything if given expression is empty
@@ -31,7 +29,7 @@ module Hotdog
31
29
  result = evaluate(node, self)
32
30
  if 0 < result.length
33
31
  _result, fields = get_hosts_with_search_tags(result, node)
34
- result = _result.take(@search_options.fetch(:limit, _result.size))
32
+ result = _result.take(options.fetch(:limit, _result.size))
35
33
  STDOUT.print(format(result, fields: fields))
36
34
  if _result.length == result.length
37
35
  logger.info("found %d host(s)." % result.length)
@@ -53,10 +51,10 @@ module Hotdog
53
51
  else []
54
52
  end
55
53
  }
56
- if @options[:display_search_tags]
54
+ if options[:display_search_tags]
57
55
  identifiers = drilldown.call(node).map(&:to_s)
58
- if @options[:primary_tag]
59
- tags = [@options[:primary_tag]] + identifiers
56
+ if options[:primary_tag]
57
+ tags = [options[:primary_tag]] + identifiers
60
58
  else
61
59
  tags = identifiers
62
60
  end
@@ -8,45 +8,39 @@ require "shellwords"
8
8
  module Hotdog
9
9
  module Commands
10
10
  class Ssh < Search
11
- def define_options(optparse)
12
- @ssh_options = @options.merge({
13
- index: nil,
14
- options: [],
15
- user: nil,
16
- port: nil,
17
- identity_file: nil,
18
- forward_agent: false,
19
- verbose: false,
20
- })
11
+ def define_options(optparse, options={})
12
+ options[:index] = nil
13
+ options[:options] = []
14
+ options[:user] = nil
15
+ options[:port] = nil
16
+ options[:identity_file] = nil
17
+ options[:forward_agent] = false
18
+ options[:verbose] = false
21
19
 
22
20
  optparse.on("-n", "--index INDEX", "Use this index of host if multiple servers are found", Integer) do |index|
23
- @ssh_options[:index] = index
21
+ options[:index] = index
24
22
  end
25
23
  optparse.on("-o SSH_OPTION", "Passes this string to ssh command through shell. This option may be given multiple times") do |option|
26
- @ssh_options[:options] += [option]
24
+ options[:options] += [option]
27
25
  end
28
26
  optparse.on("-i SSH_IDENTITY_FILE", "SSH identity file path") do |path|
29
- @ssh_options[:identity_file] = path
27
+ options[:identity_file] = path
30
28
  end
31
29
  optparse.on("-A", "Enable agent forwarding", TrueClass) do |b|
32
- @ssh_options[:forward_agent] = b
30
+ options[:forward_agent] = b
33
31
  end
34
32
  optparse.on("-p PORT", "Port of the remote host", Integer) do |port|
35
- @ssh_options[:port] = port
33
+ options[:port] = port
36
34
  end
37
35
  optparse.on("-u SSH_USER", "SSH login user name") do |user|
38
- @ssh_options[:user] = user
36
+ options[:user] = user
39
37
  end
40
38
  optparse.on("-v", "--verbose", "Enable verbose ode") do |v|
41
- @ssh_options[:verbose] = v
39
+ options[:verbose] = v
42
40
  end
43
41
  end
44
42
 
45
- def parse_options(optparse, args=[])
46
- optparse.order(args)
47
- end
48
-
49
- def run(args=[])
43
+ def run(args=[], options={})
50
44
  expression = args.join(" ").strip
51
45
  if expression.empty?
52
46
  exit(1)
@@ -67,8 +61,8 @@ module Hotdog
67
61
  STDERR.puts("no match found: #{search_args.join(" ")}")
68
62
  exit(1)
69
63
  else
70
- if @ssh_options[:index] && result.length > @ssh_options[:index]
71
- host = result[@ssh_options[:index]]
64
+ if options[:index] && result.length > options[:index]
65
+ host = result[options[:index]]
72
66
  else
73
67
  result, fields = get_hosts_with_search_tags(result, node)
74
68
 
@@ -87,22 +81,22 @@ module Hotdog
87
81
 
88
82
  # build ssh command
89
83
  cmdline = ["ssh"]
90
- @ssh_options[:options].each do |option|
84
+ options[:options].each do |option|
91
85
  cmdline << "-o" << option
92
86
  end
93
- if path = @ssh_options[:identity_file]
87
+ if path = options[:identity_file]
94
88
  cmdline << "-i" << Shellwords.escape(path)
95
89
  end
96
- if port = @ssh_options[:port]
90
+ if port = options[:port]
97
91
  cmdline << "-p" << port.to_s
98
92
  end
99
- if @ssh_options[:forward_agent]
93
+ if options[:forward_agent]
100
94
  cmdline << "-A"
101
95
  end
102
- if @ssh_options[:verbose]
96
+ if options[:verbose]
103
97
  cmdline << "-v"
104
98
  end
105
- if user = @ssh_options[:user]
99
+ if user = options[:user]
106
100
  cmdline << (user + "@" + address)
107
101
  else
108
102
  cmdline << address
@@ -3,7 +3,7 @@
3
3
  module Hotdog
4
4
  module Commands
5
5
  class Tags < BaseCommand
6
- def run(args=[])
6
+ def run(args=[], options={})
7
7
  if args.empty?
8
8
  result = execute("SELECT name, value FROM tags").map { |name, value| [join_tag(name, value)] }
9
9
  show_tags(result)
@@ -5,7 +5,7 @@ require "fileutils"
5
5
  module Hotdog
6
6
  module Commands
7
7
  class Up < BaseCommand
8
- def run(args=[])
8
+ def run(args=[], options={})
9
9
  scopes = args.map { |arg|
10
10
  if arg.index(":").nil?
11
11
  "host:#{arg}"
@@ -25,7 +25,7 @@ module Hotdog
25
25
  attr_reader :logger
26
26
  attr_reader :options
27
27
 
28
- def run(args=[])
28
+ def run(args=[], options={})
29
29
  raise(NotImplementedError)
30
30
  end
31
31
 
@@ -52,7 +52,7 @@ module Hotdog
52
52
  update_db(options)
53
53
  end
54
54
 
55
- def define_options(optparse)
55
+ def define_options(optparse, options={})
56
56
  # nop
57
57
  end
58
58
 
@@ -1,3 +1,3 @@
1
1
  module Hotdog
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
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.5.3
4
+ version: 0.5.4
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-09-28 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -153,10 +153,10 @@ files:
153
153
  - spec/formatter/text_spec.rb
154
154
  - spec/formatter/tsv_spec.rb
155
155
  - spec/formatter/yaml_spec.rb
156
+ - spec/parser/glob_expression_spec.rb
156
157
  - spec/parser/parser_spec.rb
157
- - spec/parser/tag_expression_spec.rb
158
- - spec/parser/tag_glob_expression_spec.rb
159
- - spec/parser/tag_regexp_expression_spec.rb
158
+ - spec/parser/regexp_expression_spec.rb
159
+ - spec/parser/string_expression_spec.rb
160
160
  - spec/spec_helper.rb
161
161
  homepage: https://github.com/yyuu/hotdog
162
162
  licenses:
@@ -192,9 +192,9 @@ test_files:
192
192
  - spec/formatter/text_spec.rb
193
193
  - spec/formatter/tsv_spec.rb
194
194
  - spec/formatter/yaml_spec.rb
195
+ - spec/parser/glob_expression_spec.rb
195
196
  - spec/parser/parser_spec.rb
196
- - spec/parser/tag_expression_spec.rb
197
- - spec/parser/tag_glob_expression_spec.rb
198
- - spec/parser/tag_regexp_expression_spec.rb
197
+ - spec/parser/regexp_expression_spec.rb
198
+ - spec/parser/string_expression_spec.rb
199
199
  - spec/spec_helper.rb
200
200
  has_rdoc: