lib/spandx/cli/commands/scan.rb in spandx-0.13.4 vs lib/spandx/cli/commands/scan.rb in spandx-0.13.5
- old
+ new
@@ -2,54 +2,52 @@
module Spandx
module Cli
module Commands
class Scan
- attr_reader :scan_path, :spinner
+ include Spandx::Core
+ attr_reader :scan_path
def initialize(scan_path, options)
@scan_path = ::Pathname.new(scan_path)
@options = options
- @spinner = options[:show_progress] ? ::Spandx::Core::Spinner.new : ::Spandx::Core::Spinner::NULL
require(options[:require]) if options[:require]
end
def execute(output: $stdout)
- report = ::Spandx::Core::Report.new
- each_file do |file|
- spinner.spin(file)
- each_dependency_from(file) do |dependency|
- spinner.spin(file)
- report.add(dependency)
+ with_printer(output) do |printer|
+ each_dependency do |dependency|
+ printer.print_line(Plugin.enhance(dependency), output)
end
end
- spinner.stop
- output.puts(format(report.to(@options[:format])))
end
private
def each_file
- Spandx::Core::PathTraversal
+ PathTraversal
.new(scan_path, recursive: @options[:recursive])
.each { |file| yield file }
end
- def each_dependency_from(file)
- ::Spandx::Core::Parser
- .parse(file)
- .map { |x| enhance(x) }
- .each { |dependency| yield dependency }
+ def each_dependency
+ each_file do |file|
+ Parser.parse(file).each do |dependency|
+ yield dependency
+ end
+ end
end
def format(output)
Array(output).map(&:to_s)
end
- def enhance(dependency)
- ::Spandx::Core::Plugin
- .all
- .inject(dependency) { |memo, plugin| plugin.enhance(memo) }
+ def with_printer(output)
+ printer = ::Spandx::Cli::Printer.for(@options[:format])
+ printer.print_header(output)
+ yield printer
+ ensure
+ printer.print_footer(output)
end
end
end
end
end