Sha256: 13d7ce761e7ea455d4d06e64fb6200beae272694e3265d96750786e764e94e00

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module GitBumper
  # This class receives a Hash of options parsed by CLIParser and executes the
  # requested action.
  class CLI
    attr_reader :error_msg

    # @param [Hash]
    def initialize(options)
      @options = options
      @error = false
      @error_msg = ''
    end

    def run
      Git.fetch_tags

      old_tag = greatest_tag
      return error('No tags found.') unless old_tag

      new_tag = old_tag.clone
      new_tag.increment(@options.fetch(:increment))

      puts "The old tag is      #{old_tag}"
      puts "The new tag will be #{new_tag}"
      puts 'Push to origin? (Y/n)'

      return error('Aborted.') unless prompt_yes

      Git.create_tag(new_tag)
      Git.push_tag(new_tag)
    end

    def error?
      @error
    end

    private

    def error(msg)
      @error = true
      @error_msg = msg
    end

    def prompt_yes
      input = STDIN.gets.chomp.to_s
      input.empty? || input =~ /\Ay(es)?\z/i
    end

    def greatest_tag
      Git.greatest_tag(klass: @options.fetch(:klass),
                       prefix: @options.fetch(:prefix))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git_bumper-0.1.4 lib/git_bumper/cli.rb
git_bumper-0.1.3 lib/git_bumper/cli.rb