Sha256: c2ed75edc64477d486e4513587bc06accb5aed53cf6c29e89ac949dd7c88fd3c

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

#!/usr/bin/env ruby

require 'optparse'
require 'fileutils'
require 'erb'
gem_base=File.expand_path(File.dirname(__FILE__)+"/..")
require gem_base+"/lib/distribution"

new=false
parameters=""
OptionParser.new do |opts|
  opts.banner="Usage: distribution [--new] [--params parameters] distribution"
  opts.on("-n", "--new", "Create a new template for distribution") do
    new=true
  end
  opts.on("-PMANDATORY", "--params MANDATORY", String, "Parameters for distribution") do |n_param|
    parameters=", #{n_param}"
  end
  
  opts.on("-h", "--help", "Show this message") do
    puts opts
    exit
  end

  begin
    ARGV << "-h" if ARGV.empty?
    opts.parse!(ARGV)
  rescue OptionParser::ParseError => e
    STDERR.puts e.message, "\n", opts
    exit(-1)
  end
end

ARGV.each do |distribution|
  if new
    basename=distribution.downcase
    raise "You should be inside distribution lib directory" unless File.exists? "../distribution.rb"
    raise "Distribution already created" if File.exists? basename+".rb"
    main=ERB.new(File.read(gem_base+"/data/template/distribution.erb"))
    ruby=ERB.new(File.read(gem_base+"/data/template/distribution/ruby.erb"))
    gsl=ERB.new(File.read(gem_base+"/data/template/distribution/gsl.erb"))
    spec=ERB.new(File.read(gem_base+"/data/template/spec.erb"))
    
    FileUtils.mkdir(basename) unless File.exists? basename
    File.open(basename+".rb","w") {|fp| fp.write(main.result(binding))}
    File.open(basename+"/ruby.rb","w") {|fp| fp.write(ruby.result(binding))}
    File.open(basename+"/gsl.rb","w") {|fp| fp.write(gsl.result(binding))}
    File.open("../../spec/#{basename}_spec.rb","w") {|fp| fp.write(spec.result(binding))}
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
distribution-0.7.3 bin/distribution
distribution-0.7.2 bin/distribution
distribution-0.7.1 bin/distribution