Class: KBuilder::Watch::Cli

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/k_builder/watch/cli.rb

Overview

Command line interface for starting the watcher

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCli

Returns a new instance of Cli.



19
20
21
22
23
# File 'lib/k_builder/watch/cli.rb', line 19

def initialize
  @opts = KBuilder::Watch::CliOptions.new

  process_arguments
end

Instance Attribute Details

#optsObject

Returns the value of attribute opts.



15
16
17
# File 'lib/k_builder/watch/cli.rb', line 15

def opts
  @opts
end

Class Method Details

.parse_optionsObject



25
26
27
# File 'lib/k_builder/watch/cli.rb', line 25

def self.parse_options
  new.opts
end

Instance Method Details

#optionsObject



36
37
38
39
40
41
42
# File 'lib/k_builder/watch/cli.rb', line 36

def options
  GetoptLong.new(
    ['--help' , '-h', GetoptLong::NO_ARGUMENT],
    ['--debug' , GetoptLong::NO_ARGUMENT],
    ['--new' , '-n', GetoptLong::OPTIONAL_ARGUMENT]
  )
end

#parse_argumentsObject



44
45
46
47
48
49
# File 'lib/k_builder/watch/cli.rb', line 44

def parse_arguments
  options.each do |opt, arg|
    # Arguments like -nKafeOwner and -n KafeOwner should both become 'KafeOwner'
    parse_option(opt, arg.strip)
  end
end

#process_argumentsObject



29
30
31
32
33
34
# File 'lib/k_builder/watch/cli.rb', line 29

def process_arguments
  parse_arguments

  set_watch_path_arg
  set_watch_path
end

#to_hObject



51
52
53
# File 'lib/k_builder/watch/cli.rb', line 51

def to_h
  @opts.to_h
end