Sha256: dddb62a634486ee5ef321757f245f421e2c037a796e322e47a3f913e0408bc4f

Contents?: true

Size: 945 Bytes

Versions: 7

Compression:

Stored size: 945 Bytes

Contents

require 'optparse'
module Mirage
  module Util
    
    def wait_until time=30
      start_time = Time.now
      until Time.now >= start_time + time
        sleep 0.1
        return if yield
      end
      raise 'timeout waiting'
    end

    def parse_options args
      options = {:port => 7001, :defaults_directory => 'responses', :root_directory => '.'}

      opt_parser = OptionParser.new do |opts|
        opts.banner = "Usage: mirage start|stop [options]"
        opts.on("-p", "--port PORT", "the port to start Mirage on") do |port|
          options[:port] = port.to_i
        end

        opts.on("-d", "--defaults DIR", "location to load default responses from") do |directory|
          options[:defaults_directory] = directory
        end
      end

      begin
        opt_parser.parse args
      rescue
        puts "mirage start|stop [OPTIONS]"
        puts opt_parser
        exit 1
      end

      options
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mirage-1.1.0 lib/mirage/util.rb
mirage-1.0.2 lib/mirage/util.rb
mirage-1.0.1 lib/mirage/util.rb
mirage-1.0.0 lib/mirage/util.rb
mirage-0.1.7 lib/mirage/util.rb
mirage-0.1.6 lib/mirage/util.rb
mirage-0.1.5 lib/mirage/util.rb