53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/rook/main.rb', line 53
def execute
options = @options
properties = @properties
products = @products
$rook_debug = true if @options[?D] $KCODE = @options[?k] if @options[?k]
if @options[?h] || @options[?v]
cmdname = File.basename($0)
desc = "#{cmdname} - a SCM (Software Cooking Management) tool like Make, Rake, Ant, or Cook.\n"
puts version() if @options[?v]
puts desc if @options[?h]
puts help() if @options[?h]
return
end
@options[?r].split(/,/).each { |lib| require lib } if @options[?r]
bookname = @options[?f] || @options[?b]
if bookname
test(?f, bookname) or raise _error("cookbook '#{bookname}' not found.")
else
['.yaml', '.yml', '.rb', ''].each do |suffix|
break if test(?f, bookname = "Rookbook#{suffix}")
break if test(?f, bookname = "rookbook#{suffix}")
bookname = nil
end
bookname or raise _error("cookbook 'Rookbook.yaml' or 'Rookbook.rb' not found.")
end
propfile = @options[?P]
if propfile
test(?f, propfile) or raise _error("file '#{propfile}' not found.")
else
%w[Rookbook.props properties.yaml].each do |f|
break propfile = f if test(?f, f)
end
end
if propfile
props = YAML.load_file(propfile)
props.each do |k, v|
@properties[k] = v unless @properties.key?(k)
end
end
$rook_verbose = @options[?V] ? true : (@options[?q] ? false : nil)
$rook_forced = @options[?F]
$rook_noexec = @options[?n] ? 1 : (@options[?N] ? 2 : nil)
style = bookname =~ /\.ya?ml\z/ ? :yaml : :ruby
if style == :yaml
flag_expand_tab = !options[?T]
begin
cookbook = Cookbook.new(bookname, true, flag_expand_tab)
rescue CookbookError => ex
$stderr.puts "validation error:"
ex.errors.each do |error|
e = error
$stderr.puts "#{bookname}:#{e.linenum}: [#{e.path}] #{e.message}"
end
return
end
end
if @options[?c]
style == :yaml or raise _error("-c: cannot check Ruby-DSL style cookbook.")
cookbook.validate_rubycode()
return
end
props = { :verbose=>$rook_verbose, :forced=>$rook_forced, :noexec=>$rook_noexec }
kitchen = Kitchen.new(@properties, props)
if style == :yaml
kitchen.load_book(cookbook)
else
kitchen.load_script(bookname)
end
if @options[?l] || @options[?L]
show_all = @options[?L] ? true : false
list_properties(kitchen, show_all)
puts
list_recipes(kitchen, @options[?L])
return
end
if @options[?p]
@options[?p].split(/,/).each do |name|
if kitchen.has_parameter?(name)
pp kitchen.get_parameter(name)
elsif kitchen.has_property?(name)
pp kitchen.get_property(name)
else
raise _error("-p #{name}: no such parameter or property.")
end
end
return
end
if @products && !@products.empty?
products = @products
elsif kitchen.find_specific_recipe(:default)
products = [ :default ]
elsif prod = kitchen.get_parameter('rook_product')
products = [ prod ]
elsif prod = kitchen.get_property('rook_product')
products = [ prod ]
else
$stderr.puts "*** no product specified."
list_recipes(kitchen)
return
end
products.each do |product|
product = product.sub(/\A:/, '').intern if product.is_a?(String) && product[0] == ?:
kitchen.start_cooking(product)
end
return nil
end
|