Sha256: 8ac34ae93ddef900d7f3375ca58a2c2a88fde826430225036e8839b107dbd563

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

#!/usr/bin/ruby

require File.join(File.dirname(__FILE__),"..","lib","groundwork.rb")

begin
  options = Groundwork::parse_options

  case options[:command]
  when "generate"
    generate_opts = Trollop::options(options[:remainder]) do
      banner <<-STR
Usage:
      groundwork generate [options] filename
Generates a basic recipe, which you can modify, from the current directory
[options] are:
STR
      opt :force, "Overwrite recipe file if exists", :default=>false
      opt :ignore, "Ignore files matching these filename patterns", :type=>:strings
      opt :print, "Instead of storing in a file, print the recipe to stdout", :default=>false
      opt :chdir, "Before running, cd to the given directory", :default=>FileUtils.pwd
    end

    recipe = ""
    FileUtils.cd(generate_opts[:chdir]) do
      recipe = Groundwork::Recipe.generate FileUtils.pwd, :ignore => generate_opts[:ignore]
    end

    if generate_opts[:print]
      puts recipe
    else
      name = options[:remainder].shift || "Recipe"

      if File.exists?(name+".recipe") && !generate_opts[:force]
        raise RuntimeError.new("File already exists: #{name}.recipe")
      end

      File.open(name+".recipe","w"){|f| f.print recipe}
    end
  else
  end
rescue
  puts $!.to_s
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
groundwork-0.0.2 bin/groundwork