Class: Sevgi::Function::Shell::Result
- Inherits:
-
Data
- Object
- Data
- Sevgi::Function::Shell::Result
- Defined in:
- lib/sevgi/function/shell.rb
Overview
Immutable result returned by shell commands.
Instance Attribute Summary collapse
-
#args ⇒ Array<String>
readonly
Frozen command arguments.
-
#errs ⇒ Array<String>
readonly
Frozen captured stderr lines.
-
#exit_code ⇒ Integer?
readonly
Process exit code.
-
#outs ⇒ Array<String>
readonly
Frozen captured stdout lines.
-
#signal ⇒ Integer?
readonly
Terminating signal number.
Instance Method Summary collapse
-
#all ⇒ String
Returns captured output with one blank line between non-empty streams.
-
#cmd ⇒ String
Returns the command as a shell-like display string.
-
#err ⇒ String
Returns captured stderr as a string.
-
#initialize(args:, outs:, errs:, exit_code:, signal:) ⇒ void
constructor
Creates an owned result snapshot.
-
#notok? ⇒ Boolean
Reports whether the command failed.
-
#ok? ⇒ Boolean
Reports whether the command exited successfully.
-
#out ⇒ String
Returns captured stdout as a string.
-
#outline ⇒ String?
Returns the first stdout line.
-
#signaled? ⇒ Boolean
Reports whether the command was terminated by a signal.
Constructor Details
#initialize(args:, outs:, errs:, exit_code:, signal:) ⇒ void
Creates an owned result snapshot.
61 62 63 64 65 66 67 68 69 |
# File 'lib/sevgi/function/shell.rb', line 61 def initialize(args:, outs:, errs:, exit_code:, signal:) super( args: args.map { it.to_s.dup.freeze }.freeze, outs: outs.map { it.dup.freeze }.freeze, errs: errs.map { it.dup.freeze }.freeze, exit_code:, signal: ) end |
Instance Attribute Details
#args ⇒ Array<String> (readonly)
Returns frozen command arguments.
42 43 44 |
# File 'lib/sevgi/function/shell.rb', line 42 def args @args end |
#errs ⇒ Array<String> (readonly)
Returns frozen captured stderr lines.
42 43 44 |
# File 'lib/sevgi/function/shell.rb', line 42 def errs @errs end |
#exit_code ⇒ Integer? (readonly)
Returns process exit code.
42 43 44 |
# File 'lib/sevgi/function/shell.rb', line 42 def exit_code @exit_code end |
#outs ⇒ Array<String> (readonly)
Returns frozen captured stdout lines.
42 43 44 |
# File 'lib/sevgi/function/shell.rb', line 42 def outs @outs end |
#signal ⇒ Integer? (readonly)
Returns terminating signal number.
42 43 44 |
# File 'lib/sevgi/function/shell.rb', line 42 def signal @signal end |
Instance Method Details
#all ⇒ String
Returns captured output with one blank line between non-empty streams. Captured lines are joined with one newline and are not otherwise trimmed.
81 82 83 84 85 86 |
# File 'lib/sevgi/function/shell.rb', line 81 def all return err if outs.empty? return out if errs.empty? "#{out}\n\n#{err}" end |
#cmd ⇒ String
Returns the command as a shell-like display string.
90 |
# File 'lib/sevgi/function/shell.rb', line 90 def cmd = ::Shellwords.join(args) |
#err ⇒ String
Returns captured stderr as a string.
94 |
# File 'lib/sevgi/function/shell.rb', line 94 def err = errs.join("\n") |
#notok? ⇒ Boolean
Reports whether the command failed.
98 |
# File 'lib/sevgi/function/shell.rb', line 98 def notok? = !ok? |
#ok? ⇒ Boolean
Reports whether the command exited successfully.
102 |
# File 'lib/sevgi/function/shell.rb', line 102 def ok? = !exit_code.nil? && exit_code.zero? |
#out ⇒ String
Returns captured stdout as a string.
106 |
# File 'lib/sevgi/function/shell.rb', line 106 def out = outs.join("\n") |
#outline ⇒ String?
Returns the first stdout line.
110 |
# File 'lib/sevgi/function/shell.rb', line 110 def outline = outs.first |
#signaled? ⇒ Boolean
Reports whether the command was terminated by a signal.
114 |
# File 'lib/sevgi/function/shell.rb', line 114 def signaled? = !signal.nil? |