Class: Caterer::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Vli::Util::SafePuts
Defined in:
lib/caterer/command/base.rb

Direct Known Subclasses

Berks, Server

Instance Method Summary collapse

Constructor Details

#initialize(argv, env) ⇒ Base

Returns a new instance of Base.



10
11
12
13
# File 'lib/caterer/command/base.rb', line 10

def initialize(argv, env)
  @argv   = argv
  @env    = env
end

Instance Method Details

#executeObject



15
# File 'lib/caterer/command/base.rb', line 15

def execute; end

#parse_options(opts = nil, force_argv = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/caterer/command/base.rb', line 17

def parse_options(opts=nil, force_argv=false)
  argv = @argv.dup
  opts ||= OptionParser.new

  opts.on_tail("-h", "--help", "Print this help") do
    safe_puts(opts.help)
    return nil
  end

  begin
    opts.parse!(argv)
    raise if force_argv and (not argv or argv.length == 0)
    argv
  rescue
    safe_puts(opts.help)
    nil
  end

end