1

I'd like to be able to output information from a rake task called by SSHKit but I can't see how to do it.

Say I have the following rake tasks:

require 'sshkit/dsl'

task :hello => :environment do  
  puts "Hello world"
end

task :sshkit_hello => :environment do  
  run_locally do
    rake "hello"  
  end
end

If I run the :hello task on it's own I see the "hello world" statement. However, call it from the sshkit task and I just get SSHKit info. How can I write out info from that first rake task that will appear when called from SSHKit?

rake hello
=> Hello world

rake sshkit_hello
=> INFO [f0857f14] Running /usr/bin/env rake hello on 
=> INFO [f0857f14] Finished in 6.107 seconds with exit status 0 (successful).

EDIT1:

I've found that you can add the following to get basic terminal output:

SSHKit.config.output = $stdout 

but, again, the information outputted is the same - it tells you that it's running 'rake hello' but not the output from 'rake hello'.

rake sshkit_hello
=> rake hello
Chris Lewis
  • 1,315
  • 10
  • 25
  • It's in the readme? https://github.com/capistrano/sshkit#output-handling – Mike Szyndel Feb 20 '14 at 16:08
  • I've been through that and don't get how it works. Simply adding SSHKit.config.output = SSHKit.config.formatter.new($stdout) causes it to blow up at the moment because the formatter method is now a private method. So either the docs need updating or there's another way to do it... – Chris Lewis Feb 24 '14 at 10:12
  • I looked through open issues and don't see anything similiar, but `SSHKit.config.formatter` is definitely private so you may try opening a new issue. Also - looking at number of open issues (and repeating ones) I wouldn't consider this gem very reliable. – Mike Szyndel Feb 24 '14 at 10:24
  • Can you try adding this in config? `SSHKit.config.formatter = :pretty` – Mike Szyndel Feb 24 '14 at 10:25
  • Hi Michael, adding that produces undefined method `formatter=' for # – Chris Lewis Feb 24 '14 at 10:30
  • ah, it should be SSHKit.config.format = :pretty - but that is actually the default behaviour anyway so no real change. – Chris Lewis Feb 24 '14 at 10:36
  • 1
    Thanks for your help though Michael. I'd have probably given up had you not kept suggesting things.... – Chris Lewis Feb 24 '14 at 10:48
  • 1
    Great you solved that! You can get extra karma for opening pull request with updated README on github! :) – Mike Szyndel Feb 24 '14 at 10:53

1 Answers1

5

Solved!

What I actually needed to do was change the output_verbosity to :debug in order for it to show the puts statement in the second rake task:

SSHKit.config.output_verbosity = :debug

rake sshkit_hello
=>  INFO [6dd1bbf7] Running bundle exec rake hello on 
=> DEBUG [6dd1bbf7] Command: bundle exec rake hello
=> DEBUG [6dd1bbf7]     Hello World!
=>  INFO [6dd1bbf7] Finished in 6.596 seconds with exit status 0 (successful).
Chris Lewis
  • 1,315
  • 10
  • 25