Sha256: 96d219d754ade12d5dc798c9c35106239fd70f6f79d8ce4e53db4f5ca1bb36ab

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'optparse'
require 'ostruct'

module GitBumper
  # This is the parser for CLI arguments.
  class CLIParser
    attr_reader :options

    # @param argv [Array<String>]
    def initialize(argv)
      @argv = argv
      @parser = OptionParser.new
      @options = { klass: GitBumper::Tag,
                   prefix: 'v',
                   increment: :patch }
    end

    def parse
      @parser.banner = 'Usage: git bump [options]'

      @parser
        .on('-b', '--build', 'Use build tags') do
          options[:klass] = GitBumper::BuildTag
        end
        .on('-p', '--prefix [PREFIX]', 'Set a prefix') do |prefix|
          options[:prefix] = prefix
        end
        .on('--major', 'Increments the major version') do
          options[:increment] = :major
        end
        .on('--minor', 'Increments the minor version') do
          options[:increment] = :minor
        end
        .on('-h', '--help', 'Prints this help') do
          puts @parser
          return false
        end

      @parser.parse!(@argv)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git_bumper-0.1.4 lib/git_bumper/cli_parser.rb
git_bumper-0.1.3 lib/git_bumper/cli_parser.rb
git_bumper-0.1.2 lib/git_bumper/cli_parser.rb