Sha256: 921b904ac04a6dfd042345dd6f006486f556f9477117bce1ab06a343d84356c7

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'yaml'
require 'optparse'

module Temp

  class Runner

    attr_reader :conf_file, :conf, :args

    def initialize(options = {})
      @conf_file = File.expand_path(options[:conf_file])
      @conf = { :template_dir => '~/.temp' }
      @args = options[:args] || {}

      if @conf_file && File.file?(@conf_file)
        @conf = YAML::load_file(@conf_file)
      else
        File.open(@conf_file, 'w') { |f| f.write(@conf.to_yaml) }
      end
    end

    def start!
      OptionParser.new do |o|
        o.banner = 'Usage: temp [options] [project] [template]'

        o.on('-v', '--version', 'Show version information') do
          puts "Temp #{Temp::VERSION}"
        end
      end.parse!(@args)

      c = Temp::Copier.new(:template_dir => @conf[:template_dir])
      if ARGV.size == 0
        raise 'no project directory or template name specified'
      elsif ARGV.size == 1
        c.create_project(ARGV[0])
      else
        c.create_project(ARGV[0], ARGV[1])
      end
    rescue => e
      puts e.message
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
temp-0.0.2 lib/temp/runner.rb