Class: Looks::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/looks/command/base.rb

Direct Known Subclasses

AccountManagement, Config, Pull

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
# File 'lib/looks/command/base.rb', line 12

def initialize(config)
  @opts   = OptionParser.new
  @config = config

  configure(@opts)
  set_banner
  set_version
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#run(args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/looks/command/base.rb', line 21

def run(args)
  begin
    @opts.parse! args
  rescue OptionParser::ParseError => e
    raise Error, e
  end

  usage unless args.length == arguments.length

  execute(args)
end

#to_sObject



37
38
39
# File 'lib/looks/command/base.rb', line 37

def to_s
  "#{@opts.help}\n"
end

#usageObject



33
34
35
# File 'lib/looks/command/base.rb', line 33

def usage
  abort to_s
end