require 'optparse' def parse_options(argv) options = { verbose: false, relays: nil, jetstreams: nil } parser = OptionParser.new do |opts| opts.banner = "Usage: #{$PROGRAM_NAME} [options]" opts.on('-d', '--duration SECONDS', Integer, 'Duration of the test in seconds') do |seconds| options[:duration] = seconds end opts.on('-r', '--relays HOSTS', 'Only connect to these relays; can be comma-separated or passed multiple times') do |hosts| options[:relays] ||= [] options[:relays] += hosts.split(',').map(&:strip).reject(&:empty?) end opts.on('-j', '--jetstreams HOSTS', 'Only connect to these jetstreams; can be comma-separated or passed multiple times') do |hosts| options[:jetstreams] ||= [] options[:jetstreams] += hosts.split(',').map(&:strip).reject(&:empty?) end opts.on('-v', '--verbose', 'Report the statistics to stdout during the test') do options[:verbose] = true end opts.on('-h', '--help', 'Show help') do puts opts exit 0 end end parser.parse!(argv) options rescue OptionParser::ParseError => e warn e.message warn parser exit 1 end