Sha256: 5e412020ce91570f1ff2656ead004128de821b061d3427c7642e526d1ff67d38

Contents?: true

Size: 1.24 KB

Versions: 11

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Spandx
  module Cli
    module Commands
      class Build
        INDEXES = {
          maven: Spandx::Java::Index,
          nuget: Spandx::Dotnet::Index,
          dotnet: Spandx::Dotnet::Index,
          pypi: Spandx::Python::Index,
        }.freeze

        def initialize(options)
          @options = options
        end

        def execute(output: $stdout)
          catalogue = Spandx::Spdx::Catalogue.from_git
          build_buckets
          indexes.each do |index|
            output.puts index.name
            index.update!(catalogue: catalogue, output: output)
          end
          output.puts 'OK'
        end

        private

        def indexes
          index = INDEXES[@options[:index]&.to_sym]

          if index.nil?
            INDEXES.values.uniq.map { |x| x.new(directory: directory) }
          else
            [index.new(directory: directory)]
          end
        end

        def directory
          @options.fetch(:directory, File.join(Dir.pwd, '.index'))
        end

        def build_buckets
          (0x00..0xFF).map { |x| x.to_s(16).rjust(2, '0').downcase }.each do |hex|
            FileUtils.mkdir_p(File.join(directory, hex))
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spandx-0.16.1 lib/spandx/cli/commands/build.rb
spandx-0.16.0 lib/spandx/cli/commands/build.rb
spandx-0.15.1 lib/spandx/cli/commands/build.rb
spandx-0.15.0 lib/spandx/cli/commands/build.rb
spandx-0.14.0 lib/spandx/cli/commands/build.rb
spandx-0.13.5 lib/spandx/cli/commands/build.rb
spandx-0.13.4 lib/spandx/cli/commands/build.rb
spandx-0.13.3 lib/spandx/cli/commands/build.rb
spandx-0.13.2 lib/spandx/cli/commands/build.rb
spandx-0.13.1 lib/spandx/cli/commands/build.rb
spandx-0.13.0 lib/spandx/cli/commands/build.rb