Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API for setting+configuring formatter: use_format #294

Merged

Conversation

mattbrictson
Copy link
Member

As discussed in mattbrictson/airbrussh#64 (comment), this PR adds a new API for setting the SSHKit output.

Before:

SSHKit.config.format = :pretty

After:

SSHKit.config.use_format :pretty

The benefit is that the new use_format accepts arbitrary arguments that are then passed to the formatter's constructor. This allows a formatter to be configured.

Hypothetical example:

SSHKit.config.use_format :airbrussh, :color => true, :truncate => false

This would construct SSHKit::Formatter::Airbrussh and pass { :color => true, :truncate => false } to its constructor.

SSHKit's current formatters do not yet accept extra arguments, but this API lays the groundwork for future formatters or formatter gems like airbrussh that are configurable and would benefit from a standard API for doing so.

Eventually we could deprecate the format= API, but that can be a separate PR.

@leehambley, @robd Let me know if this looks good and I'll expand this PR to a CHANGELOG entry and update the docs.

Also: this PR fixes a bug where calling format = :bad_value proceeds with no error or warning, but blows up later once a logging operation is attempted. Now it will immediately raise NameError.

This makes the error more explicit and helpful. Previously, setting
`output.format = :bad_value` would not raise immediately, but would fail later
with a confusing error once a logging operation is attempted.
This commit introduces `use_format`, which is like the existing `format=` but
optionally accepts arguments/options that will be passed to the formatter's
constructor.

SSHKit's current formatters do not yet accept extra arguments, but this API
lays the groundwork for future formatters or formatter gems like airbrussh that
are configurable and would benefit from a standard API for doing so.
@robd
Copy link
Contributor

robd commented Nov 1, 2015

👍 This looks good to me

leehambley added a commit that referenced this pull request Nov 1, 2015
New API for setting+configuring formatter: use_format
@leehambley leehambley merged commit ca52aaa into capistrano:master Nov 1, 2015
@leehambley
Copy link
Member

Thanks @mattbrictson nice work, sorry merged out of habit, and then reverted. I'm around for an hour more thing evening if you have time, looks good to me though.

@mattbrictson
Copy link
Member Author

@leehambley It should be good to merge now.

I updated the README to refer to use_format, and I also removed references to using a String or File as a formatter (i.e. anything that has a << method), because those no longer work with SSHKit's new fine-grained logging methods (e.g. log_command_start).

I also put entries in the CHANGELOG.

@mattbrictson
Copy link
Member Author

Hmm.. GitHub is not pulling the new commits into the PR. Do I need to create a new PR?

@mattbrictson
Copy link
Member Author

@leehambley Please merge #296 instead. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants