Class: VersionTracker::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/version_tracker/command_line.rb

Defined Under Namespace

Modules: COMMANDS, RESULT_STATUS

Constant Summary collapse

VALID_COMMANDS =
%w(init bump read tag)
VALID_PARTS =
%w(major minor patch)
DEFAULT_PART =
'patch'
DEFAULT_COMMIT_MESSAGE =
'Set Version to'

Instance Method Summary collapse

Constructor Details

#initializeCommandLine

Returns a new instance of CommandLine.



29
30
31
# File 'lib/version_tracker/command_line.rb', line 29

def initialize
  @version_tracker = VersionTracker::Bumper.new
end

Instance Method Details

#execute(args = [], options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/version_tracker/command_line.rb', line 34

def execute args = [], options = {}
  command = args[0] || COMMANDS::READ
  raise VersionTrackerError, 'Invalid command' unless VALID_COMMANDS.include?(command)

  @options = options.merge(:argument => args[1])


  result =
    case command
    when COMMANDS::INIT
      @version_tracker.init @options[:argument]
      @version_tracker.version
    when COMMANDS::READ
      @version_tracker.version
    when COMMANDS::TAG
      self.git_tag
      "Successfully created tag for #{@version_tracker.version}"
    when COMMANDS::BUMP
      self.bump
      @version_tracker.version
    end

  self.release if !!@options[:release]
  self.push if !!@options[:push] && !@options[:release]

  [result, RESULT_STATUS::SUCCESS]
rescue VersionTrackerError => e
  return [e.message, RESULT_STATUS::ERROR]
end