groundwork 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/groundwork +12 -5
- data/lib/recipe.rb +71 -55
- data/lib/recipe_class.rb +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/bin/groundwork
CHANGED
@@ -3,13 +3,20 @@
|
|
3
3
|
require File.join(File.dirname(__FILE__),"..","lib","groundwork.rb")
|
4
4
|
|
5
5
|
begin
|
6
|
-
|
6
|
+
options = Groundwork::parse_options
|
7
7
|
|
8
|
-
|
8
|
+
raise RuntimeError.new("No command given; use \"groundwork -h\" for help") unless options[:command]
|
9
9
|
|
10
|
-
|
10
|
+
command_file = File.join(File.dirname(__FILE__),"..","commands",options[:command]+".rb")
|
11
11
|
|
12
|
-
|
12
|
+
if File.exists? command_file
|
13
|
+
load command_file
|
14
|
+
Groundwork::Commands.send options[:command], options[:remainder]
|
15
|
+
elsif Groundwork.known_recipes[options[:command]]
|
16
|
+
Groundwork::Recipe.run Groundwork.known_recipes[options[:command]]
|
17
|
+
else
|
18
|
+
raise RuntimeError.new("#{options[:command]} is neither a command nor a recipe name; use \"groundwork -h\" for help")
|
19
|
+
end
|
13
20
|
rescue
|
14
|
-
|
21
|
+
puts $!.to_s
|
15
22
|
end
|
data/lib/recipe.rb
CHANGED
@@ -1,65 +1,81 @@
|
|
1
1
|
module Groundwork
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
class Recipe
|
3
|
+
def initialize args=[], &block
|
4
|
+
@args = args
|
5
|
+
@name = args[0]
|
6
|
+
if block_given?
|
7
|
+
instance_eval &block
|
8
|
+
end
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
def tar= data
|
12
|
+
@tar = TarWrapper.new(data)
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
def options &block
|
16
|
+
opts = Trollop::options(@args) do
|
17
|
+
self.instance_eval &block
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.each do |name, val|
|
21
|
+
instance_variable_set "@#{name}", val
|
22
|
+
end
|
23
|
+
|
24
|
+
@name = @args[0]
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
elsif opts.is_a? Hash
|
33
|
-
file.print( if opts[:from]
|
34
|
-
read_file opts[:from]
|
35
|
-
elsif opts[:from_erb]
|
36
|
-
ERB.new(read_file(opts[:from_erb])).result(binding)
|
37
|
-
elsif opts[:erb]
|
38
|
-
ERB.new(opts[:erb]).result(binding)
|
39
|
-
end )
|
40
|
-
elsif opts.nil?
|
41
|
-
# write nothing
|
42
|
-
else
|
43
|
-
raise ArgumentError.new
|
26
|
+
opts
|
27
|
+
end
|
28
|
+
|
29
|
+
# Creates a directory. If a block is passed,
|
30
|
+
# the block will be run inside that directory
|
31
|
+
def directory *name, &block
|
32
|
+
FileUtils.mkdir_p File.join(name)
|
33
|
+
if block_given?
|
34
|
+
FileUtils.cd File.join(name), &block
|
35
|
+
end
|
44
36
|
end
|
45
|
-
end
|
46
|
-
end
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
38
|
+
# If opts is a string, it's the contents of the file, verbatim
|
39
|
+
# If opts is a hash, it must contain either:
|
40
|
+
# * :from, copies the text of the given filename verbatim
|
41
|
+
# * :from_erb, uses the text of the filename as an erb template
|
42
|
+
# * :erb, uses the given string as an erb template
|
43
|
+
def file name, opts = nil
|
44
|
+
name = File.join(name)
|
45
|
+
File.open(File.join(name),"w") do |file|
|
46
|
+
if opts.is_a? String
|
47
|
+
file.print opts
|
48
|
+
elsif opts.is_a? Hash
|
49
|
+
file.print( if opts[:from]
|
50
|
+
read_file opts[:from]
|
51
|
+
elsif opts[:from_erb]
|
52
|
+
ERB.new(read_file(opts[:from_erb])).result(binding)
|
53
|
+
elsif opts[:erb]
|
54
|
+
ERB.new(opts[:erb]).result(binding)
|
55
|
+
end )
|
56
|
+
elsif opts.nil?
|
57
|
+
# write nothing
|
58
|
+
else
|
59
|
+
raise ArgumentError.new
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# When you compile a recipe, it runs it to determine which files to bake in.
|
65
|
+
# If you have a file that might not be generated by running your script with
|
66
|
+
# no options, you can call possible on it to ensure it gets baked into
|
67
|
+
# the script. This function only has an effect during compilation, it does
|
68
|
+
# nothing when the script is actually run.
|
69
|
+
def possible name ; end
|
54
70
|
|
55
|
-
|
71
|
+
private
|
56
72
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
73
|
+
def read_file name
|
74
|
+
if @tar
|
75
|
+
@tar[name]
|
76
|
+
else
|
77
|
+
File.read(name)
|
78
|
+
end
|
79
|
+
end
|
63
80
|
end
|
64
|
-
end
|
65
81
|
end
|
data/lib/recipe_class.rb
CHANGED