### Configure Airbrussh with New Syntax Source: https://github.com/mattbrictson/airbrussh/blob/main/UPGRADING-CAP-3.5.md In Capistrano 3.5 and later, use `set :format_options` to configure Airbrussh. This example disables color output. ```ruby set :format_options, color: false ``` -------------------------------- ### Install Airbrussh for Capistrano 3.4.x Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md Add Airbrussh as a gem dependency in your application's Gemfile for use with Capistrano versions prior to 3.5.0. Ensure you run `bundle install` after adding the gem. ```ruby gem "airbrussh", require: false ``` -------------------------------- ### Instantiate Airbrussh Formatter Source: https://context7.com/mattbrictson/airbrussh/llms.txt Create a formatter instance directly to manage console and log file output for SSHKit. ```ruby require "airbrussh" # Create formatter with default options output = $stdout formatter = Airbrussh.Formatter.new(output) # Create formatter with inline options hash formatter = Airbrussh.Formatter.new(output, color: true, truncate: 120, banner: "Starting deployment...", command_output: true, log_file: "log/deploy.log" ) # Set as SSHKit's output formatter SSHKit.config.output = formatter ``` -------------------------------- ### Configure Airbrussh settings Source: https://context7.com/mattbrictson/airbrussh/llms.txt Initialize and apply configuration options to control logging, output formatting, and task tracking. ```ruby require "airbrussh" config = Airbrussh::Configuration.new # Apply options via hash config.apply_options( log_file: "log/deploy.log", # nil to disable file logging color: :auto, # :auto, true, or false truncate: :auto, # :auto, integer width, or false banner: :auto, # :auto, custom string, nil, or false command_output: true, # true, false, :stdout, :stderr, or [:stdout, :stderr] task_prefix: nil, # string prefix for task headers monkey_patch_rake: false, # enable Rake task tracking context: Airbrussh::Rake::Context # custom context class ) # Check if command output should be shown for a stream config.show_command_output?(:stdout) # => true config.show_command_output?(:stderr) # => true # Get the banner message (respects :auto setting) config.banner_message # => "Using airbrussh format.\nVerbose output is being written to log/deploy.log." # Create formatters for an IO object formatters = config.formatters($stdout) # => [#, #] ``` -------------------------------- ### Initialize Airbrussh Formatter with SSHKit Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md Use Airbrussh directly with SSHKit by initializing its formatter with standard output. This allows Airbrussh's formatting capabilities to be applied to SSHKit operations. ```ruby require "airbrussh" SSHKit.config.output = Airbrussh::Formatter.new($stdout) ``` -------------------------------- ### Initialize Airbrussh Formatter with SSHKit and Options Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md Initialize the Airbrussh formatter for SSHKit, passing configuration options such as disabling color. This provides customized output formatting for SSHKit commands. ```ruby # You can also pass configuration options like this SSHKit.config.output = Airbrussh::Formatter.new($stdout, color: false) ``` -------------------------------- ### Manage console output Source: https://context7.com/mattbrictson/airbrussh/llms.txt Use the Console class for low-level output, including automatic truncation and ANSI color stripping. ```ruby require "airbrussh/console" config = Airbrussh::Configuration.new config.color = true config.truncate = 80 console = Airbrussh::Console.new($stdout, config) # Print a line with automatic truncation and color handling console.print_line("Deploying to production server...") # Write directly without truncation or newline console.write("Progress: ") # Check console width (returns nil if not a TTY or truncation disabled) width = console.console_width # => 120 # Strip ANSI color codes from a string clean = console.strip_ascii_color("\e[0;32;49mSuccess\e[0m") # => "Success" # Truncate a string to console width with ellipsis truncated = console.truncate_to_console_width("Very long message...") ``` -------------------------------- ### Configure Airbrussh in Capistrano 3.5+ Source: https://context7.com/mattbrictson/airbrussh/llms.txt Use the :format_options variable in deploy.rb to customize Airbrussh behavior in modern Capistrano. ```ruby # In deploy.rb # Enable airbrussh format explicitly (default in 3.5+) set :format, :airbrussh # Pass configuration options to Airbrussh set :format_options, color: true, # Enable ANSI colors truncate: 80, # Truncate at 80 characters command_output: true, # Show stdout and stderr log_file: "log/capistrano.log", # Verbose output location banner: "Capistrano deployment started!", task_prefix: "--- " # CI-friendly collapsible output # Example showing selective command output set :format_options, command_output: :stdout # Show only stdout, hide stderr # Example disabling all command output for minimal display set :format_options, command_output: false # Example with automatic settings for non-TTY environments set :format_options, color: :auto, truncate: :auto ``` -------------------------------- ### Configure Airbrussh globally Source: https://context7.com/mattbrictson/airbrussh/llms.txt Use the Airbrussh.configure block to set global options like log file paths, color settings, and output truncation. ```ruby require "airbrussh" Airbrussh.configure do |config| config.log_file = "log/capistrano.log" # Path for verbose log output config.color = true # Enable ANSI colors (true, false, or :auto) config.truncate = 80 # Truncate output width (integer or :auto) config.banner = "Deployment started!" # Custom banner message (string, :auto, or nil) config.command_output = true # Show command output (true, false, :stdout, :stderr) config.task_prefix = "--- " # Prefix for task names (useful for CI output collapsing) config.monkey_patch_rake = true # Enable Rake task name tracking end ``` -------------------------------- ### Configure Airbrussh via Block for 3.4.x Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md Configure Airbrussh options like color and command output using a configuration block when using Capistrano 3.4.x, as the `:format_options` system is not available. Refer to the configuration section for supported options. ```ruby Airbrussh.configure do |config| config.color = false config.command_output = true # etc. end ``` -------------------------------- ### Use Airbrussh with SSHKit Source: https://context7.com/mattbrictson/airbrussh/llms.txt Configure SSHKit to use the Airbrussh formatter for clean remote command execution output. ```ruby require "airbrussh" require "sshkit" require "sshkit/dsl" # Configure SSHKit to use Airbrussh formatter SSHKit.config.output = Airbrussh::Formatter.new($stdout, color: true, command_output: true ) # Execute remote commands with formatted output on %w[server1.example.com server2.example.com] do execute :echo, "Deploying application" execute :git, :pull, :origin, :main execute :bundle, :install execute :sudo, :systemctl, :restart, :myapp end # Output shows: # 01 echo Deploying application # 01 Deploying application # ✔ 01 user@server1.example.com 0.084s ``` -------------------------------- ### Configure Airbrussh with Old Syntax Source: https://github.com/mattbrictson/airbrussh/blob/main/UPGRADING-CAP-3.5.md Use this syntax for configuring Airbrussh in versions prior to Capistrano 3.5. ```ruby Airbrussh.configure do |config| config.color = false end ``` -------------------------------- ### Log verbose output to file Source: https://context7.com/mattbrictson/airbrussh/llms.txt Use LogFileFormatter to write SSHKit output to a file with automatic rotation. ```ruby require "airbrussh/log_file_formatter" # Create log file formatter (creates directory if needed) log_formatter = Airbrussh::LogFileFormatter.new("log/capistrano.log") # Access the configured path log_formatter.path # => "log/capistrano.log" # The formatter automatically writes a delimiter on creation: # --------------------------------------------------------------------------- # START 2024-01-15 10:30:45 +0000 cap deploy # --------------------------------------------------------------------------- # Use with SSHKit directly require "sshkit" SSHKit.config.output = log_formatter ``` -------------------------------- ### Enable Command Output in Airbrussh Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md Configure Airbrussh to display the output of commands executed via SSH. This is useful when commands do not produce output by default. ```ruby set :format_options, command_output: true ``` -------------------------------- ### Forwarding logs to multiple formatters with DelegatingFormatter Source: https://context7.com/mattbrictson/airbrussh/llms.txt Use DelegatingFormatter to broadcast SSHKit logging to both console and file outputs simultaneously. ```ruby require "airbrussh/delegating_formatter" require "airbrussh/console_formatter" require "airbrussh/log_file_formatter" config = Airbrussh::Configuration.new config.log_file = "log/deploy.log" config.color = true # Create individual formatters console_fmt = Airbrussh::ConsoleFormatter.new($stdout, config) log_fmt = Airbrussh::LogFileFormatter.new(config.log_file) # Combine with delegating formatter combined = Airbrussh::DelegatingFormatter.new([log_fmt, console_fmt]) # All logging methods are forwarded to both formatters combined.info("Deployment starting") combined.warn("Configuration warning") combined.error("Connection failed") # Access underlying formatters combined.formatters # => [log_fmt, console_fmt] ``` -------------------------------- ### Configure Airbrussh Format Options Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md Customize Airbrussh output by setting the :format_options variable in Capistrano. Options include color, truncation, and log file settings. ```ruby # Pass options to Airbrussh set :format_options, color: false, truncate: 80 ``` -------------------------------- ### Tracking Rake tasks with Rake::Context Source: https://context7.com/mattbrictson/airbrussh/llms.txt Rake::Context maintains state for task names and command positioning during execution. ```ruby require "airbrussh/rake/context" config = Airbrussh::Configuration.new config.monkey_patch_rake = true context = Airbrussh::Rake::Context.new(config) # Get current task name (nil if monkey patching disabled or no task running) context.current_task_name # => "deploy:update" # Register a command and check if it's the first execution first_time = context.register_new_command(command) # => true (first time) first_time = context.register_new_command(command) # => false (repeated) # Get command position in current task (zero-based) context.position(command) # => 0 ``` -------------------------------- ### Apply ANSI colors Source: https://context7.com/mattbrictson/airbrussh/llms.txt Use the Colors module to add color to terminal output or mix it into custom classes. ```ruby require "airbrussh/colors" # Use as module methods puts Airbrussh::Colors.red("Error: deployment failed") puts Airbrussh::Colors.green("Success!") puts Airbrussh::Colors.yellow("Warning: check configuration") puts Airbrussh::Colors.blue("Info: starting deploy") puts Airbrussh::Colors.gray("Debug: connection established") # Mix into a class class MyFormatter include Airbrussh::Colors def format_status(success) if success green("✔ Passed") else red("✘ Failed") end end end formatter = MyFormatter.new puts formatter.format_status(true) # Green "✔ Passed" puts formatter.format_status(false) # Red "✘ Failed" ``` -------------------------------- ### Format terminal output Source: https://context7.com/mattbrictson/airbrussh/llms.txt Use ConsoleFormatter to handle task names, command numbers, and status indicators in the terminal. ```ruby require "airbrussh/console_formatter" config = Airbrussh::Configuration.new config.color = true config.command_output = true config.monkey_patch_rake = true formatter = Airbrussh::ConsoleFormatter.new($stdout, config) # The formatter writes banner on initialization # Output: "Using airbrussh format." # Used internally by SSHKit to log commands # Example formatted output during deployment: # # 00:00 deploy:starting # 01 echo "Starting deployment" # 01 Starting deployment # ✔ 01 user@server.example.com 0.052s # 02 git pull origin main # ✔ 02 user@server.example.com 1.234s # 00:05 deploy:updating # 01 bundle install # ✔ 01 user@server.example.com 15.892s ``` -------------------------------- ### Set Capistrano Format to Airbrussh Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md Set the Capistrano format to :airbrussh in your deploy.rb file to enable Airbrussh. ```ruby # In deploy.rb set :format, :airbrussh ``` -------------------------------- ### Decorating command output with CommandFormatter Source: https://context7.com/mattbrictson/airbrussh/llms.txt CommandFormatter adds numbered prefixes and status indicators to SSHKit command output. ```ruby require "airbrussh/command_formatter" # CommandFormatter wraps an SSHKit::Command # position is the zero-based index in the current task command = mock_sshkit_command # SSHKit::Command object formatter = Airbrussh::CommandFormatter.new(command, 0) # Format command output with number prefix formatter.format_output("hello\n") # => "01 hello" # Get the start message (yellow colored command) formatter.start_message # => "01 echo hello" (in yellow) # Get exit message with status and timing # Success (green): "✔ 01 user@host 0.084s" # Failure (red): "✘ 01 user@host 0.084s" formatter.exit_message ``` -------------------------------- ### Restore Old Airbrussh Defaults in Capistrano 3.5 Source: https://github.com/mattbrictson/airbrussh/blob/main/UPGRADING-CAP-3.5.md To revert to the previous default behavior in Capistrano 3.5, explicitly set `banner` to `:auto` and `command_output` to `false` using `set :format_options`. ```ruby set :format_options, banner: :auto, command_output: false ``` -------------------------------- ### Remove Default Format in Capfile for 3.4.x Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md If you have explicitly set Capistrano's `:format` option, remove it to avoid overriding Airbrussh. This ensures Airbrussh functions correctly as the default formatter. ```ruby # Remove this set :format, :pretty ``` -------------------------------- ### Require Airbrussh in Capfile for 3.4.x Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md Include the Airbrussh Capistrano integration in your Capfile when using it with Capistrano 3.4.x. This makes Airbrussh available for your deployment tasks. ```ruby require "airbrussh/capistrano" ``` -------------------------------- ### Aliasing formatter for Capistrano integration Source: https://context7.com/mattbrictson/airbrussh/llms.txt SSHKit::Formatter::Airbrussh allows Capistrano to resolve the formatter using the :airbrussh symbol. ```ruby require "sshkit/formatter/airbrussh" # This class simply inherits from Airbrussh::Formatter # It allows Capistrano to use: set :format, :airbrussh # Capistrano internally looks for SSHKit::Formatter::Airbrussh formatter = SSHKit::Formatter::Airbrussh.new($stdout, color: true) # Equivalent to: formatter = Airbrussh::Formatter.new($stdout, color: true) ``` -------------------------------- ### Disable Truncation for JRuby Compatibility Source: https://github.com/mattbrictson/airbrussh/blob/main/README.md When using JRuby, disable automatic output truncation to work around a known bug in the JRuby 9.0 standard library. This ensures all output is displayed. ```ruby set :format_options, truncate: false ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.