Skip to content

Commit

Permalink
allow passing env to CommandRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Oct 15, 2024
1 parent 71e5f0a commit 060e2b8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/foreman_maintain/utils/command_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ class CommandRunner
attr_reader :logger, :command

def initialize(logger, command, options)
options.validate_options!(:stdin, :hidden_patterns, :interactive, :valid_exit_statuses)
options.validate_options!(:stdin, :hidden_patterns, :interactive, :valid_exit_statuses,
:env)
options[:valid_exit_statuses] ||= [0]
options[:env] ||= {}
@logger = logger
@command = command
@stdin = options[:stdin]
@hidden_patterns = Array(options[:hidden_patterns]).compact
@interactive = options[:interactive]
@options = options
@valid_exit_statuses = options[:valid_exit_statuses]
@env = options[:env]
raise ArgumentError, 'Can not pass stdin for interactive command' if @interactive && @stdin
end

Expand Down Expand Up @@ -81,7 +84,7 @@ def run_interactively
end

def run_non_interactively
IO.popen(full_command, 'r+') do |f|
IO.popen(@env, full_command, 'r+') do |f|
if @stdin
f.puts(@stdin)
f.close_write
Expand Down

0 comments on commit 060e2b8

Please sign in to comment.