Class: Kubetailrb::OptsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/kubetailrb/opts_parser.rb

Overview

Parse CLI arguments and flags. NOTE: We could use the standard library optparse (OptionParser) or a more comprehensive tool like Thor to achieve this, but that would defeat the purpose of learning by implementing it ourselves.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ OptsParser

Returns a new instance of OptsParser.



14
15
16
# File 'lib/kubetailrb/opts_parser.rb', line 14

def initialize(*args)
  @args = *args
end

Instance Method Details

#parseObject



18
19
20
21
22
23
24
25
26
# File 'lib/kubetailrb/opts_parser.rb', line 18

def parse
  return Cmd::Help.new if Cmd::Help.applicable?(*@args)

  return Cmd::Version.new if Cmd::Version.applicable?(*@args)

  return Cmd::File.create(*@args) if Cmd::File.applicable?(*@args)

  Cmd::K8s.create(*@args)
end