Class: ExtremeFeedbackDevice::CLI
- Inherits:
-
Object
- Object
- ExtremeFeedbackDevice::CLI
- 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
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#pid_file ⇒ Object
readonly
Returns the value of attribute pid_file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #main ⇒ Object
- #mode ⇒ Object
- #namespace ⇒ Object
- #pid ⇒ Object
- #settings ⇒ Object
Constructor Details
#initialize ⇒ CLI
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
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
17 18 19 |
# File 'lib/extreme_feedback_device/cli.rb', line 17 def opts @opts end |
#pid_file ⇒ Object (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
.instance ⇒ Object
12 13 14 |
# File 'lib/extreme_feedback_device/cli.rb', line 12 def instance @instance ||= new end |
Instance Method Details
#main ⇒ Object
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.(pid_dir), pidfile: pid_name) ExtremeFeedbackDevice::Settings.source(File.(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 |
#mode ⇒ Object
30 31 32 |
# File 'lib/extreme_feedback_device/cli.rb', line 30 def mode @mode || DEFAULT_MODE end |
#namespace ⇒ Object
34 35 36 |
# File 'lib/extreme_feedback_device/cli.rb', line 34 def namespace @namespace || DEFAULT_NAMESPACE end |
#pid ⇒ Object
38 39 40 |
# File 'lib/extreme_feedback_device/cli.rb', line 38 def pid @pid || DEFAULT_PID # File.expand_path(@pid || DEFAULT_PID) end |
#settings ⇒ Object
42 43 44 |
# File 'lib/extreme_feedback_device/cli.rb', line 42 def settings @settings || DEFAULT_SETTINGS # File.expand_path(@settings || DEFAULT_SETTINGS) end |