Class: Lapine::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



5
6
7
8
# File 'lib/lapine/cli.rb', line 5

def initialize(argv)
  @argv = argv
  @command = argv.shift
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



3
4
5
# File 'lib/lapine/cli.rb', line 3

def argv
  @argv
end

#commandObject (readonly)

Returns the value of attribute command.



3
4
5
# File 'lib/lapine/cli.rb', line 3

def command
  @command
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
# File 'lib/lapine/cli.rb', line 10

def run
  case command
  when 'consume'
    require 'lapine/consumer'
    ::Lapine::Consumer::Runner.new(argv).run
  else
    usage
  end
end

#usageObject



20
21
22
23
24
25
26
27
# File 'lib/lapine/cli.rb', line 20

def usage
  puts <<-EOF.gsub(/^ {8}/, '')
    Usage: lapine [command] [options]

      commands: consume
  EOF
  exit 1
end