Class: WiFiddler::CLI::ArgumentParser
- Inherits:
-
Object
- Object
- WiFiddler::CLI::ArgumentParser
- Defined in:
- lib/wifiddler.rb
Defined Under Namespace
Classes: InvalidOption
Constant Summary collapse
- DEFAULT_OPTIONS =
{ device_id: "en0", interval: 10, attempts: 100, timeout: 10 * 60, verbose: false }
Instance Method Summary collapse
Instance Method Details
#parse(arguments) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/wifiddler.rb', line 104 def parse(arguments) = DEFAULT_OPTIONS.dup optparse = OptionParser.new do |opts| opts. = <<-BANNER.gsub(/^\s{4}/, '') Cycle airport off & on until there is a connection Usage: wifiddler [options] Example: yourkarma --verbose BANNER opts.on('-i', '--interval=INTERVAL', "Seconds to wait after first cycle (default: #{DEFAULT_OPTIONS[:interval]})", Float) do |interval| [:interval] = interval end opts.on('-t', '--timeout=TIMEOUT', "Seconds to wait before exiting (default: #{DEFAULT_OPTIONS[:timeout]})", Float) do |timeout| [:timeout] = timeout end opts.on('-a', '--attempts=attempts', "Number of cycle attempts (default: #{DEFAULT_OPTIONS[:attempts]})", Integer) do |attempts| [:attempts] = attempts end opts.on('-d', '--device=DEVICE_ID', "Airport device ID (default: #{DEFAULT_OPTIONS[:device_id]})", String) do |device_id| [:device_id] = device_id end opts.on('-v', '--[no-]verbose', "Run verbosely (default: #{DEFAULT_OPTIONS[:verbose]})") do |v| [:verbose] = true end opts.on('-h', '--help', 'Display this screen') do raise InvalidOption, opts end end optparse.parse!(arguments) rescue OptionParser::InvalidOption, OptionParser::MissingArgument raise InvalidOption, optparse end |