summaryrefslogtreecommitdiff
path: root/lib/license/management/shell.rb
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-03-27 21:34:09 -0600
committermo khan <mo.khan@gmail.com>2020-03-30 22:28:07 -0600
commit67e1de7e57a843622a824f68e4ffb40d8b9ff320 (patch)
tree92e14683798648106e573555ed4a97658dfb7122 /lib/license/management/shell.rb
parentd0ff10b6ae1075a13827e00dd0120fac9639fde8 (diff)
Use virtualenv, pip-licenses to scan projects
* Add PIL License to list of normalized licenses * Update Python 3 v2.0 report fixture * Add CHANGELOG entry * Define local variables in bash functions * Ensure `SETUP_CMD` continues to work for python projects * build virtualenv app-data cache * Fallback to legacy scanner when SETUP_CMD is used * Extract Shell class to be able to pass custom env
Diffstat (limited to 'lib/license/management/shell.rb')
-rw-r--r--lib/license/management/shell.rb34
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