Custom output with capistrano 3

285 views Asked by At

I need to change output which is generated with sshkit formatters, and I can't install additional gems, but I can adjust my capistrano 3 configs. At first I tried just create new Formatter (I just copy paste pretty formatter, and made some output changes). like this https://gist.github.com/Dariusp/3e455fdb78b9f8636289 than set :format, :improvedformatter in deploy.rb file. And add

 require_relative 'lib/improved_formatter'

to Capfile. But I always get error "Abstract formatter should not be used directly, maybe you want SSHKit::Formatter::BlackHole", like I am trying use abstract formatter directly. if I try extend PrettyFormater, I get PrettyFormatter output, without my changes. It seems like always it execute parent class method. Its there any way how to create and set custom formatter in my capistrano configs ?

1

There are 1 answers

0
Fanny Strudel On BEST ANSWER

I ran into the exact same issue when I wanted to override the pretty formatter. The problem was that I needed to also define the "<<" operator as this is defined as an alias in the base class and aliases are not inherited.

in deploy.rb:

set :format, :myformatter

in Capfile:

require 'lib/sshkit/formatters/myformatter'

in lib/sshkit/formatters/myformatter.rb:

module SSHKit
  module Formatter
    class MyFormatter < Pretty

     def <<(obj)
       write(obj)
     end

     def write(obj)
      ...
     end
    end
  end
end