tap 0.7.9 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/History +28 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README +71 -43
  4. data/Rakefile +81 -64
  5. data/Tutorial +235 -0
  6. data/bin/tap +80 -44
  7. data/lib/tap.rb +41 -12
  8. data/lib/tap/app.rb +243 -246
  9. data/lib/tap/file_task.rb +357 -118
  10. data/lib/tap/generator.rb +88 -29
  11. data/lib/tap/generator/generators/config/config_generator.rb +4 -2
  12. data/lib/tap/generator/generators/config/templates/config.erb +1 -2
  13. data/lib/tap/generator/generators/file_task/file_task_generator.rb +3 -18
  14. data/lib/tap/generator/generators/file_task/templates/task.erb +22 -15
  15. data/lib/tap/generator/generators/file_task/templates/test.erb +13 -2
  16. data/{test/test/inference_methods/test_assert_files_exist/input/input_1.txt → lib/tap/generator/generators/generator/USAGE} +0 -0
  17. data/lib/tap/generator/generators/generator/generator_generator.rb +21 -0
  18. data/lib/tap/generator/generators/generator/templates/generator.erb +23 -0
  19. data/lib/tap/generator/generators/generator/templates/usage.erb +1 -0
  20. data/{test/test/inference_methods/test_assert_files_exist/input/input_2.txt → lib/tap/generator/generators/package/USAGE} +0 -0
  21. data/lib/tap/generator/generators/package/package_generator.rb +38 -0
  22. data/lib/tap/generator/generators/package/templates/package.erb +186 -0
  23. data/lib/tap/generator/generators/root/root_generator.rb +14 -9
  24. data/lib/tap/generator/generators/root/templates/Rakefile +20 -14
  25. data/{test/test/inference_methods/test_infer_glob/expected/file.yml → lib/tap/generator/generators/root/templates/ReadMe.txt} +0 -0
  26. data/lib/tap/generator/generators/root/templates/tap.yml +82 -0
  27. data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +0 -1
  28. data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +2 -1
  29. data/{test/test/inference_methods/test_infer_glob/expected/file_1.txt → lib/tap/generator/generators/script/USAGE} +0 -0
  30. data/lib/tap/generator/generators/script/script_generator.rb +17 -0
  31. data/lib/tap/generator/generators/script/templates/script.erb +42 -0
  32. data/lib/tap/generator/generators/task/task_generator.rb +1 -1
  33. data/lib/tap/generator/generators/task/templates/task.erb +24 -16
  34. data/lib/tap/generator/generators/task/templates/test.erb +13 -17
  35. data/lib/tap/generator/generators/workflow/templates/task.erb +10 -10
  36. data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
  37. data/lib/tap/generator/generators/workflow/workflow_generator.rb +3 -18
  38. data/lib/tap/root.rb +108 -146
  39. data/lib/tap/script.rb +362 -0
  40. data/lib/tap/script/console.rb +28 -0
  41. data/lib/tap/script/destroy.rb +13 -1
  42. data/lib/tap/script/generate.rb +13 -1
  43. data/lib/tap/script/run.rb +100 -57
  44. data/lib/tap/support/batch_queue.rb +0 -3
  45. data/lib/tap/support/logger.rb +6 -3
  46. data/lib/tap/support/rake.rb +54 -0
  47. data/lib/tap/support/task_configuration.rb +169 -0
  48. data/lib/tap/support/tdoc.rb +198 -0
  49. data/lib/tap/support/tdoc/config_attr.rb +338 -0
  50. data/lib/tap/support/tdoc/tdoc_html_generator.rb +38 -0
  51. data/lib/tap/support/tdoc/tdoc_html_template.rb +42 -0
  52. data/lib/tap/support/versions.rb +33 -1
  53. data/lib/tap/task.rb +339 -227
  54. data/lib/tap/test.rb +86 -128
  55. data/lib/tap/test/env_vars.rb +16 -5
  56. data/lib/tap/test/file_methods.rb +373 -0
  57. data/lib/tap/test/subset_methods.rb +299 -180
  58. data/lib/tap/version.rb +2 -1
  59. data/lib/tap/workflow.rb +2 -0
  60. data/test/app/lib/app_test_task.rb +1 -0
  61. data/test/app_test.rb +327 -83
  62. data/test/check/binding_eval.rb +23 -0
  63. data/test/check/define_method_check.rb +22 -0
  64. data/test/check/dependencies_check.rb +175 -0
  65. data/test/check/inheritance_check.rb +22 -0
  66. data/test/file_task_test.rb +524 -291
  67. data/test/{test/inference_methods/test_infer_glob/expected/file_2.txt → root/glob/one.txt} +0 -0
  68. data/test/root/glob/two.txt +0 -0
  69. data/test/root_test.rb +330 -262
  70. data/test/script_test.rb +194 -0
  71. data/test/support/audit_test.rb +5 -2
  72. data/test/support/combinator_test.rb +10 -10
  73. data/test/support/rake_test.rb +35 -0
  74. data/test/support/task_configuration_test.rb +272 -0
  75. data/test/support/tdoc_test.rb +363 -0
  76. data/test/support/templater_test.rb +2 -2
  77. data/test/support/versions_test.rb +32 -0
  78. data/test/tap_test_helper.rb +39 -0
  79. data/test/task_base_test.rb +115 -0
  80. data/test/task_class_test.rb +56 -4
  81. data/test/task_execute_test.rb +29 -0
  82. data/test/task_test.rb +89 -70
  83. data/test/test/env_vars_test.rb +48 -0
  84. data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/file.txt +0 -0
  85. data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/folder/file.txt +0 -0
  86. data/test/test/{inference_methods → file_methods}/test_assert_expected/input/file.txt +0 -0
  87. data/test/test/{inference_methods → file_methods}/test_assert_expected/input/folder/file.txt +0 -0
  88. data/test/test/file_methods/test_assert_files_exist/input/input_1.txt +0 -0
  89. data/test/test/file_methods/test_assert_files_exist/input/input_2.txt +0 -0
  90. data/test/test/file_methods/test_assert_output_files_equal/expected/one.txt +1 -0
  91. data/test/test/file_methods/test_assert_output_files_equal/expected/two.txt +1 -0
  92. data/test/test/file_methods/test_assert_output_files_equal/input/one.txt +1 -0
  93. data/test/test/file_methods/test_assert_output_files_equal/input/two.txt +1 -0
  94. data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_1.txt +0 -0
  95. data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_2.txt +0 -0
  96. data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_1.txt +0 -0
  97. data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_2.txt +0 -0
  98. data/test/test/file_methods/test_infer_glob/expected/file.yml +0 -0
  99. data/test/test/file_methods/test_infer_glob/expected/file_1.txt +0 -0
  100. data/test/test/file_methods/test_infer_glob/expected/file_2.txt +0 -0
  101. data/test/test/file_methods/test_method_glob/expected/file.yml +0 -0
  102. data/test/test/file_methods/test_method_glob/expected/file_1.txt +0 -0
  103. data/test/test/file_methods/test_method_glob/expected/file_2.txt +0 -0
  104. data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_1.yml +0 -0
  105. data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_2.yml +0 -0
  106. data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_1.yml +0 -0
  107. data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_2.yml +0 -0
  108. data/test/test/file_methods_test.rb +204 -0
  109. data/test/test/subset_methods_test.rb +93 -33
  110. data/test/test/test_assert_expected_result_files/expected/task/name/a.txt +1 -0
  111. data/test/test/test_assert_expected_result_files/expected/task/name/b.txt +1 -0
  112. data/test/test/test_assert_expected_result_files/input/a.txt +1 -0
  113. data/test/test/test_assert_expected_result_files/input/b.txt +1 -0
  114. data/test/test/test_file_task_test/expected/one.txt +1 -0
  115. data/test/test/test_file_task_test/expected/two.txt +1 -0
  116. data/test/test/test_file_task_test/input/one.txt +1 -0
  117. data/test/test/test_file_task_test/input/two.txt +1 -0
  118. data/test/test_test.rb +143 -3
  119. data/test/workflow_test.rb +2 -0
  120. data/vendor/rails_generator.rb +56 -0
  121. data/vendor/rails_generator/base.rb +263 -0
  122. data/vendor/rails_generator/commands.rb +581 -0
  123. data/vendor/rails_generator/generated_attribute.rb +42 -0
  124. data/vendor/rails_generator/lookup.rb +209 -0
  125. data/vendor/rails_generator/manifest.rb +53 -0
  126. data/vendor/rails_generator/options.rb +143 -0
  127. data/vendor/rails_generator/scripts.rb +83 -0
  128. data/vendor/rails_generator/scripts/destroy.rb +7 -0
  129. data/vendor/rails_generator/scripts/generate.rb +7 -0
  130. data/vendor/rails_generator/scripts/update.rb +12 -0
  131. data/vendor/rails_generator/simple_logger.rb +46 -0
  132. data/vendor/rails_generator/spec.rb +44 -0
  133. metadata +180 -196
  134. data/lib/tap/generator/generators/root/templates/app.yml +0 -19
  135. data/lib/tap/generator/generators/root/templates/config/process_tap_request.yml +0 -4
  136. data/lib/tap/generator/generators/root/templates/lib/process_tap_request.rb +0 -26
  137. data/lib/tap/generator/generators/root/templates/public/images/nav.jpg +0 -0
  138. data/lib/tap/generator/generators/root/templates/public/stylesheets/color.css +0 -57
  139. data/lib/tap/generator/generators/root/templates/public/stylesheets/layout.css +0 -108
  140. data/lib/tap/generator/generators/root/templates/public/stylesheets/normalize.css +0 -40
  141. data/lib/tap/generator/generators/root/templates/public/stylesheets/typography.css +0 -21
  142. data/lib/tap/generator/generators/root/templates/server/config/environment.rb +0 -60
  143. data/lib/tap/generator/generators/root/templates/server/lib/tasks/clear_database_prerequisites.rake +0 -5
  144. data/lib/tap/generator/generators/root/templates/server/test/test_helper.rb +0 -53
  145. data/lib/tap/script/server.rb +0 -12
  146. data/lib/tap/support/rap.rb +0 -38
  147. data/lib/tap/test/inference_methods.rb +0 -298
  148. data/test/task/config/task_with_config.yml +0 -1
  149. data/test/test/inference_methods_test.rb +0 -311
data/lib/tap/script.rb ADDED
@@ -0,0 +1,362 @@
1
+ require 'getoptlong'
2
+ require 'singleton'
3
+ autoload(:PP, "pp")
4
+
5
+ module Tap
6
+ module Support
7
+ autoload(:TDoc, 'tap/support/tdoc')
8
+ end
9
+
10
+ # == UNDER CONSTRUCTION
11
+ class ScriptConfig < OpenStruct
12
+ class << self
13
+ def defaults
14
+ {:gems => [],
15
+ :load_once_paths => [],
16
+ :load_paths => ["lib"],
17
+ :script_paths => ["script"]}
18
+ end
19
+
20
+ def spec_filepath(dir=nil)
21
+ dir == nil ? "tapspec.yml" : File.join(dir, "tapspec.yml")
22
+ end
23
+ end
24
+
25
+ def initialize(config={}, app=Tap::App.instance)
26
+ super(
27
+ :gemspecs => [],
28
+ :load_once_paths => [],
29
+ :load_paths => [],
30
+ :script_paths => [])
31
+
32
+ config = ScriptConfig.defaults.merge(config)
33
+ resolve_paths(config, app)
34
+ collect_gem_paths(config)
35
+
36
+ # add additional configurations
37
+ config.each_pair do |key, value|
38
+ next if self.respond_to?(key)
39
+ self.send("#{key}=", value)
40
+ end
41
+
42
+ self.load_once_paths.uniq!
43
+ self.load_paths.uniq!
44
+ self.script_paths.uniq!
45
+ end
46
+
47
+ def scripts
48
+ scripts = {}
49
+ self.script_paths.each do |dir|
50
+ Dir.glob(File.expand_path(File.join(dir, "**/*.rb"))).each do |file|
51
+ script = Tap::App.relative_filepath(dir, file).chomp(".rb")
52
+ raise "script name confict: #{script}" if scripts.include?(script)
53
+ scripts[script] = file
54
+ end
55
+ end
56
+
57
+ # allow gem scripts to overrride default scripts
58
+ # (hence do this second)
59
+ script_dir = File.expand_path(File.join( File.dirname(__FILE__), "script"))
60
+ Dir.glob( script_dir + "/**/*.rb" ).each do |file|
61
+ script = Tap::App.relative_filepath(script_dir, file).chomp(".rb")
62
+ scripts[script] = file unless scripts.include?(script)
63
+ end
64
+
65
+ scripts
66
+ end
67
+
68
+ protected
69
+
70
+ # Resolve configuration paths, :load_paths, :load_once_paths, :script_paths,
71
+ # to full paths using the provided app, or by expanding the paths relative to
72
+ # the full_gem_path of the provided gemspec.
73
+ def resolve_paths(config, app_or_gemspec) # :nodoc:
74
+ # resolve and collect paths
75
+ [:load_paths, :load_once_paths, :script_paths].each do |key|
76
+ paths = arrayify(config[key])
77
+
78
+ paths.collect! do |path|
79
+ case app_or_gemspec
80
+ when Tap::App
81
+ app_or_gemspec.filepath(path)
82
+ when Gem::Specification
83
+ expanded = File.expand_path(path, app_or_gemspec.full_gem_path)
84
+ unless expanded.index(app_or_gemspec.full_gem_path) == 0
85
+ raise "'#{path}' for '#{app_or_gemspec.name}' resolves to a non-gem directory"
86
+ end
87
+ expanded
88
+ end
89
+ end
90
+
91
+ self.send(key).concat(paths)
92
+ end
93
+ end
94
+
95
+ # Recursively collects paths from the gems specfied in config[:gems],
96
+ # using tap specification file for the gem as determined by
97
+ # ScriptConfig#spec_filepath
98
+ def collect_gem_paths(config) # :nodoc:
99
+ arrayify(config[:gems]).each do |string|
100
+ # figure the version of the gem, by default >= 0.0.0
101
+ string =~ /^([^<=>]*)(.*)$/
102
+ gem_name, version = $1, $2
103
+ version = ">= 0.0.0" if version.empty?
104
+
105
+ # load the gem and get the spec
106
+ gem(gem_name, version)
107
+ spec = Gem.loaded_specs[gem_name]
108
+
109
+ # prevent an infinite loop...
110
+ next if self.gemspecs.include?(spec)
111
+ self.gemspecs << spec
112
+
113
+ # load gem config from the spec, if possible,
114
+ # otherwise use the defaults for the gem
115
+ tap_spec_file = ScriptConfig.spec_filepath(spec.full_gem_path)
116
+ gem_config = if File.exists?(tap_spec_file)
117
+ YAML.load_file(tap_spec_file).symbolize_keys
118
+ else
119
+ ScriptConfig.defaults
120
+ end
121
+
122
+ resolve_paths(gem_config, spec)
123
+ collect_gem_paths(gem_config)
124
+ end
125
+ end
126
+
127
+ def arrayify(obj) # :nodoc:
128
+ case obj
129
+ when nil then []
130
+ when Array then obj
131
+ else
132
+ obj.to_s.strip.empty? ? [] : [obj]
133
+ end
134
+ end
135
+ end
136
+
137
+ # == UNDER CONSTRUCTION
138
+ #
139
+ # Script is a mixed bag of methods encapsulating many scripting
140
+ # functions like reconfiguring an application, handling options
141
+ # and assembling usage information.
142
+ class Script
143
+
144
+ class << self
145
+ def config_filepath(dir=nil)
146
+ dir == nil ? "tap.yml" : File.join(dir, "tap.yml")
147
+ end
148
+
149
+ def read_config(config_file)
150
+ config = if File.exists?(config_file)
151
+ config_str = ERB.new( File.read(config_file) ).result
152
+ config = config_str.empty? ? {} : YAML.load(config_str)
153
+ config == false ? {} : config
154
+ else
155
+ {}
156
+ end
157
+
158
+ unless config.kind_of?(Hash)
159
+ raise "cannot parse file contents into a hash using YAML: #{config_file}"
160
+ end
161
+
162
+ config.symbolize_keys
163
+ end
164
+
165
+ def split_arguments(argv, separator_regexp=/^-{2}$/)
166
+ splits = []
167
+ current = []
168
+ argv.each do |arg|
169
+ if arg =~ separator_regexp
170
+ splits << current unless current.empty?
171
+ current = []
172
+ else
173
+ current << arg
174
+ end
175
+ end
176
+ splits << current unless current.empty?
177
+ splits
178
+ end
179
+
180
+ def next_arg(argv)
181
+ index = nil
182
+ argv.each_with_index do |arg, i|
183
+ if arg !~ /^-/
184
+ index = i
185
+ break
186
+ end
187
+ end
188
+ index == nil ? nil : argv.delete_at(index)
189
+ end
190
+
191
+ def usage(program_file, *sections)
192
+ options = sections.last.kind_of?(Hash) ? sections.pop : {}
193
+ options = {:keep_headers => true}.merge(options)
194
+ comment = Support::TDoc.usage(program_file, sections, options[:keep_headers])
195
+ comment.rstrip + "\n"
196
+ end
197
+
198
+ def usage_options(opts)
199
+ opt_lines = ["Options:\n"]
200
+ opts.each do |long, short, mode, desc|
201
+ short = short == nil ? " " : "(#{short})"
202
+ opt_lines << " %-25s %s %s" % [long, short, desc]
203
+ end
204
+ opt_lines.join("\n")
205
+ end
206
+
207
+ # Handles options using GetoptLong, and passes each option and
208
+ # value in ARGV to the block.
209
+ #
210
+ #--
211
+ # expect [long, <short>, type, desc]
212
+ #++
213
+ def handle_options(*options)
214
+ options = options.collect do |opt|
215
+ opt = opt[0..-2]
216
+ opt.compact
217
+ end
218
+
219
+ opts = GetoptLong.new(*options)
220
+ opts.each do |opt, value|
221
+ yield(opt, value)
222
+ end
223
+ end
224
+
225
+ def handle_task_options(task)
226
+ return task.handle_options if task.respond_to?(:handle_options)
227
+
228
+ config = {}
229
+ opt_map = {}
230
+ opts = task.class.configurations.collect do |declaration_class, key, value, attributes|
231
+ long, short, opt_type, desc = config_to_opt(key, value, attributes)
232
+ opt_map[long] = key
233
+ [long, short, opt_type, desc]
234
+ end
235
+ opts << ['--help', '-h', GetoptLong::NO_ARGUMENT, "Print this help."]
236
+
237
+ handle_options(*opts) do |opt, value|
238
+ case opt
239
+ when '--help'
240
+ class_doc = Tap::Support::TDoc[task.class]
241
+ if class_doc == nil
242
+ puts "could not find help for '#{task.class}'"
243
+ exit
244
+ end
245
+
246
+ sections = class_doc.comment_sections(/Description|Usage/i, true)
247
+ opt_lines = opts.collect do |long, short, opt_type, desc|
248
+ key = opt_map[long]
249
+ default = PP.singleline_pp(task.class.configurations.default[key], "")
250
+ config_attr = class_doc.find_configuration_named(key.to_s)
251
+
252
+ short = "(#{short})" unless short.to_s.empty?
253
+ if desc == nil && config_attr != nil
254
+ desc = config_attr.desc + " (#{default})"
255
+ end
256
+
257
+ " %-25s %-5s %s" % [long, short, desc]
258
+ end
259
+
260
+ puts %Q{#{task.class.to_s}
261
+ #{sections["Description"]}
262
+
263
+ Usage:
264
+ #{sections["Usage"]}
265
+
266
+ Options:
267
+ #{opt_lines.join("\n")}}
268
+ exit
269
+
270
+ else
271
+ key = opt_map[opt]
272
+ config[key] = YAML.load(value)
273
+ end
274
+ end
275
+
276
+ # reconfigure task
277
+ task.batch.each do |t|
278
+ t.config = config
279
+ end
280
+ end
281
+
282
+ protected
283
+
284
+ def config_to_opt(key, value, attributes)
285
+ attributes = {
286
+ :long => key,
287
+ :short => nil,
288
+ :opt_type => GetoptLong::REQUIRED_ARGUMENT,
289
+ :desc => nil
290
+ }.merge(attributes)
291
+
292
+ long = attributes[:long]
293
+ attributes[:long] = "--#{long}" unless long =~ /^-{2}/
294
+
295
+ short = attributes[:short].to_s
296
+ attributes[:short] = "-#{short}" unless short.empty? || short =~ /^-/
297
+
298
+ [attributes[:long], attributes[:short], attributes[:opt_type], attributes[:desc]]
299
+ end
300
+ end
301
+
302
+ include Singleton
303
+
304
+ attr_accessor :config
305
+
306
+ def reset
307
+ self.config = nil
308
+ end
309
+
310
+ # Configures the app with the input configurations.
311
+ def configure_app(app_config={}, app=Tap::App.instance)
312
+ app_config = app_config ? app_config.symbolize_keys : {}
313
+
314
+ # partition script_config from config
315
+ script_config = ScriptConfig.defaults
316
+ script_config_keys = script_config.keys
317
+ app_config.delete_if do |key, value|
318
+ if script_config_keys.include?(key)
319
+ script_config[key] = value
320
+ true
321
+ else
322
+ false
323
+ end
324
+ end
325
+
326
+ # reconfigure the current app with remaining keys
327
+ # this must be done first so load paths can be
328
+ # resolved using the most current app config
329
+ app.reconfigure(app_config) do |key, value|
330
+ # collect unknown options
331
+ script_config[key] = value
332
+ end
333
+
334
+ # define the config, using the newly configured app
335
+ self.config = ScriptConfig.new(script_config, app)
336
+
337
+ # add load paths to system load paths
338
+ # echos Rail::Initializer.set_load_path
339
+ tap_gem_dir = File.expand_path(File.dirname(__FILE__) + "/..")
340
+ config.load_paths.unshift(tap_gem_dir)
341
+ config.load_paths.reverse_each do |dir|
342
+ $LOAD_PATH.unshift(dir) #if File.directory?(dir)
343
+ end
344
+ $LOAD_PATH.uniq!
345
+
346
+ # set Dependencies load paths and freeze setting of load_paths
347
+ # echos Rail::Initializer.set_autoload_paths
348
+ Dependencies.load_once_paths = config.load_once_paths
349
+ Dependencies.load_paths = config.load_paths
350
+
351
+ extra = Dependencies.load_once_paths - Dependencies.load_paths
352
+ unless extra.empty?
353
+ raise(
354
+ "load_once_paths must be a subset of the load_paths.\n" +
355
+ "Extra items in load_once_paths: #{extra * ','}")
356
+ end
357
+
358
+ config
359
+ end
360
+
361
+ end
362
+ end
@@ -1,3 +1,31 @@
1
+ # = Usage
2
+ # tap console {options}
3
+ #
4
+ # = Description
5
+ # Opens up an IRB session with Tap initialized with configurations
6
+ # in tap.yml. Access the Tap::App.instance through 'app'
7
+ #
8
+
9
+ require 'tap/script'
10
+
11
+ #
12
+ # handle options
13
+ #
14
+
15
+ opts = [
16
+ ['--help', '-h', GetoptLong::NO_ARGUMENT, "Print this help."]]
17
+
18
+ Tap::Script.handle_options(*opts) do |opt, value|
19
+ case opt
20
+ when '--help'
21
+ puts Tap::Script.usage(__FILE__, "Usage", "Description", :keep_headers => false)
22
+ puts
23
+ puts Tap::Script.usage_options(opts)
24
+ exit
25
+
26
+ end
27
+ end
28
+
1
29
  require "irb"
2
30
 
3
31
  def app
@@ -1,8 +1,20 @@
1
- require 'tap/generator'
1
+ begin
2
+ $:.unshift File.dirname(__FILE__) + "/../../../vendor"
3
+ require 'tap/generator'
4
+ rescue(LoadError)
5
+ puts "The 'rails' gem is required for destroyers -- install using:"
6
+ puts " % gem install rails"
7
+ exit
8
+ end
9
+
2
10
  Rails::Generator::Base.use_tap_sources!
3
11
 
4
12
  require 'rails_generator/scripts/destroy'
5
13
  generator = ARGV.shift
14
+
15
+ # Ensure help is printed if help is the first argument
16
+ generator = nil if generator == '--help' || generator == '-h'
17
+
6
18
  script = Rails::Generator::Scripts::Destroy.new
7
19
  script.extend Tap::Generator::Usage
8
20
  script.run(ARGV, :generator => generator)
@@ -1,8 +1,20 @@
1
- require 'tap/generator'
1
+ begin
2
+ $:.unshift File.dirname(__FILE__) + "/../../../vendor"
3
+ require 'tap/generator'
4
+ rescue(LoadError)
5
+ puts "The 'rails' gem is required for generators -- install using:"
6
+ puts " % gem install rails"
7
+ exit
8
+ end
9
+
2
10
  Rails::Generator::Base.use_tap_sources!
3
11
 
4
12
  require 'rails_generator/scripts/generate'
5
13
  generator = ARGV.shift
14
+
15
+ # Ensure help is printed if help is the first argument
16
+ generator = nil if generator == '--help' || generator == '-h'
17
+
6
18
  script = Rails::Generator::Scripts::Generate.new
7
19
  script.extend Tap::Generator::Usage
8
20
  script.run(ARGV, :generator => generator)
@@ -1,86 +1,130 @@
1
+ # = Usage
2
+ # tap run {options} -- {task options} task INPUTS...
3
+ #
4
+ # examples:
5
+ # tap run --help Prints this help
6
+ # tap run -- task --help Prints help for task
7
+ #
8
+
9
+ require 'tap/script'
10
+
1
11
  app = Tap::App.instance
2
- task_config = {}
12
+ script = Tap::Script.instance
3
13
 
4
14
  #
5
15
  # handle options
6
16
  #
7
- require 'getoptlong'
8
17
 
9
- opts = GetoptLong.new(
10
- ['--app-config', '-a', GetoptLong::REQUIRED_ARGUMENT],# "Specifies an application config file"],
11
- ['--config', '-c', GetoptLong::REQUIRED_ARGUMENT],# "Specifies configurations for the task."],
12
- ['--quiet', '-q', GetoptLong::NO_ARGUMENT],# "Suppresses logging"],
13
- ['--force', '-f', GetoptLong::NO_ARGUMENT],# "Force execution at checkpoints."],
14
- ['--debug', '-d', GetoptLong::NO_ARGUMENT],# "Trace execution and debug."],
15
- ['--help', '-h', GetoptLong::OPTIONAL_ARGUMENT])#, "Display help for app, or specified task."])
18
+ opts = [
19
+ ['--help', '-h', GetoptLong::NO_ARGUMENT, "Print this help"],
20
+ ['--debug', '-d', GetoptLong::NO_ARGUMENT, "Trace execution and debug"],
21
+ ['--force', '-f', GetoptLong::NO_ARGUMENT, "Force execution at checkpoints"],
22
+ ['--quiet', '-q', GetoptLong::NO_ARGUMENT, "Suppress logging"]]
16
23
 
17
- opts.each do |opt, value|
24
+ Tap::Script.handle_options(*opts) do |opt, value|
18
25
  case opt
19
26
  when '--help'
20
- puts "help!"
21
- exit
22
-
23
- if value.empty?
24
- help
25
- else
26
- task = task(value)
27
- puts task.class.help
28
- puts "Default Config:"
29
- puts task.class.default_config.stringify_keys.to_yaml
30
- end
31
-
32
- when '--usage'
33
- puts "usage!"
27
+ puts Tap::Script.usage(__FILE__, "Usage", :keep_headers => false)
28
+ puts
29
+ puts Tap::Script.usage_options(opts)
34
30
  exit
35
-
36
- when '--app-config'
37
- config = Tap::App.parse_yaml(value)
38
- if config.kind_of?(String)
39
- raise "application config file does not exist: #{config}" unless File.exists?(config)
40
- config = Tap::App.read_erb_yaml(config)
41
- end
42
- app.reconfigure(config)
43
-
44
- when '--config'
45
- task_config = Tap::App.parse_yaml(value)
46
- if task_config.kind_of?(String)
47
- raise "task config file does not exist: #{config}" unless File.exists?(config)
48
- task_config = Tap::App.read_erb_yaml(config)
49
- end
50
-
31
+
51
32
  when '--quiet', '--force', '--debug'
52
33
  # simply track these have been set
53
34
  opt =~ /^-+(\w+)/
54
35
  app.options.send("#{$1}=", true)
55
-
56
- else
57
- puts "unknown option: #{opt}"
58
- exit
36
+
59
37
  end
60
38
  end
61
39
 
62
40
  #
63
- # gather arguments
64
- # (be sure to clear for gets during interruption)
65
-
66
- if ARGV.empty?
41
+ # handle options for each specified task
42
+ #
43
+ argv = Tap::Script.split_arguments(ARGV)
44
+ if argv.empty?
67
45
  puts "no task specified"
68
46
  exit
69
47
  end
70
48
 
71
- td = ARGV.shift
72
- args = ARGV.collect {|arg| Tap::App.parse_yaml(arg) }
73
- ARGV.clear
49
+ argv.each do |args|
50
+ ARGV.clear
51
+ ARGV.concat(args)
52
+
53
+ td = Tap::Script.next_arg(ARGV)
54
+ if td == 'rake'
55
+ # interpret 'rake' tds as specifications for
56
+ # rake tasks and/or inputs:
57
+ # tap run rake -T
58
+ # tap run rake test
59
+ #
60
+ app.extend Tap::Support::Rake
61
+
62
+ rake = Rake.application
63
+ options = rake.options
64
+
65
+ # merge options down from app
66
+ app.options.marshal_dump.each_pair do |key, value|
67
+ options.send("#{key}=", value)
68
+ end
69
+ options.silent = true
70
+
71
+ # now follow the same protocol as
72
+ # in run, handling options
73
+ rake.init
74
+ rake.load_rakefile
75
+
76
+ # takes the place of rake.top_level
77
+ if options.show_tasks
78
+ rake.display_tasks_and_comments
79
+ exit
80
+ elsif options.show_prereqs
81
+ rake.display_prerequisites
82
+ exit
83
+ else
84
+ rake.top_level_tasks.each do |task_name|
85
+ task = app.task(task_name)
86
+ app.queue.enq(task)
87
+ end
88
+ end
89
+
90
+ next
91
+ end
92
+
93
+ # lookup the task
94
+ begin
95
+ task = (td.nil? ? nil : app.task(td))
96
+ rescue(Tap::App::LookupError)
97
+ end
98
+
99
+ # unless a Tap::Task was found, treat the
100
+ # args as a specification for Rake.
101
+ unless task.kind_of?(Tap::Task)
102
+ args.unshift(td) unless task == nil
103
+ args.unshift('rake')
104
+ redo
105
+ end
106
+
107
+ # handle task configuration options
108
+ Tap::Script.handle_task_options(task)
74
109
 
75
- task = app.task(td, task_config)
110
+ # queue the task with the remaining inputs
111
+ args = ARGV.collect! {|arg| Tap::App.parse_yaml(arg) }
112
+ app.queue.enq(task, *args)
113
+ end
114
+ ARGV.clear
76
115
 
77
116
  #
78
117
  # set signals and run!
79
118
  #
80
119
 
81
- # info signal
82
- Signal.trap("INFO") do
83
- puts app.info
120
+ # info signal -- Note: windows does
121
+ # not support the INFO signal
122
+ if RUBY_PLATFORM.index('mswin').nil?
123
+ Signal.trap("INFO") do
124
+ puts app.info
125
+ end
126
+
127
+ puts "ctl-i prints information"
84
128
  end
85
129
 
86
130
  # interuption signal
@@ -104,8 +148,7 @@ Signal.trap("INT") do
104
148
  end
105
149
  end
106
150
 
107
- puts "ctl-i prints information"
108
151
  puts "ctl-c interupts execution"
109
152
  puts "beginning run..."
110
153
 
111
- app.run(task, *args)
154
+ app.run