configuration.rb
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require "airbrussh/colors"
require "airbrussh/console_formatter"
require "airbrussh/log_file_formatter"
module Airbrussh
class Configuration
attr_accessor :log_file, :monkey_patch_rake, :color, :truncate, :banner,
:command_output, :task_prefix
def initialize
self.log_file = nil
self.monkey_patch_rake = false
self.color = :auto
self.truncate = :auto
self.banner = :auto
self.command_output = false
self.task_prefix = nil
end
def apply_options(options)
return self if options.nil?
options.each do |key, value|
if respond_to?(writer = "#{key}=")
public_send(writer, value)
else
warn_unrecognized_key(key)
end
end
self
end
def banner_message
return nil unless banner
return banner unless banner == :auto
msg = "Using airbrussh format."
if log_file
msg << "\n"
msg << "Verbose output is being written to #{Colors.blue(log_file)}."
end
msg
end
# This returns an array of formatters appropriate for the configuration.
# Depending on whether a log file is configured, this could be just the
# Airbrussh:ConsoleFormatter, or that plus the LogFileFormatter.
def formatters(io)
fmts = [Airbrussh::ConsoleFormatter.new(io, self)]
fmts.unshift(Airbrussh::LogFileFormatter.new(log_file)) if log_file
fmts
end
def show_command_output?(sym)
command_output == true || Array(command_output).include?(sym)
end
private
def warn_unrecognized_key(key)
$stderr.puts("Ignoring unrecognized Airbrussh option: #{key}")
end
end
end