groundwork 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/groundwork CHANGED
@@ -8,17 +8,34 @@ begin
8
8
  case options[:command]
9
9
  when "generate"
10
10
  generate_opts = Trollop::options(options[:remainder]) do
11
- opt :force, :default=>false
11
+ banner <<-STR
12
+ Usage:
13
+ groundwork generate [options] filename
14
+ Generates a basic recipe, which you can modify, from the current directory
15
+ [options] are:
16
+ STR
17
+ opt :force, "Overwrite recipe file if exists", :default=>false
18
+ opt :ignore, "Ignore files matching these filename patterns", :type=>:strings
19
+ opt :print, "Instead of storing in a file, print the recipe to stdout", :default=>false
20
+ opt :chdir, "Before running, cd to the given directory", :default=>FileUtils.pwd
12
21
  end
13
22
 
14
- name = options[:remainder].shift || "Recipe"
15
-
16
- if File.exists?(name+".recipe") && !generate_opts[:force]
17
- raise RuntimeError.new("File already exists: #{name}.recipe")
23
+ recipe = ""
24
+ FileUtils.cd(generate_opts[:chdir]) do
25
+ recipe = Groundwork::Recipe.generate FileUtils.pwd, :ignore => generate_opts[:ignore]
18
26
  end
19
27
 
20
- recipe = Groundwork::Recipe.generate
21
- File.open(name+".recipe","w"){|f| f.print recipe}
28
+ if generate_opts[:print]
29
+ puts recipe
30
+ else
31
+ name = options[:remainder].shift || "Recipe"
32
+
33
+ if File.exists?(name+".recipe") && !generate_opts[:force]
34
+ raise RuntimeError.new("File already exists: #{name}.recipe")
35
+ end
36
+
37
+ File.open(name+".recipe","w"){|f| f.print recipe}
38
+ end
22
39
  else
23
40
  end
24
41
  rescue
data/lib/groundwork.rb CHANGED
@@ -132,12 +132,17 @@ module Groundwork
132
132
 
133
133
  # Generate a tree of file and directory calls that would create the given
134
134
  # directory
135
- def self.generate dir = FileUtils.pwd
135
+ def self.generate dir = FileUtils.pwd, options = {}
136
136
  base = Pathname.new dir
137
137
 
138
138
  handle_dir = lambda do |d, output, indent|
139
139
  FileUtils.cd d do
140
140
  Dir["*"].each do |file|
141
+ rel = Pathname.new(File.join(FileUtils.pwd,file))
142
+ relpath = rel.relative_path_from(base).to_s
143
+
144
+ next if options[:ignore] && options[:ignore].any?{|p| File.fnmatch(p,relpath) }
145
+
141
146
  if File.directory? file
142
147
  if Dir[File.join(file,"*")].empty?
143
148
  output.puts((" "*indent)+"directory \"#{file}\"")
@@ -149,8 +154,6 @@ module Groundwork
149
154
  output.puts("")
150
155
  end
151
156
  else
152
- rel = Pathname.new(File.join(FileUtils.pwd,file))
153
- relpath = rel.relative_path_from(base).to_s
154
157
  output.puts((" "*indent)+"file \"#{file}\", :from => \"#{relpath}\"")
155
158
  end
156
159
  end
data/lib/options.rb CHANGED
@@ -3,8 +3,13 @@ require "abbrev"
3
3
  module Groundwork
4
4
  def self.parse_options opts=ARGV
5
5
  global_opts = Trollop::options(opts) do
6
- banner "Groundwork"
7
- version "0.0.1"
6
+ banner <<-STR
7
+ Usage:
8
+ groundwork [global_options] command [command_options]
9
+ Currently, the only implemented command is "generate", which generates a recipe for the current directory
10
+ Options are:
11
+ STR
12
+ version "0.0.2"
8
13
  stop_on_unknown
9
14
  end
10
15
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrews, Ross