Sha256: 0493d036db05ae15c01f3793a0122054776208ad44ce0514de176faf1eb3b7f8

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

#!/usr/bin/env ruby

require 'log_simulator/version'
require 'optparse'
require 'peak_log_simulator'
require 'resolve'
require 'socket_connetion'

options={:filepath => nil ,:timescale => 1.0, :pretty => false}

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('-p','--pretty','Pretty Log Messages') do
    options[:pretty] = true
  end

  opts.on('-v','--version','Version') {puts LogSimulator::VERSION; exit}

  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|
  puts "Connection to #{target.name} - #{target.target_name} :#{target.port}"
  socket_connection = LogSimulator::SocketConnetion.new(target.target_name,target.port)

  unless options[:filepath].nil?
    LogSimulator::PeakLogSimulator.start(socket_connection.socket,options[:filepath],options[:timescale],options[:pretty]) 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
log_simulator-0.2.1 bin/simulate
log_simulator-0.2.0 bin/simulate