ruby-on-rails - 显示 SSHKit 调用的 rake 任务的输出

标签 ruby-on-rails ruby rake sshkit

我希望能够从 SSHKit 调用的 rake 任务中输出信息,但我不知道该怎么做。

假设我有以下 rake 任务:

require 'sshkit/dsl'

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

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

如果我自己运行 :hello 任务,我会看到“hello world”语句。但是,从 sshkit 任务调用它,我只得到 SSHKit 信息。我如何写出从 SSHKit 调用时出现的第一个 rake 任务的信息?

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).

编辑1:

我发现您可以添加以下内容以获得基本的终端输出:

SSHKit.config.output = $stdout 

但是,同样,输出的信息是相同的——它告诉您它正在运行“rake hello”,而不是“rake hello”的输出。

rake sshkit_hello
=> rake hello

最佳答案

解决了!

我实际上需要做的是将 output_verbosity 更改为 :debug 以便它在第二个 rake 任务中显示 puts 语句:

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).

关于ruby-on-rails - 显示 SSHKit 调用的 rake 任务的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21910685/

相关文章:

ruby-on-rails - Rails 在结合了 "respond_to?"和 "send"的 ActiveRecord 模型上有一个实例方法吗?

ruby-on-rails - 无法在 Rails 5.1.2 项目上使用 Milia

ruby-on-rails - 范围作为 rails_admin 中的过滤器

rake - 如何使用rails/rake为对象添加PostgreSQL注释?

ruby-on-rails - rake 工作 :work issue in implementing projectfedena

ruby-on-rails - mod_http_upload - 使用 Ruby on Rails 上传 HTTP 文件 (XEP-0363)

ruby-on-rails - Rspec + Capybara - Paypal Express 沙盒结帐时间

ruby-on-rails - 创建嵌套关联记录 Ruby on Rails

ruby - Soundcloud Oauth 实现 : Why the hash parameters?

ruby - 如何声明依赖于参数化任务的 Rake 任务?