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 CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -3,13 +3,20 @@
3
3
  require File.join(File.dirname(__FILE__),"..","lib","groundwork.rb")
4
4
 
5
5
  begin
6
- options = Groundwork::parse_options
6
+ options = Groundwork::parse_options
7
7
 
8
- raise RuntimeError.new("No command given; use \"groundwork -h\" for help") unless options[:command]
8
+ raise RuntimeError.new("No command given; use \"groundwork -h\" for help") unless options[:command]
9
9
 
10
- load File.join(File.dirname(__FILE__),"..","commands",options[:command]+".rb")
10
+ command_file = File.join(File.dirname(__FILE__),"..","commands",options[:command]+".rb")
11
11
 
12
- Groundwork::Commands.send options[:command], options[:remainder]
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
- puts $!.to_s
21
+ puts $!.to_s
15
22
  end
@@ -1,65 +1,81 @@
1
1
  module Groundwork
2
- class Recipe
3
- def initialize &block
4
- if block_given?
5
- instance_eval &block
6
- end
7
- end
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
- def tar= data
10
- @tar = TarWrapper.new(data)
11
- end
11
+ def tar= data
12
+ @tar = TarWrapper.new(data)
13
+ end
12
14
 
13
- # Creates a directory. If a block is passed,
14
- # the block will be run inside that directory
15
- def directory *name, &block
16
- FileUtils.mkdir_p File.join(name)
17
- if block_given?
18
- FileUtils.cd File.join(name), &block
19
- end
20
- end
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
- # If opts is a string, it's the contents of the file, verbatim
23
- # If opts is a hash, it must contain either:
24
- # * :from, copies the text of the given filename verbatim
25
- # * :from_erb, uses the text of the filename as an erb template
26
- # * :erb, uses the given string as an erb template
27
- def file name, opts = nil
28
- name = File.join(name)
29
- File.open(File.join(name),"w") do |file|
30
- if opts.is_a? String
31
- file.print opts
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
- # When you compile a recipe, it runs it to determine which files to bake in.
49
- # If you have a file that might not be generated by running your script with
50
- # no options, you can call possible on it to ensure it gets baked into
51
- # the script. This function only has an effect during compilation, it does
52
- # nothing when the script is actually run.
53
- def possible name ; end
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
- private
71
+ private
56
72
 
57
- def read_file name
58
- if @tar
59
- @tar[name]
60
- else
61
- File.read(name)
62
- end
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
@@ -66,7 +66,7 @@ module Groundwork
66
66
  (script, data) = File.read(script_file).split("\n__END__\n")
67
67
 
68
68
  Groundwork::Recipe.new do
69
- self.tar = data
69
+ self.tar = data if data
70
70
  eval script
71
71
  end
72
72
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrews, Ross