smith 0.7.3 → 0.7.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c23b69a6f4301a873fa28d72bf647d1a55f7be5
4
- data.tar.gz: c95dbea268470374884fe322e12319b6d1722a77
3
+ metadata.gz: 79102bfef4bada48d73758f32078771d6100e759
4
+ data.tar.gz: 8405a9460440fdc43abc5072f0f1566848a30741
5
5
  SHA512:
6
- metadata.gz: 4da08538d2ac1a625cf2d491308281591b4b76f01d88498c14bf395dab50e78966b8a26ef6b447ee341e6b6666f7d6f3a6cea3d3229af7515c34652c9589a911
7
- data.tar.gz: 9484464efc2fd47fd667af75974a4ef7a18a9edc60897293465db77165af77ca18ffa75013295db3770f4c7d21f1cf5f2b1c21ab1386ef829c193bdf5b3b0530
6
+ metadata.gz: 201c524f5a686fe1372d264b46ee665a78143ea17335ad7eab6bf50cd6ea27c424f991a5037224f65c03521442b3911cbd121fdcabad3deb56e0629ee390ebcc
7
+ data.tar.gz: 087cd24ebce5fca132d8ac5b79a1e4054efeb91bb52ce2a2bdcd3106a2655b9553d141654e9ce5c95a2e86df6e21db2d4be8df2df9573d544c0695efa65a22eb
@@ -35,7 +35,7 @@ module Smith
35
35
  def find_by_name(*names)
36
36
  inject([]) do |a, agent|
37
37
  a.tap do |acc|
38
- names.flatten.each do |name|
38
+ names.flatten.uniq.each do |name|
39
39
  acc << agent if name == agent.name
40
40
  end
41
41
  end
@@ -28,12 +28,12 @@ module Smith
28
28
  end.read
29
29
  end
30
30
 
31
- def banner(banner=nil, opts={})
31
+ def banner(banner=nil, additional_text=nil, opts={})
32
32
  if banner.nil?
33
33
  @banner
34
34
  else
35
35
  @banner = banner
36
- @parser.banner((opts[:no_template]) ? banner : banner_template(banner))
36
+ @parser.banner((opts[:no_template]) ? banner : banner_template(banner, additional_text))
37
37
  end
38
38
  end
39
39
 
@@ -57,16 +57,15 @@ module Smith
57
57
 
58
58
  private
59
59
 
60
- def banner_template(text)
61
- return <<-EOS
62
-
60
+ def banner_template(text, additional_text)
61
+ return %(
63
62
  #{text}
64
63
 
65
64
  Usage:
66
- smithctl #{self.class.to_s.split('::').last.downcase} [Options]
65
+ smithctl #{self.class.to_s.split('::').last.downcase} [Options]#{(additional_text) ? " #{additional_text}" : ''}
67
66
 
68
67
  [Options] are:
69
- EOS
68
+ )
70
69
  end
71
70
  end
72
71
  end
@@ -1,28 +1,30 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ require_relative '../common'
3
+
2
4
  module Smith
3
5
  module Commands
4
6
  class Agents < CommandBase
7
+ include Common
8
+
5
9
  def execute
6
10
  responder.succeed(_agents)
7
11
  end
8
12
 
13
+ # Return the fully qualified class of all avaiable agents
9
14
  def _agents
10
- # FIXME make sure that if the path doesn't exist don't blow up.
11
15
  separator = (options[:one_column]) ? "\n" : " "
12
16
 
13
- Smith.agent_directories.inject([]) do |path_acc, path|
14
- path_acc.tap do |a|
15
- if path.exist?
16
- a << path.each_child.inject([]) do |agent_acc, p|
17
- agent_acc.tap do |b|
18
- b << Extlib::Inflection.camelize(p.basename('.rb')) if p.file? && p.basename('.rb').to_s.end_with?("agent")
19
- end
20
- end.flatten
21
- else
22
- return "Agent path doesn't exist: #{path}"
17
+ if options[:group]
18
+ agent_group(options[:group]).sort.join(separator)
19
+ else
20
+ Smith.agent_directories.each_with_object([]) do |agent_root_path, acc|
21
+ Pathname.glob(agent_root_path.join("**/*")).each do |agent_path|
22
+ if !agent_path.symlink? && !agent_path.directory?
23
+ acc << Utils.class_name_from_path(agent_path, agent_root_path)
24
+ end
23
25
  end
24
- end
25
- end.flatten.sort.join(separator)
26
+ end.sort.join(separator)
27
+ end
26
28
  end
27
29
 
28
30
  private
@@ -30,7 +32,8 @@ module Smith
30
32
  def options_spec
31
33
  banner "List all available agents."
32
34
 
33
- opt :one_column, "the number of times to send the message", :short => :s
35
+ opt :one_column, "List one agent per line", :short => :s
36
+ opt :group, "list only agents in this group", :type => :string, :short => :g
34
37
  end
35
38
  end
36
39
  end
@@ -14,15 +14,18 @@ module Smith
14
14
 
15
15
  # Returns the agents in a group.
16
16
  def group(&blk)
17
+ separator = (options[:one_column]) ? "\n" : " "
17
18
  begin
18
- blk.call(agent_group(target.first).join(' '))
19
+ blk.call(agent_group(target.first).join(separator))
19
20
  rescue RuntimeError => e
20
21
  blk.call(e.message)
21
22
  end
22
23
  end
23
24
 
24
25
  def options_spec
25
- banner "Lists the agents in a group."
26
+ banner "Lists the agents in a group.", "<group>"
27
+
28
+ opt :one_column, "Lists one agent per line", :short => :s
26
29
  end
27
30
  end
28
31
  end
@@ -1,7 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ require_relative '../common'
3
+
2
4
  module Smith
3
5
  module Commands
4
6
  class Kill < CommandBase
7
+
8
+ include Common
9
+
5
10
  def execute
6
11
  work = ->(acc, uuid, iter) do
7
12
  if agents.exist?(uuid)
@@ -15,11 +20,19 @@ module Smith
15
20
 
16
21
  done = ->(errors) { responder.succeed(format_error_message(errors)) }
17
22
 
18
- EM::Iterator.new(target).inject([], work, done)
23
+ EM::Iterator.new(agents_to_kill).inject([], work, done)
19
24
  end
20
25
 
21
26
  private
22
27
 
28
+ def agents_to_kill
29
+ if options[:group]
30
+ agents.find_by_name(agent_group(options[:group])).map(&:uuid)
31
+ else
32
+ target
33
+ end
34
+ end
35
+
23
36
  def format_error_message(errors)
24
37
  errors = errors.compact
25
38
  case errors.size
@@ -33,7 +46,9 @@ module Smith
33
46
  end
34
47
 
35
48
  def options_spec
36
- banner "Kill an agent/agents."
49
+ banner "Kill an agent/agents.", "<uuid[s]>"
50
+
51
+ opt :group, "kill agents in this group", :type => :string, :short => :g
37
52
  end
38
53
  end
39
54
  end
@@ -64,7 +64,7 @@ module Smith
64
64
  end
65
65
 
66
66
  def options_spec
67
- banner "List the running agents."
67
+ banner "List the running agents.", "<agent name[s]>"
68
68
 
69
69
  opt :long, "shows full details of running agents", :short => :l
70
70
  opt :group, "list only agents in this group", :type => :string, :short => :g
@@ -57,7 +57,7 @@ module Smith
57
57
  end
58
58
 
59
59
  def options_spec
60
- banner "Change the log and trace level of the agents or the agency."
60
+ banner "Change the log and trace level of the agents or the agency.", "<uuid[s]>"
61
61
 
62
62
  opt :level, "the log level you want to set", :type => :string, :short => :l
63
63
  opt :trace, "turn trace on or off", :type => :boolean, :short => :t
@@ -9,7 +9,7 @@ module Smith
9
9
  private
10
10
 
11
11
  def options_spec
12
- banner "Display an agent/agents metadata."
12
+ banner "Display an agent/agents metadata.", "<uuid>"
13
13
  end
14
14
  end
15
15
  end
@@ -25,7 +25,7 @@ module Smith
25
25
  begin
26
26
  agents_to_start = agent_group(options[:group])
27
27
  if agents_to_start.empty?
28
- blk.call("Agent group is empty. No agents started: #{options[:group]}")
28
+ blk.call("Empty group: #{options[:group]}. No agents started")
29
29
  else
30
30
  start_agents(agents_to_start, &blk)
31
31
  end
@@ -63,7 +63,7 @@ module Smith
63
63
  end
64
64
 
65
65
  def options_spec
66
- banner "Start an agent/agents or group of agents."
66
+ banner "Start an agent/agents or group of agents.", "<agent[s]>"
67
67
 
68
68
  opt :group, "Start everything in the specified group", :type => :string, :short => :g
69
69
  end
@@ -55,7 +55,7 @@ module Smith
55
55
  begin
56
56
  agents_to_stop = agents.find_by_name(agent_group(options[:group])).map(&:uuid)
57
57
  if agents_to_stop.empty?
58
- blk.call("There are no agents in group: #{options[:group]}")
58
+ blk.call("Empty group: #{options[:group]}. No agents stopped")
59
59
  end
60
60
  rescue RuntimeError => e
61
61
  return blk.call(e.message)
@@ -98,7 +98,7 @@ module Smith
98
98
  end
99
99
 
100
100
  def options_spec
101
- banner "Stop an agent/agents."
101
+ banner "Stop an agent/agents.", "<uuid[s]>"
102
102
 
103
103
  opt :group, "Stop everything in the specified group", :type => :string, :short => :g
104
104
  opt :name, "Stop an agent(s) by name", :type => :string, :short => :n
@@ -18,7 +18,7 @@ module Smith
18
18
  if group_directory.exist? && group_directory.directory?
19
19
  agents = Pathname.glob(group_directory.join("*.rb")).map(&:expand_path)
20
20
 
21
- agents.each_with_object([]) do |agent, acc|
21
+ agents.inject([]) do |acc, agent|
22
22
  if agent.symlink?
23
23
  expanded_agent_path = resolve_agent_path(group_directory, agent)
24
24
  acc << Utils.class_name_from_path(expanded_agent_path, agent_directory)
@@ -68,7 +68,7 @@ module Smith
68
68
  end
69
69
 
70
70
  def options_spec
71
- banner "List and display acl files."
71
+ banner "List and display acl files.", "[acl]"
72
72
 
73
73
  opt :long, "format the listing", :short => :l
74
74
  opt :show, "show the contents of the acl file", :short => :s
@@ -5,7 +5,11 @@ module Smith
5
5
  module Commands
6
6
  class Dump < CommandBase
7
7
  def execute
8
- dump
8
+ if options[:'yes-i-want-to-remove-all-acls-from-the-queue']
9
+ dump
10
+ else
11
+ responder.succeed("Missing option. You need to supply the ridiculously long anti-fuckup option.")
12
+ end
9
13
  end
10
14
 
11
15
  def dump
@@ -67,10 +71,10 @@ module Smith
67
71
  private
68
72
 
69
73
  def options_spec
70
- banner "Dump a queue to STDOUT.\n\n This is a very DANGEROUS command in that it removes all messages from a queue."
74
+ banner "Dump a queue to STDOUT.\n\n This is a very DANGEROUS command in that it removes all messages from a queue.", "<queue>"
71
75
 
72
- opt :'yes-i-want-to-remove-all-messaeges-from-the-queue', "Remove all messages from the queue and print to stdout", :type => :boolean, :short => :none
73
- opt :verbose, "print the number of messages backed up.", :type => :boolean, :short => :v
76
+ opt :'yes-i-want-to-remove-all-acls-from-the-queue', "Remove all acls from the queue and print to stdout", :type => :boolean, :short => :none
77
+ opt :verbose, "Print the number of acls dumped.", :type => :boolean, :short => :v
74
78
  end
75
79
  end
76
80
  end
@@ -26,10 +26,11 @@ module Smith
26
26
  end
27
27
 
28
28
  def options_spec
29
- b = ["Listens to the rabbitmq firehose for the named queue and prints decoded message to stdout.",
30
- " Be warned it can produce vast amounts of outpu.\n",
31
- " You _must_ run 'rabbitmqctl trace_on' for this to work."]
32
- banner b.join("\n")
29
+ banner %(Listens on the rabbitmq firehose for the named queue and prints decoded
30
+ message to stdout.
31
+
32
+ Be warned it can produce vast amounts of outpu. You _must_ run 'rabbitmqctl
33
+ trace_on' for this to work.), "<queue>"
33
34
 
34
35
  opt :json, "return the JSON representation of the message", :short => :j
35
36
  opt :direction, "Show messages that are leaving the broker [deliver|publish]", :short => :d, :type => :string, :default => 'deliver'
@@ -74,7 +74,7 @@ module Smith
74
74
  end
75
75
 
76
76
  def options_spec
77
- banner "Pop messages off the named queue."
77
+ banner "Pop messages off the named queue.", "<queue>"
78
78
 
79
79
  opt :print, "print the message", :short => :p
80
80
  opt :json , "return the JSON representation of the message", :short => :j
@@ -88,9 +88,9 @@ module Smith
88
88
  end
89
89
 
90
90
  def options_spec
91
- banner "Send a message to a queue. The ACL can also be specified."
91
+ banner "Pushs an ACL on to a queue.", "<queue>"
92
92
 
93
- opt :type, "message type", :type => :string, :default => 'default', :short => :t
93
+ opt :type, "message type", :type => :string, :required => true, :short => :t
94
94
  opt :message, "the message, as json", :type => :string, :short => :m
95
95
  opt :file, "read messages from the named file", :type => :string, :short => :f
96
96
  opt :number, "the number of times to send the message", :type => :integer, :default => 1, :short => :n
@@ -23,7 +23,7 @@ module Smith
23
23
  private
24
24
 
25
25
  def options_spec
26
- banner "Display or remove a message from the named queue."
26
+ banner "Display or remove a message from the named queue.", "<queue>"
27
27
 
28
28
  opt :force, "force the removal even if there are messages on the queue", :short => :f
29
29
  opt :ignore_errors, "ignore any errors.", :default => false
@@ -25,7 +25,7 @@ module Smith
25
25
  end
26
26
 
27
27
  def options_spec
28
- banner "Subcribe to the named queue and print and received messages to stdout."
28
+ banner "Subcribe to the named queue and print and received messages to stdout.", "<queue>"
29
29
 
30
30
  opt :durable, "amqp durable option", :default => false
31
31
  opt :auto_delete, "amqp auto-delete option", :default => false
@@ -97,7 +97,9 @@ module Smith
97
97
 
98
98
  @timeout ||= Timeout.new(Smith.config.smith.timeout, :queue_name => @queue_def.denormalise)
99
99
 
100
- queue_def = QueueDefinition.new(opts.delete(:reply_queue_name) || "#{@queue_def.denormalise}.reply", opts.merge(:auto_delete => true, :durable => false))
100
+ reply_queue = opts.delete(:reply_queue_name) { random("#{@queue_def.denormalise}.") }
101
+
102
+ queue_def = QueueDefinition.new(reply_queue, opts.merge(:auto_delete => true, :durable => false))
101
103
  logger.debug { "reply queue: #{queue_def.denormalise}" }
102
104
 
103
105
  @reply_queue_completion ||= EM::Completion.new.tap do |completion|
data/lib/smith/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Smith
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smith
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Heycock
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-25 00:00:00.000000000 Z
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -190,6 +190,20 @@ dependencies:
190
190
  - - '='
191
191
  - !ruby/object:Gem::Version
192
192
  version: 0.1.4
193
+ - !ruby/object:Gem::Dependency
194
+ name: hashie
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: '2.1'
200
+ type: :runtime
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - "~>"
205
+ - !ruby/object:Gem::Version
206
+ version: '2.1'
193
207
  - !ruby/object:Gem::Dependency
194
208
  name: curses
195
209
  requirement: !ruby/object:Gem::Requirement