Sha256: dcf48b3510a0e37f4eb12b13e7e009b1c9ad3e73b635f4c2e92ccd16e4024874

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

#!/usr/bin/env ruby

require 'scrimp'
require 'optparse'

options = {:port => 7000,
           :thrift_command => 'thrift'}
parser = OptionParser.new do |op|
  op.banner = 'Usage: scrimp FOLDER... [OPTIONS]'
  op.on '-p', '--port PORT', 'port to launch UI server on' do |port|
    options[:port] = port.to_i
  end
  op.on '-t', '--thrift-command COMMAND', 'thrift compiler' do |cmd|
    options[:thrift_command] = cmd
  end
  op.on '-h', '--help' do
    puts parser
    exit 0
  end
end

begin
  parser.parse!
  raise 'need arguments' if ARGV.empty?
rescue
  puts parser
  exit 0
end

Dir.mktmpdir do |out|
  files = ARGV.map {|dir| Dir["#{dir}/**/*.thrift"]}.flatten
  folders = files.map {|file| File.dirname(File.expand_path(file))}.uniq
  include_directives = folders.map {|dir| "-I #{dir}"}.join(' ')
  files.each do |file|
    puts (cmd = "#{options[:thrift_command]} --gen rb -out #{out} #{include_directives} #{file}")
    puts `#{cmd}`
  end
  $LOAD_PATH.unshift out
  Dir["#{out}/*.rb"].each {|file| require file}
  $LOAD_PATH.delete out
end

Scrimp::ThriftUtil.extend_structs
Scrimp::App.run! :port => options[:port]

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scrimp-1.0.0 bin/scrimp