#!/usr/bin/env ruby require 'optparse' require 'peak_log_simulator' require 'resolve' require 'socket_connetion' options={:filepath => nil ,:timescale => 1.0} opts = OptionParser.new do |opts| opts.banner = "Usage: simulate [logfile path] [options]" opts.on('-t time',Float,'timescale. Default is 1.0') do |time| options[:timescale] = time end opts.on_tail('-h', '--help', 'Show this message') { puts opts; exit } end opts.parse!(ARGV) # empty option set # if STDIN.tty? # puts opts.help # exit 1 # end unless ARGV.empty? options[:filepath] = ARGV.pop(ARGV.count)[0] end LogSimulator::Resolver.select_target(2.0) do |target| socket_connection = LogSimulator::SocketConnetion.new(target.target_name,target.port) unless options[:filepath].nil? LogSimulator::PeakLogSimulator.start(socket_connection.socket,options[:filepath],options[:timescale]) do |success| while true #TODO: make it DRY print '>' message = gets.chomp socket_connection.socket.puts message end end else while true print '>' message = gets.chomp socket_connection.socket.puts message end end end