Sha256: 41467606b866601e4574660f6d6eddb2b46b34882def6d85347c972ee0d86796

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Spandx
  module Cli
    module Commands
      class Pull
        def initialize(options)
          @options = options
        end

        def execute(output: $stderr)
          sync(output)
          build(output, ::Spandx::Core::Dependency::PACKAGE_MANAGERS.values.uniq)
          output.puts 'OK'
        end

        private

        def sync(output)
          Spandx.git.each_value do |db|
            with_spinner("Updating #{db.url}...", output: output) do
              db.update!
            end
          end
        end

        def build(output, sources)
          index_path = Spandx.git[:cache].root.join('.index')

          with_spinner('Rebuilding index...', output: output) do
            sources.each do |source|
              Spandx::Core::Cache
                .new(source, root: index_path)
                .rebuild_index
            end
          end
        end

        def with_spinner(message, output:)
          spinner = TTY::Spinner.new("[:spinner] #{message}", output: output)
          spinner.auto_spin
          yield
          spinner.success('(done)')
        ensure
          spinner.stop
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spandx-0.15.1 lib/spandx/cli/commands/pull.rb