Skip to content

Commit

Permalink
5918 - RPC::Helpers should provide a single host version of printrpc
Browse files Browse the repository at this point in the history
Allow printrpc to print individual results rather than arrays full
for use in the rpc client mode that access the MC::Client directly
  • Loading branch information
ripienaar committed Jan 18, 2011
1 parent a8a02a5 commit 9b56c1e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
12 changes: 10 additions & 2 deletions lib/mcollective/rpc.rb
Expand Up @@ -131,8 +131,16 @@ def printrpc(result, flags = {})
verbose = flags[:verbose] || verbose
flatten = flags[:flatten] || false

puts
puts Helpers.rpcresults(result, {:verbose => verbose, :flatten => flatten})
result_text = Helpers.rpcresults(result, {:verbose => verbose, :flatten => flatten})

if result.is_a?(Array)
puts "\n%s\n" % [ result_text ]
else
# when we get just one result to print dont pad them all with
# blank spaces etc, just print the individual result with no
# padding
puts result_text unless result_text == ""
end
end

# Wrapper for MCollective::Util.empty_filter? to make clients less fugly
Expand Down
5 changes: 2 additions & 3 deletions lib/mcollective/rpc/helpers.rb
Expand Up @@ -85,7 +85,7 @@ def self.rpcresults(result, flags = {})
if flags[:verbose]
result_text = old_rpcresults(result, flags)
else
result.each do |r|
[result].flatten.each do |r|
begin
ddl = DDL.new(r.agent).action_interface(r.action.to_s)

Expand Down Expand Up @@ -165,7 +165,6 @@ def self.text_for_result(sender, status, msg, result, ddl)
end
end

result_text << "\n"
result_text
end

Expand Down Expand Up @@ -203,7 +202,7 @@ def self.old_rpcresults(result, flags = {})

result_text << ""
else
result.each do |r|
[result].flatten.each do |r|

if flags[:verbose]
result_text << "%-40s: %s\n" % [r[:sender], r[:statusmsg]]
Expand Down
1 change: 1 addition & 0 deletions website/changelog.md
Expand Up @@ -11,6 +11,7 @@ title: Changelog

|Date|Description|Ticket|
|----|-----------|------|
|2011/01/17|Allow MC::RPC#printrpc to print single results|5918|
|2011/01/16|Provide SimpleRPC style results when accessing the MC::Client results directly|5912|
|2011/01/11|Add an option to Base64 encode the STOMP payload|5815|
|2011/01/11|Fix a bug with forcing all facts to be strings|5832|
Expand Down
12 changes: 12 additions & 0 deletions website/simplerpc/clients.md
Expand Up @@ -336,6 +336,18 @@ mc.echo(:msg => "hello world") do |resp, simpleresp|
end
{% endhighlight %}

You can still use printrpc to print these style of results and gain advantage of the DDL and so forth:

{% highlight ruby %}
mc.echo(:msg => "hello world") do |resp, simpleresp|
begin
printrpc simpleresp
rescue RPCError => e
puts "The RPC agent returned an error: #{e}"
end
end
{% endhighlight %}

You will need to handle exceptions yourself but you have a simpler result set to deal with

## Adding custom command line options
Expand Down

0 comments on commit 9b56c1e

Please sign in to comment.