Module: Everywhere::Shellout
- Defined in:
- lib/everywhere/shellout.rb
Overview
All external commands (tebako, cargo, the app's own bin/dev) run outside this gem's bundle — they have their own gem environments.
Class Method Summary collapse
-
.capture(*cmd) ⇒ Object
Run a command and capture its combined stdout+stderr.
- .run!(env, *cmd, chdir: Dir.pwd) ⇒ Object
- .run?(*cmd) ⇒ Boolean
-
.run_logged!(env, cmd, log:) ⇒ Object
Run a command streaming to the console while also capturing to a log file.
- .spawn(env, cmd, chdir:) ⇒ Object
- .unbundled(&block) ⇒ Object
Class Method Details
.capture(*cmd) ⇒ Object
Run a command and capture its combined stdout+stderr. Returns [output_string, Process::Status]. For probing tool output (codesign, stapler, notarytool) rather than driving a build.
27 28 29 30 31 32 |
# File 'lib/everywhere/shellout.rb', line 27 def capture(*cmd) require "open3" unbundled { Open3.capture2e(*cmd) } rescue Errno::ENOENT ["", nil] end |
.run!(env, *cmd, chdir: Dir.pwd) ⇒ Object
15 16 17 18 |
# File 'lib/everywhere/shellout.rb', line 15 def run!(env, *cmd, chdir: Dir.pwd) success = unbundled { system(env, *cmd, chdir: chdir) } UI.die!("command failed: #{cmd.join(" ")}") unless success end |
.run?(*cmd) ⇒ Boolean
20 21 22 |
# File 'lib/everywhere/shellout.rb', line 20 def run?(*cmd) unbundled { system(*cmd) } end |
.run_logged!(env, cmd, log:) ⇒ Object
Run a command streaming to the console while also capturing to a log file.
35 36 37 38 39 40 |
# File 'lib/everywhere/shellout.rb', line 35 def run_logged!(env, cmd, log:) require "shellwords" line = "#{cmd.shelljoin} 2>&1 | tee #{log.shellescape}" success = unbundled { system(env, "/bin/bash", "-o", "pipefail", "-c", line) } UI.die!("command failed: #{cmd.join(" ")} (full log: #{log})") unless success end |
.spawn(env, cmd, chdir:) ⇒ Object
42 43 44 |
# File 'lib/everywhere/shellout.rb', line 42 def spawn(env, cmd, chdir:) unbundled { Process.spawn(env, cmd, chdir: chdir) } end |
.unbundled(&block) ⇒ Object
11 12 13 |
# File 'lib/everywhere/shellout.rb', line 11 def unbundled(&block) defined?(Bundler) ? Bundler.with_unbundled_env(&block) : yield end |