mattbrictson / airbrussh

Airbrussh pretties up your SSHKit and Capistrano output
MIT License
514 stars 35 forks source link

Set options per task #82

Open mdesantis opened 8 years ago

mdesantis commented 8 years ago

I have a Capistrano task for rails runner remote execution:

require 'shellwords'

namespace :invoke do

  desc "Execute rails runner on a remote server"
  task :runner do
    if ENV['COMMAND']
      on roles(:app) do
        within current_path do
          with rails_env: fetch(:rails_env) do
            execute :rails, :runner, ENV['COMMAND'].shellescape
          end
        end
      end

    else
      puts "\n\nFailed! You need to specify the 'COMMAND' parameter",
           "Usage: cap <stage> invoke:runner COMMAND=your-command"
    end
  end

end

In this task, but only in this one, I would like to disable truncation. Is it possible to access to Airbrussh formatter within the task in order to set truncation to false?

mattbrictson commented 8 years ago

Capistrano is not really designed to handle per-task logging options.

However, you could hack something together inside your task like this:

task :runner do
  original_truncate = Airbrussh.configuration.truncate
  Airbrussh.configuration.truncate = false
  begin
    # ...
  ensure
    Airbrussh.configuration.truncate = original_truncate
  end
end