blob: 903d0b6898c117093ae237a9dcbfb384294a3bed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# frozen_string_literal: true
module License
module Management
class Shell
attr_reader :logger
def initialize(logger: License::Management.logger)
@logger = logger
end
def execute(command, env: {})
expanded_command = expand(command)
logger.debug(expanded_command)
stdout, stderr, status = Open3.capture3(env, expanded_command)
logger.debug(stdout) unless stdout.nil? || stdout.empty?
logger.error(stderr) unless stderr.nil? || stderr.empty?
[stdout, stderr, status]
end
def sh(command, env: {})
execute("sh -c '#{expand(command)}'", env: env)
end
private
def expand(command)
Array(command).map(&:to_s).join(' ')
end
end
end
end
|