Class: ExtremeFeedbackDevice::CLI

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

Constant Summary collapse

DEFAULT_MODE =
'run'
DEFAULT_NAMESPACE =
'default'
DEFAULT_PID =
'~/.extreme_feedback_device.pid'
DEFAULT_SETTINGS =
'~/.extreme_feedback_device.yml'

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
24
25
26
27
28
# File 'lib/extreme_feedback_device/cli.rb', line 19

def initialize
  @opts = ::GetoptLong.new(
    [ '--help', '-h', ::GetoptLong::NO_ARGUMENT ],
    [ '--mode', '-m', ::GetoptLong::REQUIRED_ARGUMENT ],
    [ '--namespace', '-n', ::GetoptLong::REQUIRED_ARGUMENT ],
    [ '--pid', '-p', ::GetoptLong::REQUIRED_ARGUMENT ],
    [ '--settings', '-s', ::GetoptLong::REQUIRED_ARGUMENT ],
    [ '--version', '-v', ::GetoptLong::NO_ARGUMENT ]
  )
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



17
18
19
# File 'lib/extreme_feedback_device/cli.rb', line 17

def opts
  @opts
end

#pid_fileObject (readonly)

Returns the value of attribute pid_file.



17
18
19
# File 'lib/extreme_feedback_device/cli.rb', line 17

def pid_file
  @pid_file
end

Class Method Details

.instanceObject



12
13
14
# File 'lib/extreme_feedback_device/cli.rb', line 12

def instance
  @instance ||= new
end

Instance Method Details

#mainObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/extreme_feedback_device/cli.rb', line 46

def main
  parse_opts!

  if argv.length > 0
    puts_help
    exit -1
  else
    @pid_file = PidFile.new(piddir: File.expand_path(pid_dir), pidfile: pid_name)

    ExtremeFeedbackDevice::Settings.source(File.expand_path(settings))
    ExtremeFeedbackDevice::Settings.namespace(namespace)
    ExtremeFeedbackDevice::Settings.reload!

    if mode =~ /^run$/i
      ExtremeFeedbackDevice.run
      exit 0
    elsif mode =~ /^loop$/i
      ExtremeFeedbackDevice.infinite_loop
      exit 0
    else
      puts_help
      exit -1
    end
  end
end

#modeObject



30
31
32
# File 'lib/extreme_feedback_device/cli.rb', line 30

def mode
  @mode || DEFAULT_MODE
end

#namespaceObject



34
35
36
# File 'lib/extreme_feedback_device/cli.rb', line 34

def namespace
  @namespace || DEFAULT_NAMESPACE
end

#pidObject



38
39
40
# File 'lib/extreme_feedback_device/cli.rb', line 38

def pid
  @pid || DEFAULT_PID # File.expand_path(@pid || DEFAULT_PID)
end

#settingsObject



42
43
44
# File 'lib/extreme_feedback_device/cli.rb', line 42

def settings
  @settings || DEFAULT_SETTINGS # File.expand_path(@settings || DEFAULT_SETTINGS)
end