class TShield::Options
Options
for command line
Attributes
debug[R]
Public Class Methods
init(options = {})
click to toggle source
# File lib/tshield/options.rb, line 13 def self.init(options = {}) @instance = TShield::Options.new(options) end
instance()
click to toggle source
# File lib/tshield/options.rb, line 17 def self.instance @instance || TShield::Options.new end
new(options = {})
click to toggle source
# File lib/tshield/options.rb, line 21 def initialize(options = {}) @options = {} parse unless options[:skip_parse] end
Public Instance Methods
configuration_file()
click to toggle source
# File lib/tshield/options.rb, line 26 def configuration_file @options.fetch(:configuration_file, 'config/tshield.yml') end
port()
click to toggle source
# File lib/tshield/options.rb, line 30 def port @options.fetch(:port, 4567) end
Private Instance Methods
parse()
click to toggle source
# File lib/tshield/options.rb, line 64 def parse OptionParser.new do |opts| opts.banner = 'Usage: tshield [options]' register(opts) end.parse! end
register(opts)
click to toggle source
# File lib/tshield/options.rb, line 71 def register(opts) register_configuration(opts) register_version(opts) register_port(opts) register_help(opts) end
register_configuration(opts)
click to toggle source
# File lib/tshield/options.rb, line 43 def register_configuration(opts) opts.on('-c', '--configuration [FILE]', 'Configuration File') do |file| @options[:configuration_file] = file end end
register_help(opts)
click to toggle source
# File lib/tshield/options.rb, line 57 def register_help(opts) opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end
register_port(opts)
click to toggle source
# File lib/tshield/options.rb, line 36 def register_port(opts) opts.on('-p', '--port [PORT]', 'Sinatra port') do |port| @options[:port] = port.to_i end end
register_version(opts)
click to toggle source
# File lib/tshield/options.rb, line 50 def register_version(opts) opts.on('-v', '--version', 'Show version') do TShield.logger.info(TShield::Version.to_s) exit end end