Class: SnapshotArchive::Shell
- Inherits:
-
Object
- Object
- SnapshotArchive::Shell
- Defined in:
- lib/snapshot_archive/shell.rb
Constant Summary collapse
- CODES =
{ red: 31, green: 32, yellow: 33, pink: 35, }.freeze
- CommandFailureError =
Class.new(StandardError)
Instance Method Summary collapse
- #debug(msg) ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(verbose: false) ⇒ Shell
constructor
A new instance of Shell.
- #notify(msg) ⇒ Object
- #puts(msg) ⇒ Object
- #run(cmd) ⇒ Object
- #warn(msg) ⇒ Object
Constructor Details
#initialize(verbose: false) ⇒ Shell
Returns a new instance of Shell.
12 13 14 |
# File 'lib/snapshot_archive/shell.rb', line 12 def initialize(verbose: false) @verbose = verbose end |
Instance Method Details
#debug(msg) ⇒ Object
40 41 42 |
# File 'lib/snapshot_archive/shell.rb', line 40 def debug(msg) puts(msg) if @verbose end |
#info(msg) ⇒ Object
36 37 38 |
# File 'lib/snapshot_archive/shell.rb', line 36 def info(msg) puts(msg) end |
#notify(msg) ⇒ Object
28 29 30 |
# File 'lib/snapshot_archive/shell.rb', line 28 def notify(msg) print "#{colorize(msg, :yellow)}\n" end |
#puts(msg) ⇒ Object
32 33 34 |
# File 'lib/snapshot_archive/shell.rb', line 32 def puts(msg) print "#{msg}\n" end |
#run(cmd) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/snapshot_archive/shell.rb', line 16 def run(cmd) debug(cmd) `#{cmd} 2>&1` .split("\n") .tap { raise CommandFailureError.new([cmd, _1].join("\n---\n")) unless $? == 0 } end |
#warn(msg) ⇒ Object
24 25 26 |
# File 'lib/snapshot_archive/shell.rb', line 24 def warn(msg) print "#{colorize(msg, :red)}\n" end |