Class: Smith::CommandBase

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/smith/command_base.rb

Defined Under Namespace

Classes: UnkownCommandError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

included

Constructor Details

#initializeCommandBase

Returns a new instance of CommandBase.



13
14
15
16
# File 'lib/smith/command_base.rb', line 13

def initialize
  @parser = Trollop::Parser.new
  options_spec
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/smith/command_base.rb', line 9

def options
  @options
end

#targetObject (readonly)

Returns the value of attribute target.



9
10
11
# File 'lib/smith/command_base.rb', line 9

def target
  @target
end

Instance Method Details



31
32
33
34
35
36
37
38
# File 'lib/smith/command_base.rb', line 31

def banner(banner=nil, opts={})
  if banner.nil?
    @banner
  else
    @banner = banner
    @parser.banner((opts[:no_template]) ? banner : banner_template(banner))
  end
end

#format_help(opts = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/smith/command_base.rb', line 23

def format_help(opts={})
  StringIO.new.tap do |help|
    help.puts opts[:prefix] if opts[:prefix]
    @parser.educate(help)
    help.rewind
  end.read
end

#parse_options(args) ⇒ Object



18
19
20
21
# File 'lib/smith/command_base.rb', line 18

def parse_options(args)
  @options = @parser.parse(args)
  @target = args
end