diff options
Diffstat (limited to 'lib/license/management/shell.rb')
| -rw-r--r-- | lib/license/management/shell.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/license/management/shell.rb b/lib/license/management/shell.rb new file mode 100644 index 0000000..903d0b6 --- /dev/null +++ b/lib/license/management/shell.rb @@ -0,0 +1,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 |
