Sha256: 1b49e5e23027844ffaa08d6db1b9350606ec84dc64862c0e7bbf62f571ad9868

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true
module Gistory
  module Cli
    class Main
      def initialize(repo_path:, args:, io: Gistory::Cli::Io.new)
        @repo_path = repo_path
        @args = args
        @io = io
      end

      def run
        repo = GitRepo.new(path: @repo_path)
        parser = Cli::ArgParser.new(args: @args, io: @io)
        config = parser.parse
        history(repo, config.gem_name)
      rescue Gistory::ParserError => error
        @io.error error.message
        @io.puts parser
      rescue Gistory::Error => error
        @io.error error.message
      end

      private

      def history(repo, gem_name)
        changes = ChangeLog.new(repo: repo).changelog_for_gem(gem_name)

        if changes.empty?
          raise(Gistory::Error, "Gem '#{gem_name}' not found in lock file, maybe a typo?")
        end

        @io.puts "Gem: #{gem_name}"
        @io.puts "Current version: #{changes.first.version}"
        @io.puts ''

        @io.puts 'Change history:'
        changes.each do |change|
          @io.puts "#{change.version} on #{change.date.strftime('%a, %e %b %Y %H:%M %Z')} (commit #{change.short_hash})"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gistory-0.1.3 lib/gistory/cli/main.rb
gistory-0.1.2 lib/gistory/cli/main.rb
gistory-0.1.1 lib/gistory/cli/main.rb
gistory-0.1.0 lib/gistory/cli/main.rb