Class: EY::Serverside::Shell

Inherits:
Object
  • Object
show all
Includes:
Logger::Severity
Defined in:
lib/engineyard-serverside/shell.rb,
lib/engineyard-serverside/shell/helpers.rb,
lib/engineyard-serverside/shell/yieldio.rb,
lib/engineyard-serverside/shell/formatter.rb

Defined Under Namespace

Modules: Helpers Classes: Formatter, YieldIO

Constant Summary collapse

STATUS_PREFIX =
'~> '.freeze
SUBSTATUS_PREFIX =
' ~ '.freeze
IMPORTANT_PREFIX =
'!> '.freeze
CMD_PREFIX =
'   $ '.freeze
CMD_CONTINUE =
'   > '.freeze
CMD_INDENT =
'     '.freeze
BOL =
/^/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Shell

Returns a new instance of Shell.


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/engineyard-serverside/shell.rb', line 21

def initialize(options)
  @start_time = options[:start_time] || Time.now
  @verbose    = options[:verbose]

  @stdout = options[:stdout] || $stdout
  @stderr = options[:stderr] || $stderr

  log_pathname = Pathname.new(options[:log_path])
  log_pathname.unlink if log_pathname.exist? # start fresh
  @logger = Logger.new(log_pathname.to_s)
  @logger.level = Logger::DEBUG # Always log to the file at debug, formatter hides debug for non-verbose
  @logger.formatter = EY::Serverside::Shell::Formatter.new(@stdout, @stderr, start_time, @verbose)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger


19
20
21
# File 'lib/engineyard-serverside/shell.rb', line 19

def logger
  @logger
end

#start_timeObject (readonly)

Returns the value of attribute start_time


19
20
21
# File 'lib/engineyard-serverside/shell.rb', line 19

def start_time
  @start_time
end

Instance Method Details

#command_err(msg) ⇒ Object


93
94
95
# File 'lib/engineyard-serverside/shell.rb', line 93

def command_err(msg)
  unknown(msg.gsub(BOL,CMD_INDENT))
end

#command_out(msg) ⇒ Object


89
90
91
# File 'lib/engineyard-serverside/shell.rb', line 89

def command_out(msg)
  debug(msg.gsub(BOL,CMD_INDENT))
end

#command_show(cmd) ⇒ Object

a debug outputter that displays a command being run Formatis like this:

$ cmd blah do \
> something more
> end

85
86
87
# File 'lib/engineyard-serverside/shell.rb', line 85

def command_show(cmd)
  debug(cmd.gsub(BOL,CMD_CONTINUE).sub(CMD_CONTINUE, CMD_PREFIX))
end

#debug(msg) ⇒ Object


72
73
74
# File 'lib/engineyard-serverside/shell.rb', line 72

def debug(msg)
  logger.debug(msg)
end

#error(msg) ⇒ Object


55
56
57
# File 'lib/engineyard-serverside/shell.rb', line 55

def error(msg)
  logger.error("ERROR: #{msg}")
end

#fatal(msg) ⇒ Object


51
52
53
# File 'lib/engineyard-serverside/shell.rb', line 51

def fatal(msg)
  logger.fatal("FATAL: #{msg}")
end

#info(msg) ⇒ Object


68
69
70
# File 'lib/engineyard-serverside/shell.rb', line 68

def info(msg)
  logger.info(msg)
end

#logged_system(cmd, server = nil) ⇒ Object


97
98
99
# File 'lib/engineyard-serverside/shell.rb', line 97

def logged_system(cmd, server = nil)
  EY::Serverside::Spawner.run(cmd, self, server)
end

#notice(msg) ⇒ Object


64
65
66
# File 'lib/engineyard-serverside/shell.rb', line 64

def notice(msg)
  logger.warn(msg)
end

#status(msg) ⇒ Object

a nice info outputter that prepends spermy operators for some reason.


40
41
42
43
44
45
# File 'lib/engineyard-serverside/shell.rb', line 40

def status(msg)
  if msg.respond_to?(:force_encoding)
    msg.force_encoding(Encoding::UTF_8)
  end
  info msg.gsub(BOL, STATUS_PREFIX)
end

#substatus(msg) ⇒ Object


47
48
49
# File 'lib/engineyard-serverside/shell.rb', line 47

def substatus(msg)
  debug msg.gsub(BOL, SUBSTATUS_PREFIX)
end

#unknown(msg) ⇒ Object


76
77
78
# File 'lib/engineyard-serverside/shell.rb', line 76

def unknown(msg)
  logger.unknown(msg)
end

#verbose?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/engineyard-serverside/shell.rb', line 35

def verbose?
  @verbose
end

#warning(msg) ⇒ Object Also known as: warn


59
60
61
# File 'lib/engineyard-serverside/shell.rb', line 59

def warning(msg)
  logger.warn("WARNING: #{msg}")
end