Class: GitBumper::CLIParser

Inherits:
Object
  • Object
show all
Defined in:
lib/git_bumper/cli_parser.rb

Overview

This is the parser for CLI arguments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLIParser

Returns a new instance of CLIParser.

Parameters:

  • argv (Array<String>)


10
11
12
13
14
15
16
# File 'lib/git_bumper/cli_parser.rb', line 10

def initialize(argv)
  @argv = argv
  @parser = OptionParser.new
  @options = { klass: GitBumper::Tag,
               prefix: 'v',
               increment: :patch }
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/git_bumper/cli_parser.rb', line 7

def options
  @options
end

Instance Method Details

#parseObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/git_bumper/cli_parser.rb', line 18

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