lib/spandx/cli/commands/scan.rb in spandx-0.11.0 vs lib/spandx/cli/commands/scan.rb in spandx-0.12.0

- old
+ new

@@ -1,26 +1,27 @@ # frozen_string_literal: true module Spandx module Cli module Commands - class Scan < Spandx::Cli::Command + class Scan attr_reader :scan_path def initialize(scan_path, options) @scan_path = ::Pathname.new(scan_path) @options = options + require(options[:require]) if options[:require] end def execute(output: $stdout) report = ::Spandx::Core::Report.new each_file_in(scan_path) do |file| each_dependency_from(file) do |dependency| report.add(dependency) end end - output.puts report.to(@options[:format]) + output.puts(format(report.to(@options[:format]))) end private def recursive? @@ -31,19 +32,33 @@ files = File.directory?(dir) ? Dir.glob(File.join(dir, '*')) : [dir] files.each do |file| if File.directory?(file) each_file_in(file, &block) if recursive? else + Spandx.logger.debug(file) block.call(file) end end end def each_dependency_from(file) ::Spandx::Core::Parser .for(file) .parse(file) + .map { |dependency| enhance(dependency) } .each { |dependency| yield dependency } + rescue StandardError => error + Spandx.logger.error(error) + end + + def format(output) + Array(output).map(&:to_s) + end + + def enhance(dependency) + ::Spandx::Core::Plugin + .all + .inject(dependency) { |memo, plugin| plugin.enhance(memo) } end end end end end