bin/simulate in log_simulator-0.0.7 vs bin/simulate in log_simulator-0.1.0

- old
+ new

@@ -1,28 +1,51 @@ #!/usr/bin/env ruby require 'optparse' -require 'log_simulator' +require 'peak_log_simulator' +require 'resolve' +require 'socket_connetion' -timescale = 1.0 +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| - timescale = time + options[:timescale] = time end opts.on_tail('-h', '--help', 'Show this message') { puts opts; exit } end opts.parse!(ARGV) -filepath = ARGV.pop(ARGV.count)[0] -if filepath - LogSimulator::PlusLogSimulator.start(filepath,timescale) -else - puts opts.help - exit 1 +# 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