Sha256: 0979102e3b806ce35bf18657f9672cac312963e2ac8a2cc691d060d534d50d66

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Spandx
  module Cli
    module Commands
      class Scan
        include Spandx::Core
        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)
          with_printer(output) do |printer|
            each_dependency do |dependency|
              printer.print_line(Plugin.enhance(dependency), output)
            end
          end
        end

        private

        def each_file
          PathTraversal
            .new(scan_path, recursive: @options[:recursive])
            .each { |file| yield file }
        end

        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 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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spandx-0.18.1 lib/spandx/cli/commands/scan.rb
spandx-0.18.0 lib/spandx/cli/commands/scan.rb
spandx-0.17.0 lib/spandx/cli/commands/scan.rb
spandx-0.16.1 lib/spandx/cli/commands/scan.rb
spandx-0.16.0 lib/spandx/cli/commands/scan.rb
spandx-0.15.1 lib/spandx/cli/commands/scan.rb
spandx-0.15.0 lib/spandx/cli/commands/scan.rb
spandx-0.14.0 lib/spandx/cli/commands/scan.rb
spandx-0.13.5 lib/spandx/cli/commands/scan.rb