bin/parserver in biodiversity-3.2.1 vs bin/parserver in biodiversity-3.3.0

- old
+ new

@@ -2,15 +2,17 @@ require 'optparse' require 'socket' require 'biodiversity' DEFAULT_PORT = 4334 +DEFAULT_HOST = "127.0.0.1" RUBY_VERSION_INT = RUBY_VERSION.split('.')[0..1].join('').to_i OPTIONS = { output: 'json', canonical_with_rank: false, - port: DEFAULT_PORT + port: DEFAULT_PORT, + host: DEFAULT_HOST } options = {} ARGV.options do |opts| script_name = File.basename($0) @@ -31,10 +33,16 @@ canonical - canonical form only', 'Default: json') { |output| options[:output] = output } opts.separator '' + opts.on('-H', '--host=host', String, + 'Specifies host as "127.0.0.1", "localhost" etc.', + "Default: #{DEFAULT_HOST}") { |host| options[:host] = host } + + opts.separator '' + opts.on('-p', '--port=port', String, 'Specifies the port number', "Default: #{DEFAULT_PORT}") { |port| options[:port] = port } opts.separator '' @@ -44,10 +52,11 @@ opts.parse! end OPTIONS[:output] = options[:output] if ['canonical'].include?(options[:output]) +OPTIONS[:host] = options[:host] if options[:host] OPTIONS[:port] = options[:port].to_i if options[:port].to_i > 0 OPTIONS[:canonical_with_rank] = !!options[:canonical_with_rank] def get_output(name_string, parser) name_string.chop! @@ -59,15 +68,15 @@ output = OPTIONS[:output] return parsed.to_json if output == 'json' parsed[:scientificName][:canonical].to_s end -puts "Running parser service on port %s, output type is '%s'" % - [OPTIONS[:port], OPTIONS[:output]] +puts "Running parser service on %{host}:%{port}, output type is '%{output}'" % + OPTIONS opts = {} opts = {canonical_with_rank: true} if OPTIONS[:canonical_with_rank] parser = ScientificNameParser.new(opts) -server = TCPServer.open(OPTIONS[:port]) # Socket to listen on a port +server = TCPServer.open(OPTIONS[:host], OPTIONS[:port]) # Socket to listen on a port loop do # Servers run forever Thread.start(server.accept) do |client| puts 'opening client' count = 0 while a = client.readline rescue nil