Make ConsoleFormatter's context configurable
pblesi opened this issue · 5 comments
Right now Airbrussh, provides an Airbrussh::Rake::Context
. This Context is used in the ConsoleFormatter
and provides the following interface: current_task_name
, register_new_command
, and position
. In the context of Capistrano, this context is enabled. When a new task is started, the current task changes and the history is reset. Outside the context of Capistrano, when using SSHKit directly, current_task_name
always returns nil
and position
becomes an incrementing number for the entirety of execution.
It would be useful if Airbrussh::Rake::Context
was abstracted so that a context could be set using configuration. This way SSHKit executors that do not use Capistrano/Rake (e.x. https://github.com/braintree/runbook) could define their own implementations of current_task_name
, register_new_command
, and position
.
Thanks for the suggestion! I'm interested in this idea.
What do you think the configuration syntax for this would look like? Is it something the user will put in their Capfile
or deploy.rb
?
Is it something the user will put in their
Capfile
ordeploy.rb
?
Actually, I guess the answer is "neither" since this is intended for users who are not using Capistrano. In that case could you provide an example of what this configuration would look like with plain SSHKit or something like runbook?
Right. So this is how Runbook currently initializes Airbrussh through SSHKit:
If Airbrussh took a context
option as part of its format options, then this would be a way to configure the context. This class would default to Airbrussh::Rake::Context
. Another class could be set that adheres to the specified interface (current_task_name
, register_new_command
, and position
).
I believe the configuration could analogously be applied to the set :format_options
interface used by capistrano:
https://github.com/mattbrictson/airbrussh#configuration
The syntax in the Airbrussh::Formatter initializer case would be:
ssh_kit.output = Airbrussh::Formatter.new(
$stdout,
banner: nil,
command_output: true,
context: Runbook::Airbrussh::Context
)
And in the Capistrano case would be:
set :format_options, color: false, truncate: 80, context: CustomAirbrusshContext
I'd be happy to throw together a PR
Makes sense. Thanks for the writeup.
I'd be happy to throw together a PR
Yes please! 🙏
Fixed via #131