Class: Bumpversion::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/bumpversion/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(options, arguments = nil) ⇒ Parser

Returns a new instance of Parser.



6
7
8
9
# File 'lib/bumpversion/parser.rb', line 6

def initialize(options, arguments = nil)
  @args = arguments || ARGV
  @options = options
end

Instance Method Details

#mount_bannerObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bumpversion/parser.rb', line 11

def mount_banner
  version_number = VERSION
  Optimist::Parser.new do
    version "Bumpversion #{version_number}"
    usage "bumpversion [options] --part [major|minor|patch]
    where [options] are:"

    banner <<-EOS
#{version}

Usage:
#{usage}
    EOS

    opt :help, 'Show this help!'
    opt :part, 'The part of the version to increase, [major, minor, patch]', default: 'minor'
    opt :file, 'The file that will be modified can be multi-files separated by comma.
      Example: VERSION, GEMNAME.gemspec, version.rb', default: 'VERSION', type: :string
    opt :config_file, 'The file contains config this program', default: '.bumpversion.cfg', type: :string
    opt :current_version, 'The current version of the software package before bumping ', type: :string
    opt :new_version, 'The version of the software package after the increment. \
    If not given will be automatically determined.', required: false, type: :string

    opt :git_commit, 'Whether to create a commit using Git.', required: false, default: false, type: :boolean
    opt :git_tag, 'Whether to create a tag, that is the new version, prefixed with the character "v". If you are using git',
        required: false, default: false, type: :boolean
    opt :git_push, 'Pushes Tags and Commit to origin Git', reuired: false, default: false, type: :boolean
    opt :git_user, 'Name from User to Create Commit', required: false, default: "Auto Bump", type: :string
    opt :git_email, 'Email from User to Create Email', required: false, default: "[email protected]", type: :string
    opt :git_extra_add, 'Extra files to add in git commit', required: false, default: "", type: :string

    opt :pre_commit_hooks, 'Call sh commands before commits after Bumpversion separated by ;',
        required: false, type: :string
    opt :pos_commit_hooks, 'Call sh commands after commits separated by ;',
        required: false, type: :string
  end
end

#parseObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bumpversion/parser.rb', line 49

def parse
  banner = mount_banner
  @options = Optimist.with_standard_exception_handling banner do
    fail Optimist::HelpNeeded if @args.empty?
    banner.parse @args
  end

  Optimist.die if @options[:help]

  @options
end