Module: Spoom::Context::Exec
- Included in:
- Spoom::Context
- Defined in:
- lib/spoom/context/exec.rb
Overview
Execution features for a context @requires_ancestor: Context
Instance Method Summary collapse
-
#exec(command, capture_err: true) ⇒ Object
Run a command in this context directory : (String command, ?capture_err: bool) -> ExecResult.
Instance Method Details
#exec(command, capture_err: true) ⇒ Object
Run a command in this context directory : (String command, ?capture_err: bool) -> ExecResult
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/spoom/context/exec.rb', line 31 def exec(command, capture_err: true) Bundler.with_unbundled_env do opts = { chdir: absolute_path } #: Hash[Symbol, untyped] # When Ruby is wrapped in another dev environment (e.g. Nix), that environment might set # env variables that cause Sorbet (or other tools) to link to incorrect versions of # dependencies. # # In the case of Sorbet, this can lead to corrupted JSON output. # # Executing the command directly through the shell bypasses any Ruby wrappers and # ensures that we are using the versions of tools that are default on the system. command_with_shell = "/bin/sh -c #{command.shellescape}" if capture_err out, err, status = Open3.capture3(command_with_shell, opts) ExecResult.new(out: out, err: err, status: T.must(status.success?), exit_code: T.must(status.exitstatus)) else out, status = Open3.capture2(command_with_shell, opts) ExecResult.new(out: out, err: nil, status: T.must(status.success?), exit_code: T.must(status.exitstatus)) end end end |