Class: PVN::Command::Command

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/pvn/command/command.rb

Constant Summary collapse

@@doc_for_class =
Hash.new { |h, k| h[k] = PVN::Command::Documentation.new }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Command

Returns a new instance of Command.



68
69
70
71
72
73
74
75
76
77
# File 'lib/pvn/command/command.rb', line 68

def initialize args
  options = self.class.optset
  options.process args
  
  if options.help
    show_help
  else
    init options
  end
end

Class Method Details

.description(desc) ⇒ Object



23
24
25
# File 'lib/pvn/command/command.rb', line 23

def description desc
  getdoc.description = desc
end

.example(*ex) ⇒ Object



50
51
52
# File 'lib/pvn/command/command.rb', line 50

def example *ex
  getdoc.examples << ex
end

.getdocObject



15
16
17
# File 'lib/pvn/command/command.rb', line 15

def getdoc
  @@doc_for_class[self]
end

.matches_subcommand?(sc) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/pvn/command/command.rb', line 54

def matches_subcommand? sc
  getdoc.subcommands.include? sc
end

.options(opts) ⇒ Object

$$$ remove this:



36
37
38
# File 'lib/pvn/command/command.rb', line 36

def options opts
  getdoc.options.concat opts
end

.optsclsObject



40
41
42
# File 'lib/pvn/command/command.rb', line 40

def optscls
  getdoc.options.concat optset.options
end

.optsetObject



44
45
46
47
48
# File 'lib/pvn/command/command.rb', line 44

def optset
  optmodule = to_s.sub %r{::\w+$}, ''
  optcls = optmodule + '::OptionSet'
  optset = instance_eval optcls + '.new'
end

.subcommands(sc) ⇒ Object



19
20
21
# File 'lib/pvn/command/command.rb', line 19

def subcommands sc
  getdoc.subcommands = sc
end

.summary(smry) ⇒ Object



31
32
33
# File 'lib/pvn/command/command.rb', line 31

def summary smry
  getdoc.summary = smry
end

.usage(usg) ⇒ Object



27
28
29
# File 'lib/pvn/command/command.rb', line 27

def usage usg
  getdoc.usage = usg
end

Instance Method Details

#init(options) ⇒ Object



79
80
81
# File 'lib/pvn/command/command.rb', line 79

def init options
  raise "implement this to handle non-help options"
end

#show_helpObject



64
65
66
# File 'lib/pvn/command/command.rb', line 64

def show_help
  to_doc $stdout
end

#to_doc(io) ⇒ Object



59
60
61
62
# File 'lib/pvn/command/command.rb', line 59

def to_doc io
  doc = self.class.getdoc
  doc.write io
end