class Gitvers::CLI
Public Class Methods
new()
click to toggle source
# File lib/gitvers/cli.rb, line 5 def initialize command = ARGV.shift.to_sym rescue nil rep = Repository.new(Dir.pwd) begin case command when :bump rep.bump(ARGV.shift) when :init if rep.versions.count > 0 puts "Repository already have a git tag #{rep.full_version}" else initial = ask("Please enter the initial version in the form X.Y.Z: ") rep.tag(initial) end when :show what = ARGV.shift case what when 'full' puts rep.full_version when 'short' puts rep.short_version when 'revision' puts rep.revision_number when 'shell' opts = ARGV.shift(2) export = opts.include?('export') noprefix = opts.include?('noprefix') v = [rep.revision_number, rep.full_version, rep.short_version] k = %w(GITVERS_REVISION GITVERS_FULL GITVERS_SHORT) k = %w(REVISION_NUMBER FULL_VERSION SHORT_VERSION) if noprefix v.each_with_index do |val, i| print 'export ' if export puts "#{k[i]}=#{val}" end when 'lines' puts rep.revision_number puts rep.full_version puts rep.short_version else puts "Current version: #{rep.summary}\n\n" puts "All versions:" puts rep.versions.map {|l| " #{l}"} end else usage end rescue NoVersionError puts "No git tag, use `gitvers init` to create one." rescue InvalidVersionError => e puts e.message end end
Public Instance Methods
usage()
click to toggle source
# File lib/gitvers/cli.rb, line 62 def usage puts %|usage: gitvers <command> [<args>] Commands: init Create an initial git tag bump <step> Bump the version, step can be major, minor or patch bump <version> Bump the version to a specific destination version show [<what>] Display the current version 'What' can be: - full # x.y.z-commit - short # x.y.z - revision # revision - shell # output GITVERS_<name> variables # supports two options - export # prefix lines with export - noprefix # do not prefix lines with GITVERS_ - lines # output 3 lines with revision, full, short respectively Examples: gitvers bump major gitvers bump 1.3.4 | end