Class: VCLog::CLI::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/vclog/cli/abstract.rb

Overview

Abstract base class for all command classes.

Direct Known Subclasses

Autotag, Bump, Formats, Log, News, Version

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAbstract

Returns a new instance of Abstract.



40
41
42
# File 'lib/vclog/cli/abstract.rb', line 40

def initialize
  @options = {}
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



86
87
88
# File 'lib/vclog/cli/abstract.rb', line 86

def arguments
  @arguments
end

Class Method Details

.inherited(subclass) ⇒ Object



30
31
32
# File 'lib/vclog/cli/abstract.rb', line 30

def self.inherited(subclass)
  CLI.register << subclass
end

.run(argv) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/vclog/cli/abstract.rb', line 18

def self.run(argv)
  new.run(argv)
rescue => err
  if $DEBUG
    raise err
  else
    puts err.message
    exit -1
  end
end

.termsObject



35
36
37
# File 'lib/vclog/cli/abstract.rb', line 35

def self.terms
  [name.split('::').last.downcase]
end

Instance Method Details

#optionsObject



45
46
47
# File 'lib/vclog/cli/abstract.rb', line 45

def options
  @options
end

#parser(&block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vclog/cli/abstract.rb', line 50

def parser(&block)
  parser = OptionParser.new(&block)

  parser.separator " "
  parser.separator "SYSTEM OPTIONS:"
  parser.on('--debug', 'show debugging information') do
    $DEBUG = true
  end
  parser.on('--help' , '-h', 'display this help information') do
    puts parser
    exit
  end
  parser
end

#repoObject

Repo is set in #run.



81
82
83
# File 'lib/vclog/cli/abstract.rb', line 81

def repo
  @repo
end

#run(argv = nil) ⇒ Object

Run the command.



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/vclog/cli/abstract.rb', line 66

def run(argv=nil)
  argv ||= ARGV.dup

  parser.parse!(argv)

  @arguments = argv

  root  = Dir.pwd  # TODO: find root

  @repo = VCLog::Repo.new(root, options)

  execute
end