Class: XscreenUsbUnlocker::OptionParser
- Inherits:
-
OptionParser
- Object
- OptionParser
- XscreenUsbUnlocker::OptionParser
- Defined in:
- lib/xscreen_usb_unlocker/optparser.rb
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
-
#bool_on(word, description = "") ⇒ Object
This will build an on/off option with a default value set to false.
-
#initialize ⇒ OptionParser
constructor
A new instance of OptionParser.
- #parse! ⇒ Object
Constructor Details
#initialize ⇒ OptionParser
Returns a new instance of OptionParser.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/xscreen_usb_unlocker/optparser.rb', line 5 def initialize super @options = {} on("-V", "--version", "Print version") { |version| @options[:version] = true} on("-p", "--pry", "open a pry shell.") { |pry| @options[:pry] = true} if App.plugins.include? 'logging' on("-l", "--log-level LEVEL", "Change the log level, default is debug.") { |level| Log.level level } on("--log-file FILE", "What file to output to, default is STDOUT") { |file| Log.filename file } end end |
Instance Method Details
#[](k) ⇒ Object
41 42 43 |
# File 'lib/xscreen_usb_unlocker/optparser.rb', line 41 def [](k) @options[k] end |
#[]=(k, v) ⇒ Object
45 46 47 |
# File 'lib/xscreen_usb_unlocker/optparser.rb', line 45 def []=(k,v) @options[k] = v end |
#bool_on(word, description = "") ⇒ Object
This will build an on/off option with a default value set to false.
17 18 19 20 21 22 |
# File 'lib/xscreen_usb_unlocker/optparser.rb', line 17 def bool_on(word, description = "") Options[word.to_sym] = false on "-#{word.chars.first}", "--[no]#{word}", description do |o| Options[word.to_sym] == o end end |
#parse! ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xscreen_usb_unlocker/optparser.rb', line 24 def parse! super if @options[:version] puts XscreenUsbUnlocker::VERSION exit 0 end # we need to mash in our config array. To do this we want to make config # options that don't overwrite cli options. if App.plugins.include? 'config' Config.each do |k,v| @options[k] = v if !@options[k] end end end |