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

Allow ConsoleFormatter context to be configurable #131

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Here are the options you can use, and their effects (note that the defaults may
|`banner`|`nil`|Provide a string (e.g. "Capistrano started!") that will be printed when Capistrano starts up.|
|`color`|`:auto`|Use `true` or `false` to enable or disable ansi color. If set to `:auto`, Airbrussh automatically uses color based on whether the output is a TTY, or if the SSHKIT_COLOR environment variable is set.|
|`command_output`|`true`|Set to `:stdout`, `:stderr`, or `true` to display the SSH output received via stdout, stderr, or both, respectively. Set to `false` to not show any SSH output, for a minimal look.|
|`context`|`Airbrussh::Rake::Context`|Defines the execution context. Targeted towards uses of Airbrussh outside of Rake/Capistrano. Alternate implementations should provide the definition for `current_task_name`, `register_new_command`, and `position`.|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great documentation, thanks! 😍

|`log_file`|`log/capistrano.log`|Capistrano's verbose output is saved to this file to facilitate debugging. Set to `nil` to disable completely.|
|`truncate`|`:auto`|Set to a number (e.g. 80) to truncate the width of the output to that many characters, or `false` to disable truncation. If `:auto`, output is automatically truncated to the width of the terminal window, if it can be determined.|
|`task_prefix`|`nil`|A string to prefix to task output. Handy for output collapsing like [buildkite](https://buildkite.com/docs/builds/managing-log-output)'s `---` prefix|
Expand Down
3 changes: 2 additions & 1 deletion lib/airbrussh/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Airbrussh
class Configuration
attr_accessor :log_file, :monkey_patch_rake, :color, :truncate, :banner,
:command_output, :task_prefix
:command_output, :task_prefix, :context

def initialize
self.log_file = nil
Expand All @@ -15,6 +15,7 @@ def initialize
self.banner = :auto
self.command_output = false
self.task_prefix = nil
self.context = Airbrussh::Rake::Context
end

def apply_options(options)
Expand Down
2 changes: 1 addition & 1 deletion lib/airbrussh/console_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(io, config=Airbrussh.configuration)
super(io)

@config = config
@context = Airbrussh::Rake::Context.new(config)
@context = config.context.new(config)
@console = Airbrussh::Console.new(original_output, config)

write_banner
Expand Down
5 changes: 4 additions & 1 deletion test/airbrussh/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_defaults
assert_nil(@config.task_prefix)
refute(@config.monkey_patch_rake)
refute(@config.command_output)
assert_equal(Airbrussh::Rake::Context, @config.context)
end

def test_apply_options
Expand All @@ -25,7 +26,8 @@ def test_apply_options
:truncate => false,
:banner => "hi",
:monkey_patch_rake => true,
:command_output => true
:command_output => true,
:context => Class
)

assert_equal("test", @config.log_file)
Expand All @@ -34,6 +36,7 @@ def test_apply_options
assert_equal("hi", @config.banner)
assert(@config.monkey_patch_rake)
assert(@config.command_output)
assert_equal(Class, @config.context)
end

def test_apply_options_warns_on_stderr_of_bad_key
Expand Down