Sha256: 2955374e9822a9d892c4bdcf3d776f8ac08f3671384a52386776304f0be4450c

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

# typed: true
# frozen_string_literal: true

require "benchmark"

module Packwerk
  module Formatters
    class ProgressFormatter
      extend T::Sig

      sig { params(out: T.any(StringIO, IO), style: OutputStyle).void }
      def initialize(out, style: OutputStyles::Plain.new)
        @out = out
        @style = style
      end

      def started(target_files)
        files_size = target_files.size
        files_string = Inflector.default.pluralize("file", files_size)
        @out.puts("📦 Packwerk is inspecting #{files_size} #{files_string}")
      end

      def started_validation
        @out.puts("📦 Packwerk is running validation...")

        execution_time = Benchmark.realtime { yield }
        finished(execution_time)

        @out.puts("✅ Packages are valid. Use `packwerk check` to run static checks.")
      end

      def mark_as_inspected
        @out.print(".")
      end

      def mark_as_failed
        @out.print("#{@style.error}E#{@style.reset}")
      end

      def finished(execution_time)
        @out.puts
        @out.puts("📦 Finished in #{execution_time.round(2)} seconds")
      end

      def interrupted
        @out.puts
        @out.puts("Manually interrupted. Violations caught so far are listed below:")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
packwerk-1.4.0 lib/packwerk/formatters/progress_formatter.rb
packwerk-1.3.2 lib/packwerk/formatters/progress_formatter.rb
packwerk-1.3.1 lib/packwerk/formatters/progress_formatter.rb
packwerk-1.3.0 lib/packwerk/formatters/progress_formatter.rb
packwerk-1.2.0 lib/packwerk/formatters/progress_formatter.rb