Class: Bsdkrun::Result
- Inherits:
-
Data
- Object
- Data
- Bsdkrun::Result
- Defined in:
- lib/bsdkrun/types.rb
Overview
The captured result of running a command in a guest via Sandbox#exec.
Instance Attribute Summary collapse
-
#command ⇒ String
readonly
A human label for the command.
- #exit_code ⇒ Integer readonly
- #stderr ⇒ String readonly
- #stdout ⇒ String readonly
Instance Method Summary collapse
-
#json ⇒ Object
Stdout parsed as JSON.
-
#lines ⇒ Array<String>
Non-empty stdout lines.
-
#ok? ⇒ Boolean
Whether the command succeeded (exit 0).
-
#text ⇒ String
Stdout with trailing newlines trimmed — the common case.
- #throw_if_failed! ⇒ self
Instance Attribute Details
#command ⇒ String (readonly)
Returns a human label for the command.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/bsdkrun/types.rb', line 166 Result = Data.define(:stdout, :stderr, :exit_code, :command) do # @return [Boolean] whether the command succeeded (exit 0). def ok? exit_code.zero? end # @return [String] stdout with trailing newlines trimmed — the common case. def text stdout.sub(/\n+\z/, "") end # @return [Object] stdout parsed as JSON. def json require "json" JSON.parse(stdout) end # @return [Array<String>] non-empty stdout lines. def lines stdout.split("\n").reject(&:empty?) end # @raise [CommandFailed] if the command exited non-zero. # @return [self] def throw_if_failed! unless ok? raise CommandFailed.new( exit_code: exit_code, stdout: stdout, stderr: stderr, command: command ) end self end end |
#exit_code ⇒ Integer (readonly)
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/bsdkrun/types.rb', line 166 Result = Data.define(:stdout, :stderr, :exit_code, :command) do # @return [Boolean] whether the command succeeded (exit 0). def ok? exit_code.zero? end # @return [String] stdout with trailing newlines trimmed — the common case. def text stdout.sub(/\n+\z/, "") end # @return [Object] stdout parsed as JSON. def json require "json" JSON.parse(stdout) end # @return [Array<String>] non-empty stdout lines. def lines stdout.split("\n").reject(&:empty?) end # @raise [CommandFailed] if the command exited non-zero. # @return [self] def throw_if_failed! unless ok? raise CommandFailed.new( exit_code: exit_code, stdout: stdout, stderr: stderr, command: command ) end self end end |
#stderr ⇒ String (readonly)
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/bsdkrun/types.rb', line 166 Result = Data.define(:stdout, :stderr, :exit_code, :command) do # @return [Boolean] whether the command succeeded (exit 0). def ok? exit_code.zero? end # @return [String] stdout with trailing newlines trimmed — the common case. def text stdout.sub(/\n+\z/, "") end # @return [Object] stdout parsed as JSON. def json require "json" JSON.parse(stdout) end # @return [Array<String>] non-empty stdout lines. def lines stdout.split("\n").reject(&:empty?) end # @raise [CommandFailed] if the command exited non-zero. # @return [self] def throw_if_failed! unless ok? raise CommandFailed.new( exit_code: exit_code, stdout: stdout, stderr: stderr, command: command ) end self end end |
#stdout ⇒ String (readonly)
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/bsdkrun/types.rb', line 166 Result = Data.define(:stdout, :stderr, :exit_code, :command) do # @return [Boolean] whether the command succeeded (exit 0). def ok? exit_code.zero? end # @return [String] stdout with trailing newlines trimmed — the common case. def text stdout.sub(/\n+\z/, "") end # @return [Object] stdout parsed as JSON. def json require "json" JSON.parse(stdout) end # @return [Array<String>] non-empty stdout lines. def lines stdout.split("\n").reject(&:empty?) end # @raise [CommandFailed] if the command exited non-zero. # @return [self] def throw_if_failed! unless ok? raise CommandFailed.new( exit_code: exit_code, stdout: stdout, stderr: stderr, command: command ) end self end end |
Instance Method Details
#json ⇒ Object
Returns stdout parsed as JSON.
178 179 180 181 |
# File 'lib/bsdkrun/types.rb', line 178 def json require "json" JSON.parse(stdout) end |
#lines ⇒ Array<String>
Returns non-empty stdout lines.
184 185 186 |
# File 'lib/bsdkrun/types.rb', line 184 def lines stdout.split("\n").reject(&:empty?) end |
#ok? ⇒ Boolean
Returns whether the command succeeded (exit 0).
168 169 170 |
# File 'lib/bsdkrun/types.rb', line 168 def ok? exit_code.zero? end |
#text ⇒ String
Returns stdout with trailing newlines trimmed — the common case.
173 174 175 |
# File 'lib/bsdkrun/types.rb', line 173 def text stdout.sub(/\n+\z/, "") end |
#throw_if_failed! ⇒ self
190 191 192 193 194 195 196 197 |
# File 'lib/bsdkrun/types.rb', line 190 def throw_if_failed! unless ok? raise CommandFailed.new( exit_code: exit_code, stdout: stdout, stderr: stderr, command: command ) end self end |