bin/globetrotter in globetrotter-0.0.5 vs bin/globetrotter in globetrotter-0.0.6
- old
+ new
@@ -1,52 +1,53 @@
#!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), %w{.. lib})
require 'globetrotter'
-require 'trollop'
+require 'optparse'
+require 'ostruct'
+require 'dnsruby'
-opts = Trollop.options do
- opt :ns_count_to_check,
- 'How many nameservers to query',
- type: Integer,
- default: 100,
- short: '-c'
- opt :ns_max_age_minutes,
- 'Query nameservers validated <= this many minutes ago',
- type: Integer,
- default: 60,
- short: '-a'
- opt :query,
- 'Hostname to lookup',
- type: String,
- default: 'googleapis.com'
- opt :timeout_seconds,
- 'Seconds to wait before queries timeout',
- type: Integer,
- default: 2,
- short: '-t'
- opt :concurrency,
- 'Number of concurrent DNS requests to make',
- type: Integer,
- default: 10,
- short: '-p'
-end
+class GlobetrotterOptions
+ def self.parse(args)
+ options = OpenStruct.new
+ options.domain = 'googleapis.com'
+ options.ns_count_to_check = 100
+ options.ns_max_age_minutes = 60
+ options.timeout_seconds = 2
+ options.ns_query_concurrency = 10
-ns_count_to_check = opts.ns_count_to_check
-ns_max_age_minutes = opts.ns_max_age_minutes
-timeout_seconds = opts.timeout_seconds
-concurrency = opts.concurrency
-query = opts.query
+ opt_parser = OptionParser.new do |opts|
+ opts.banner = 'Usage: globetrotter [options] example.org'
+ opts.on('-q googleapis.com', String, 'Domain to look up') do |o|
+ options.domain = o
+ end
+ opts.on('-n 100', Integer, 'Query N name servers') do |o|
+ options.ns_count_to_check = o
+ end
+ opts.on('-t 2', Integer, 'Wait T seconds per request') do |o|
+ options.timeout_seconds = o
+ end
+ opts.on('-p 10', Integer, 'Query P name servers in parallel') do |o|
+ options.ns_query_concurrency = o
+ end
+ opts.on('-a 60', Integer, 'Use name servers checked less than A minutes ago') do |o|
+ options.ns_max_age_minutes = o
+ end
+ opts.on_tail('-h', '--help', 'Display CLI help (this output)') do |o|
+ puts opts.help
+ exit
+ end
+ opts.on_tail('-v', '--version', 'Display Globetrotter version') do |o|
+ puts "Globetrotter #{Globetrotter::VERSION}"
+ exit
+ end
+ end # opt_parser
-Trollop.die :ns_count_to_check, 'must be positive' if ns_count_to_check < 0
-Trollop.die :ns_max_age_minutes, 'must be positive' if ns_max_age_minutes < 0
-Trollop.die :timeout_seconds, 'must be positive' if ns_max_age_minutes < 0
-Trollop.die :concurrency, 'must be positive' if ns_max_age_minutes < 0
+ opt_parser.parse!(args)
-gt = Globetrotter.new(
- query: query,
- ns_count_to_check: ns_count_to_check,
- ns_max_age_minutes: ns_max_age_minutes,
- timeout_seconds: timeout_seconds,
- concurrency: concurrency
-)
+ options
+ end # parse()
+end # class Globetrotter Options
+
+options = GlobetrotterOptions.parse(ARGV)
+gt = Globetrotter.new(options)
gt.run