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:, filter: nil) ⇒ Object
Run a command, capturing its full combined output to a log file while showing a (optionally filtered) view on the console.
- .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:, filter: nil) ⇒ Object
Run a command, capturing its full combined output to a log file while showing a (optionally filtered) view on the console.
Pass filter: a LogFilter (or any #call(line) -> String | :drop | nil) to prettify what a human sees; the on-disk log always gets the raw stream, so nothing is lost. Unrecognized lines (filter returns nil) are shown dimmed and indented so they read as background detail under the current step.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/everywhere/shellout.rb', line 41 def run_logged!(env, cmd, log:, filter: nil) require "open3" success = false unbundled do File.open(log, "w") do |logf| Open3.popen2e(env, *cmd) do |stdin, out, wait| stdin.close out.each_line do |raw| logf.write(raw) emit(raw, filter) end success = wait.value.success? end end end UI.die!("command failed: #{cmd.join(" ")} (full log: #{log})") unless success end |
.spawn(env, cmd, chdir:) ⇒ Object
73 74 75 |
# File 'lib/everywhere/shellout.rb', line 73 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 |