Skip to content

Commit 7119806

Browse files
committed
expose ability to run commands in display environment
1 parent c0c3ce3 commit 7119806

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/arduino_ci/display_manager.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,28 @@ def with_display
8181
end
8282
end
8383

84+
# run a command in a display
85+
def run(*args, **kwargs)
86+
ret = false
87+
# do some work to extract & merge environment variables if they exist
88+
has_env = !args.empty? && args[0].class == Hash
89+
with_display do |env_vars|
90+
env_vars = {} if env_vars.nil?
91+
env_vars.merge!(args[0]) if has_env
92+
actual_args = has_env ? args[1..-1] : args # need to shift over if we extracted args
93+
full_cmd = env_vars.empty? ? actual_args : [env_vars] + actual_args
94+
95+
puts "Running #{env_vars} $ #{args.join(' ')}"
96+
ret = system(*full_cmd, **kwargs)
97+
end
98+
ret
99+
end
100+
101+
# run a command in a display with no output
102+
def run_silent(*args)
103+
run(*args, out: File::NULL, err: File::NULL)
104+
end
105+
84106
def environment
85107
return nil unless @existing || @enabled
86108
return {} if @existing

0 commit comments

Comments
 (0)