Class: Babushka::Shell
- Inherits:
-
Object
- Object
- Babushka::Shell
- Includes:
- LogHelpers
- Defined in:
- lib/babushka/shell.rb
Defined Under Namespace
Classes: ShellCommandFailed
Instance Attribute Summary (collapse)
-
- (Object) cmd
readonly
Returns the value of attribute cmd.
-
- (Object) env
readonly
Returns the value of attribute env.
-
- (Object) opts
readonly
Returns the value of attribute opts.
-
- (Object) result
readonly
Returns the value of attribute result.
-
- (Object) stderr
readonly
Returns the value of attribute stderr.
-
- (Object) stdout
readonly
Returns the value of attribute stdout.
Instance Method Summary (collapse)
-
- (Shell) initialize(*cmd)
constructor
A new instance of Shell.
- - (Boolean) ok?
- - (Object) run(&block)
Methods included from LogHelpers
#debug, #log, #log_block, #log_error, #log_ok, #log_verbose, #log_warn
Constructor Details
- (Shell) initialize(*cmd)
A new instance of Shell
20 21 22 23 24 25 26 |
# File 'lib/babushka/shell.rb', line 20 def initialize *cmd @opts = cmd. raise "You can't use :spinner and :progress together in Babushka::Shell." if opts[:spinner] && opts[:progress] @env = cmd.first.is_a?(Hash) ? cmd.shift : {} @cmd = cmd @progress = nil end |
Instance Attribute Details
- (Object) cmd (readonly)
Returns the value of attribute cmd
18 19 20 |
# File 'lib/babushka/shell.rb', line 18 def cmd @cmd end |
- (Object) env (readonly)
Returns the value of attribute env
18 19 20 |
# File 'lib/babushka/shell.rb', line 18 def env @env end |
- (Object) opts (readonly)
Returns the value of attribute opts
18 19 20 |
# File 'lib/babushka/shell.rb', line 18 def opts @opts end |
- (Object) result (readonly)
Returns the value of attribute result
18 19 20 |
# File 'lib/babushka/shell.rb', line 18 def result @result end |
- (Object) stderr (readonly)
Returns the value of attribute stderr
18 19 20 |
# File 'lib/babushka/shell.rb', line 18 def stderr @stderr end |
- (Object) stdout (readonly)
Returns the value of attribute stdout
18 19 20 |
# File 'lib/babushka/shell.rb', line 18 def stdout @stdout end |
Instance Method Details
- (Boolean) ok?
28 |
# File 'lib/babushka/shell.rb', line 28 def ok?; result == 0 end |
- (Object) run(&block)
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/babushka/shell.rb', line 30 def run &block @stdout, @stderr = '', '' @result = invoke print "#{" " * (@progress.length + 1)}#{"\b" * (@progress.length + 1)}" unless @progress.nil? if block_given? yield(self) elsif ok? stdout.chomp else raise ShellCommandFailed.new(cmd, stdout, stderr) end end |