bahuvrihi-tap 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History +69 -0
- data/MIT-LICENSE +21 -0
- data/README +119 -0
- data/bin/tap +114 -0
- data/cmd/console.rb +42 -0
- data/cmd/destroy.rb +16 -0
- data/cmd/generate.rb +16 -0
- data/cmd/run.rb +126 -0
- data/doc/Class Reference +362 -0
- data/doc/Command Reference +153 -0
- data/doc/Tutorial +237 -0
- data/lib/tap.rb +32 -0
- data/lib/tap/app.rb +720 -0
- data/lib/tap/constants.rb +8 -0
- data/lib/tap/env.rb +640 -0
- data/lib/tap/file_task.rb +547 -0
- data/lib/tap/generator/base.rb +109 -0
- data/lib/tap/generator/destroy.rb +37 -0
- data/lib/tap/generator/generate.rb +61 -0
- data/lib/tap/generator/generators/command/command_generator.rb +21 -0
- data/lib/tap/generator/generators/command/templates/command.erb +32 -0
- data/lib/tap/generator/generators/config/config_generator.rb +26 -0
- data/lib/tap/generator/generators/config/templates/doc.erb +12 -0
- data/lib/tap/generator/generators/config/templates/nodoc.erb +8 -0
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +27 -0
- data/lib/tap/generator/generators/file_task/templates/file.txt +11 -0
- data/lib/tap/generator/generators/file_task/templates/result.yml +6 -0
- data/lib/tap/generator/generators/file_task/templates/task.erb +33 -0
- data/lib/tap/generator/generators/file_task/templates/test.erb +29 -0
- data/lib/tap/generator/generators/root/root_generator.rb +55 -0
- data/lib/tap/generator/generators/root/templates/Rakefile +86 -0
- data/lib/tap/generator/generators/root/templates/gemspec +27 -0
- data/lib/tap/generator/generators/root/templates/tapfile +8 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +3 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +5 -0
- data/lib/tap/generator/generators/root/templates/test/tapfile_test.rb +15 -0
- data/lib/tap/generator/generators/task/task_generator.rb +27 -0
- data/lib/tap/generator/generators/task/templates/task.erb +14 -0
- data/lib/tap/generator/generators/task/templates/test.erb +21 -0
- data/lib/tap/generator/manifest.rb +14 -0
- data/lib/tap/patches/rake/rake_test_loader.rb +8 -0
- data/lib/tap/patches/rake/testtask.rb +55 -0
- data/lib/tap/patches/ruby19/backtrace_filter.rb +51 -0
- data/lib/tap/patches/ruby19/parsedate.rb +16 -0
- data/lib/tap/root.rb +581 -0
- data/lib/tap/support/aggregator.rb +55 -0
- data/lib/tap/support/assignments.rb +172 -0
- data/lib/tap/support/audit.rb +418 -0
- data/lib/tap/support/batchable.rb +47 -0
- data/lib/tap/support/batchable_class.rb +107 -0
- data/lib/tap/support/class_configuration.rb +194 -0
- data/lib/tap/support/command_line.rb +98 -0
- data/lib/tap/support/comment.rb +270 -0
- data/lib/tap/support/configurable.rb +114 -0
- data/lib/tap/support/configurable_class.rb +296 -0
- data/lib/tap/support/configuration.rb +122 -0
- data/lib/tap/support/constant.rb +70 -0
- data/lib/tap/support/constant_utils.rb +127 -0
- data/lib/tap/support/declarations.rb +111 -0
- data/lib/tap/support/executable.rb +111 -0
- data/lib/tap/support/executable_queue.rb +82 -0
- data/lib/tap/support/framework.rb +71 -0
- data/lib/tap/support/framework_class.rb +199 -0
- data/lib/tap/support/instance_configuration.rb +147 -0
- data/lib/tap/support/lazydoc.rb +428 -0
- data/lib/tap/support/manifest.rb +89 -0
- data/lib/tap/support/run_error.rb +39 -0
- data/lib/tap/support/shell_utils.rb +71 -0
- data/lib/tap/support/summary.rb +30 -0
- data/lib/tap/support/tdoc.rb +404 -0
- data/lib/tap/support/tdoc/tdoc_html_generator.rb +38 -0
- data/lib/tap/support/tdoc/tdoc_html_template.rb +42 -0
- data/lib/tap/support/templater.rb +180 -0
- data/lib/tap/support/validation.rb +410 -0
- data/lib/tap/support/versions.rb +97 -0
- data/lib/tap/task.rb +259 -0
- data/lib/tap/tasks/dump.rb +56 -0
- data/lib/tap/tasks/rake.rb +93 -0
- data/lib/tap/test.rb +37 -0
- data/lib/tap/test/env_vars.rb +29 -0
- data/lib/tap/test/file_methods.rb +377 -0
- data/lib/tap/test/script_methods.rb +144 -0
- data/lib/tap/test/subset_methods.rb +420 -0
- data/lib/tap/test/tap_methods.rb +237 -0
- data/lib/tap/workflow.rb +187 -0
- metadata +145 -0
data/doc/Class Reference
ADDED
@@ -0,0 +1,362 @@
|
|
1
|
+
= Class Reference
|
2
|
+
|
3
|
+
Working up from the ground is useful to get a sense for how Tap does what it does. This reference goes through the modules and classes that build up a task application: Tasks, Apps, and Envs.
|
4
|
+
|
5
|
+
== Tasks (Tap::Task, Tap::Workflow)
|
6
|
+
|
7
|
+
==== Methods
|
8
|
+
|
9
|
+
http://tap.rubyforge.org/images/Method.png
|
10
|
+
|
11
|
+
Tasks begin with methods, simply a block of code.
|
12
|
+
|
13
|
+
==== Tap::Support::Executable
|
14
|
+
|
15
|
+
http://tap.rubyforge.org/images/Executable.png
|
16
|
+
|
17
|
+
Executable extends objects allowing them to be enqued and run by an App. Executable objects specify a method that gets called upon execution; in essence Executable wraps this method and adds workflow behaviors like auditing and an <tt>on_complete</tt> block.
|
18
|
+
|
19
|
+
Tasks are constructed such that <tt>execute</tt> is their executable method. Task#execute simply provides hooks before and after forwarding control to the <tt>process</tt> method. Hence <tt>process</tt> is the standard method overridden in subclasses of Task.
|
20
|
+
|
21
|
+
==== Tap::Support::Batchable
|
22
|
+
|
23
|
+
http://tap.rubyforge.org/images/Batchable.png
|
24
|
+
|
25
|
+
Tasks can be assembled into batches that all enque at the same time and share the same <tt>on_complete</tt> block. This behavior is very powerful, allowing workflow logic to be defined once but executed under multiple conditions. Task includes the Batchable module to facilitate batching.
|
26
|
+
|
27
|
+
==== Tap::Support::Configurable
|
28
|
+
|
29
|
+
http://tap.rubyforge.org/images/Configurable.png
|
30
|
+
|
31
|
+
Configurable allows declaration of class configurations. Configurable classes have a <tt>configurations</tt> method accessing a {ClassConfiguration}[link:classes/Tap/Support/ClassConfiguration.html] which holds all declared configs, their default values, and metadata for transforming configurations into command line options (for example).
|
32
|
+
|
33
|
+
Instances of a Configurable class have a <tt>config</tt> method accessing a {InstanceConfiguration}[link:classes/Tap/Support/InstanceConfiguration.html] object. The instance configuration acts like a forwarding hash; read and write operations for declared configs get forwarded to class methods while undeclared configs are stored directly. The writer for a config may be defined through a block provided during config declaration. For instance:
|
34
|
+
|
35
|
+
class ConfigClass
|
36
|
+
include Tap::Support::Configurable
|
37
|
+
|
38
|
+
config :key, 'value' do |input|
|
39
|
+
input.upcase
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Is basically the same as:
|
44
|
+
|
45
|
+
class RegularClass
|
46
|
+
attr_reader :key
|
47
|
+
|
48
|
+
def key=(input)
|
49
|
+
@key = input.upcase
|
50
|
+
end
|
51
|
+
|
52
|
+
def initialize
|
53
|
+
self.key = 'value'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
As you can see here:
|
58
|
+
|
59
|
+
c = ConfigClass.new
|
60
|
+
c.key # => 'VALUE'
|
61
|
+
|
62
|
+
c.config[:key] = 'new value'
|
63
|
+
c.key # => 'NEW VALUE'
|
64
|
+
|
65
|
+
c.key = 'another value'
|
66
|
+
c.config[:key] # => 'ANOTHER VALUE'
|
67
|
+
|
68
|
+
This setup is both fast and convenient.
|
69
|
+
|
70
|
+
==== Tap::Support::Validation
|
71
|
+
|
72
|
+
When configurations are set from the command line, the writer method will inevitably receive a string, whereas configurations set within code can receive any type of object. The {Validation}[link:classes/Tap/Support/Validation.html] module provides standard blocks for validating and transforming inputs, accessible through the <tt>c</tt> method (ex: <tt>c.integer</tt> or <tt>c.regexp</tt>). These blocks (generally) load string inputs as YAML and validate that the result is the correct class; non-string inputs are simply validated.
|
73
|
+
|
74
|
+
class ValidatingClass
|
75
|
+
include Tap::Support::Configurable
|
76
|
+
|
77
|
+
config :int, 1, &c.integer # assures the input is an integer
|
78
|
+
config :int_or_nil, 1, &c.integer_or_nil # integer or nil only
|
79
|
+
config :array, [], &c.array # you get the idea
|
80
|
+
end
|
81
|
+
|
82
|
+
vc = ValidatingClass.new
|
83
|
+
|
84
|
+
vc.array = [:a, :b, :c]
|
85
|
+
vc.array # => [:a, :b, :c]
|
86
|
+
|
87
|
+
vc.array = "[1, 2, 3]"
|
88
|
+
vc.array # => [1, 2, 3]
|
89
|
+
|
90
|
+
vc.array = "string" # !> ValidationError
|
91
|
+
|
92
|
+
Validation blocks sometimes imply metadata. For instance <tt>c.flag</tt> makes a config into a flag on the command line.
|
93
|
+
|
94
|
+
==== Tap::Support::Lazydoc
|
95
|
+
|
96
|
+
http://tap.rubyforge.org/images/Lazydoc.png
|
97
|
+
|
98
|
+
Ah lazydoc. Lazydoc fits into the space between live code and code documentation. Lazydoc can scan a file (code or not) and pull out documentation into the object space where it can be utilized. Lazydoc uses a key-value syntax that is both invalid Ruby and easily hidden in RDoc. Looks like this:
|
99
|
+
|
100
|
+
# ::key value
|
101
|
+
|
102
|
+
Try the former line without the comment and a syntax error results. In RDoc, the syntax doesn't interfere with any of the standard documentation conventions and can be hidden with the use of a <tt>:startdoc:</tt> attribute (an extra space is added to <tt>:startdoc:</tt> so the line isn't actually hidden in this document):
|
103
|
+
|
104
|
+
# :start doc::key value
|
105
|
+
|
106
|
+
Lazydoc parses a constant name, the key, the value, and any comment following the value until a non-comment line or an end key. For example:
|
107
|
+
|
108
|
+
[lazydoc_file.rb]
|
109
|
+
# Name::Space::key value
|
110
|
+
#
|
111
|
+
# This documentation
|
112
|
+
# gets parsed.
|
113
|
+
#
|
114
|
+
|
115
|
+
# Name::Space::another another value
|
116
|
+
# This gets parsed.
|
117
|
+
# Name::Space::another-
|
118
|
+
#
|
119
|
+
# This does not.
|
120
|
+
|
121
|
+
require 'tap'
|
122
|
+
|
123
|
+
lazydoc = Tap::Support::Lazydoc[__FILE__]
|
124
|
+
lazydoc.resolve
|
125
|
+
|
126
|
+
lazydoc['Name::Space']['key'].to_s # => "This documentation gets parsed."
|
127
|
+
lazydoc['Name::Space']['another'].subject # => "another value"
|
128
|
+
|
129
|
+
Furthermore, Lazydoc allows living code to register lines that should get documented. These lines are parsed to echo what happens in RDoc.
|
130
|
+
|
131
|
+
[another_lazydoc_file.rb]
|
132
|
+
# documentation
|
133
|
+
# for the method
|
134
|
+
def method
|
135
|
+
end
|
136
|
+
|
137
|
+
require 'tap'
|
138
|
+
|
139
|
+
lazydoc = Tap::Support::Lazydoc[__FILE__]
|
140
|
+
code_comment = lazydoc.register(2)
|
141
|
+
lazydoc.resolve
|
142
|
+
|
143
|
+
code_comment.subject # => "def method"
|
144
|
+
code_comment.to_s # => "documentation for the method"
|
145
|
+
|
146
|
+
Tap uses Lazydoc to indicate when a file contains a Task (<tt>::manifest</tt>) or a generator (<tt>::generator</tt>), and for config documentation. Tap::Env uses this information to facilitate lookup and instantiation of task classes.
|
147
|
+
|
148
|
+
One note: when no constant name is specified for a Lazydoc key, it gets treated as a default for the whole file.
|
149
|
+
|
150
|
+
[lib/sample/task.rb]
|
151
|
+
# ::manifest sample task description
|
152
|
+
#
|
153
|
+
# This manifest is expected to apply to the Sample::Task class.
|
154
|
+
# If more than one task is defined in this file, or if Sample::Task
|
155
|
+
# is not defined by loading this file, Tap will run into trouble.
|
156
|
+
|
157
|
+
However, the best practice is to include the namespace explicitly.
|
158
|
+
|
159
|
+
=== Tap::Task
|
160
|
+
|
161
|
+
http://tap.rubyforge.org/images/Task.png
|
162
|
+
|
163
|
+
Running a task through the tap executable instantiates a task class, configures it, enques it, and runs a Tap::App to get the inputs to the <tt>process</tt> method. Tasks do not have to be used this way; they are perfectly capable as objects in free-standing scripts.
|
164
|
+
|
165
|
+
Task instances can take a block that acts as a stand-in for <tt>process</tt>:
|
166
|
+
|
167
|
+
t = Tap::Task.new {|task| 1 + 2 }
|
168
|
+
t.process # => 3
|
169
|
+
|
170
|
+
t = Tap::Task.new {|task, x, y| x + y }
|
171
|
+
t.process(1, 2) # => 3
|
172
|
+
|
173
|
+
Tasks can be configured:
|
174
|
+
|
175
|
+
t1 = Tap::Task.new(:key => 'one') {|task, input| "#{input}:#{task.config[:key]}"}
|
176
|
+
t1.process('str') # => "str:one"
|
177
|
+
|
178
|
+
And batched:
|
179
|
+
|
180
|
+
t2 = t1.initialize_batch_obj(:key => 'two')
|
181
|
+
t3 = t1.initialize_batch_obj(:key => 'three')
|
182
|
+
|
183
|
+
t1.batch # => [t1, t2, t3]
|
184
|
+
|
185
|
+
Batched tasks enque together, and therefore run sequentially with the same inputs:
|
186
|
+
|
187
|
+
app = Tap::App.instance
|
188
|
+
app.enq(t1, 'str')
|
189
|
+
app.queue.to_a # => [[t1, ['str']], [t2, ['str']], [t3, ['str']]]
|
190
|
+
app.run
|
191
|
+
|
192
|
+
app.results(t1) # => ["str:one"]
|
193
|
+
app.results(t2) # => ["str:two"]
|
194
|
+
app.results(t3) # => ["str:three"]
|
195
|
+
|
196
|
+
Also, as a consequence of Task being Executable, the results have audit trails. In the audit trail, the tasks are identified by name (by default the name the underscored class name):
|
197
|
+
|
198
|
+
t1.name = 'task one'
|
199
|
+
t2.name = 'task two'
|
200
|
+
t3.name = 'task three'
|
201
|
+
|
202
|
+
app._results(t1,t2,t3).collect do |_result|
|
203
|
+
_result.to_s
|
204
|
+
end.join("---\n")
|
205
|
+
# =>
|
206
|
+
# o-[] 1
|
207
|
+
# o-[task one] "str:one"
|
208
|
+
# ---
|
209
|
+
# o-[] 1
|
210
|
+
# o-[task two] "str:two"
|
211
|
+
# ---
|
212
|
+
# o-[] 1
|
213
|
+
# o-[task three] "str:three"
|
214
|
+
|
215
|
+
Task instances can be joined into workflows. The workflow model used by Tap is very simple; when a task completes it calls its <tt>on_complete</tt> block to enque the next task (or tasks) in the workflow. Arbitrary workflow logic is allowed since there are no restrictions on what the <tt>on_complete</tt> block does. If a task has no <tt>on_complete</tt> block, App collects the unhandled results (as shown above) so they can be handled somewhere else. See below for more details.
|
216
|
+
|
217
|
+
=== Tap::Workflow
|
218
|
+
|
219
|
+
http://tap.rubyforge.org/images/Workflow.png
|
220
|
+
|
221
|
+
Workflows are not Tasks but are constructed with the same modules as Task and work very similarly Tasks. Workflows have a <tt>workflow</tt> method which defines the entry and exit points for the workflow; there can be 1+ entry points and 0+ exit points. The enque method for a workflow enques all it's entry points, and when the <tt>on_complete</tt> block is set for a workflow, it is set for all exit points.
|
222
|
+
|
223
|
+
Like Tasks, Workflows can be configured, enqued, used in workflows, and subclassed.
|
224
|
+
|
225
|
+
== Apps
|
226
|
+
|
227
|
+
==== Tap::Root
|
228
|
+
|
229
|
+
http://tap.rubyforge.org/images/Root.png
|
230
|
+
|
231
|
+
A Root represents the base of a directory structure. Roots allow you to alias directories and ease working with filepaths, basically allowing you to develop code for a conceptual directory structure that can be defined later.
|
232
|
+
|
233
|
+
root = Tap::Root.new '/path/to/root'
|
234
|
+
root.root # => '/path/to/root'
|
235
|
+
root['config'] # => '/path/to/root/config'
|
236
|
+
root.filepath('config', 'sample.yml') # => '/path/to/root/config/sampl.yml'
|
237
|
+
|
238
|
+
While simple, this ability to reference files using aliases is useful, powerful, and forms the basis of the Tap execution environment.
|
239
|
+
|
240
|
+
==== Tap::Support::ExecutableQueue
|
241
|
+
|
242
|
+
http://tap.rubyforge.org/images/ExecutableQueue.png
|
243
|
+
|
244
|
+
Apps coordinate the execution of tasks through a queue. The queue is just a stack of Executable objects, basically methods, and the inputs to those methods; during a run the enqued methods are sequentially executed with the inputs.
|
245
|
+
|
246
|
+
Normally the methods execute one after the other on the main thread, however the methods can be set to multithread. In this case all sequential, multithreadable methods are executed on their own thread (up to a configurable maximum number of threads). A non-multithreadable method blocks until all these threads finish, and then the sequential, single thread execution resumes.
|
247
|
+
|
248
|
+
For instance, assuming non-multithreadable executables [a,b,c] and multithread executables [m1, m2, m3], a queue of [a, m1, m2, m3, b, c] executes like:
|
249
|
+
|
250
|
+
a... done
|
251
|
+
(m1, m2, m3)... done
|
252
|
+
b... done
|
253
|
+
c... done
|
254
|
+
|
255
|
+
==== Tap::Support::Audit
|
256
|
+
|
257
|
+
Tap tracks inputs as they are modified by various tasks, again through Executable. At the end of a run, any individual result can be tracked back to it's original value with references to the source of each change in the value (ie the task or Executable). This auditing can be very useful when workflows diverge, as they often do.
|
258
|
+
|
259
|
+
Auditing is largely invisible except in <tt>on_complete</tt> blocks. <tt>on_complete</tt> blocks receive the audited results so that this information can be used, as needed, to make decisions.
|
260
|
+
|
261
|
+
t = Task.new
|
262
|
+
t.on_complete do |_result| # _result is an Audit instance
|
263
|
+
_result._current # the current value
|
264
|
+
_result._original # the original value
|
265
|
+
end
|
266
|
+
|
267
|
+
To help indicate when a result is actually a result and when it is an audit, Tap uses a convention whereby a leading underscore signals auditing is involved.
|
268
|
+
|
269
|
+
==== Tap::Support::Aggregator
|
270
|
+
|
271
|
+
When a task completes, it executes it's <tt>on_complete</tt> block to handle the results, perhaps passing them on to other tasks. Aggregators collect results when no <tt>on_complete</tt> block is specified. Results are collected per-task into an array; a single task executed many times will have it's results aggregated into this single array.
|
272
|
+
|
273
|
+
=== Tap::App
|
274
|
+
|
275
|
+
http://tap.rubyforge.org/images/App.png
|
276
|
+
|
277
|
+
Instances of Tap::App coordinate the execution of tasks. Apps are basically a subclass of Root with an ExecutableQueue and Aggregator. Task initialization requires an App, which is by default Tap::App.instance. Tasks use their app for logging, checks, and to enque themselves. Normally a script will only need and use a single instance (often Tap::App.instance), but there is no reason why multiple instances could not be used.
|
278
|
+
|
279
|
+
log = StringIO.new
|
280
|
+
app = Tap::App.instance
|
281
|
+
app.logger = Logger.new(log)
|
282
|
+
|
283
|
+
t = Tap::Task.new
|
284
|
+
t.log 'action', 'to app'
|
285
|
+
log.string # => " I[15:21:23] action to app\n"
|
286
|
+
|
287
|
+
t.enq(1)
|
288
|
+
t.enq(2,3)
|
289
|
+
app.queue.to_a # => [[t, [1]], [t, [2,3]]
|
290
|
+
|
291
|
+
Apps also coordinate the creation of standard workflow patterns like sequence, fork, and merge. These methods set <tt>on_complete</tt> blocks for the input tasks.
|
292
|
+
|
293
|
+
t1 = Tap.task('t1') {|t| 'hellO'}
|
294
|
+
t2 = Tap.task('t2') {|t, input| input + ' woRld' }
|
295
|
+
t3 = Tap.task('t3') {|t, input| input.downcase }
|
296
|
+
t4 = Tap.task('t4') {|t, input| input.upcase }
|
297
|
+
t5 = Tap.task('t5') {|t, input| input + "!" }
|
298
|
+
|
299
|
+
# sequence t1, t2
|
300
|
+
app.sequence(t1, t2)
|
301
|
+
|
302
|
+
# fork t2 results to t3 and t4
|
303
|
+
app.fork(t2, t3, t4)
|
304
|
+
|
305
|
+
# unsynchronized merge of t3 and t4 into t5
|
306
|
+
app.merge(t5, t3, t4)
|
307
|
+
|
308
|
+
app.enq(t1)
|
309
|
+
app.run
|
310
|
+
|
311
|
+
app.results(t5) # => ["hello world!", "HELLO WORLD!"]
|
312
|
+
|
313
|
+
As shown above, aggregated results may be accessed by task through the <tt>results</tt> method. To access the audited results, use <tt>_results</tt>:
|
314
|
+
|
315
|
+
app._results(t5).collect do |_result|
|
316
|
+
_result.to_s
|
317
|
+
end.join("---\n")
|
318
|
+
# =>
|
319
|
+
# o-[t1] "hellO"
|
320
|
+
# o-[t2] "hellO woRld"
|
321
|
+
# o-[t3] "hello world"
|
322
|
+
# o-[t5] "hello world!"
|
323
|
+
# ----
|
324
|
+
# o-[t1] "hellO"
|
325
|
+
# o-[t2] "hellO woRld"
|
326
|
+
# o-[t4] "HELLO WORLD"
|
327
|
+
# o-[t5] "HELLO WORLD!"
|
328
|
+
|
329
|
+
== Envs
|
330
|
+
|
331
|
+
==== Tap::Env
|
332
|
+
|
333
|
+
http://tap.rubyforge.org/images/Env.png
|
334
|
+
|
335
|
+
Environments are still under construction. Basically a wrapper for a Root, Envs define methods to generate manifests for a type of file-based resource (tasks, generators, etc). Furthermore they provide methods to uniquely identify the resource by path or, more specifically, minimized base paths. In this directory structure:
|
336
|
+
|
337
|
+
path
|
338
|
+
`- to
|
339
|
+
|- another
|
340
|
+
| `- file.rb
|
341
|
+
|- file-0.1.0.rb
|
342
|
+
|- file-0.2.0.rb
|
343
|
+
`- file.rb
|
344
|
+
|
345
|
+
The minimal paths that uniquely identify these files are (respectively):
|
346
|
+
|
347
|
+
'another/file'
|
348
|
+
'file-0.1.0'
|
349
|
+
'file-0.2.0'
|
350
|
+
'file.rb'
|
351
|
+
|
352
|
+
Envs facilitate mapping the minimal path, which might be provided by the command line, to the actual path, and hence to the resource. Envs can be nested so that manifests span multiple directories. Indeed, this is how tap accesses tasks and generators within gems; the gem directories are initialized as Envs and nested within the Env for the working directory.
|
353
|
+
|
354
|
+
http://tap.rubyforge.org/images/Nested-Env.png
|
355
|
+
|
356
|
+
To prevent conflicts between similarly-named resources under two Envs, Env allows selection of Envs, also by minimized paths. At present this is difficult to illustrate in a code snippit.
|
357
|
+
|
358
|
+
--
|
359
|
+
==== Run Env
|
360
|
+
http://tap.rubyforge.org/images/Run-Env.png
|
361
|
+
++
|
362
|
+
|
@@ -0,0 +1,153 @@
|
|
1
|
+
= Command Reference
|
2
|
+
|
3
|
+
The <tt>tap</tt> executable is the gateway for the execution of tasks. To get help for tap, type:
|
4
|
+
|
5
|
+
% tap --help
|
6
|
+
|
7
|
+
<tt>tap</tt> sets up the execution environment from <tt>tap.yml</tt>, if it exists, and passes control to the specified command. Command help can be obtained using:
|
8
|
+
|
9
|
+
% tap [command] --help
|
10
|
+
|
11
|
+
This reference covers the commands: run, console, generate, destroy
|
12
|
+
|
13
|
+
=== tap run
|
14
|
+
|
15
|
+
Run configures, enqueues, and executes tasks. Run has a rich syntax allowing the specification of any number of tasks with configurations and inputs, but simplifies under most circumstances. Several examples illustrate the key points:
|
16
|
+
|
17
|
+
% tap run sample/task
|
18
|
+
% tap run -- sample/task --key=value input_one -- another/task input_two
|
19
|
+
|
20
|
+
The second statement specifies two tasks with inputs, and specifies a configuration for sample/task. As can be seen, run separates tasks using a double-dash, the standard option break. Options for the run command can be specified before the first option break.
|
21
|
+
|
22
|
+
% tap run --debug -- sample/task --key=value
|
23
|
+
|
24
|
+
Here run receives the <tt>--debug</tt> option and sample/task receives the <tt>--key=value</tt> option. NOTE: it's always a good idea to include the first option break to formally signify when configuration of run stops. Otherwise you may be confused when the following commands both produce the help for run:
|
25
|
+
|
26
|
+
% tap run --help
|
27
|
+
% tap run sample/task --help
|
28
|
+
|
29
|
+
Inputs work the same way. For example:
|
30
|
+
|
31
|
+
% tap run -- sample/task --key=value one -- another/task two three
|
32
|
+
|
33
|
+
Specifies the following:
|
34
|
+
|
35
|
+
t1 = Sample::Task.new(:key => 'value')
|
36
|
+
t1.enq('one')
|
37
|
+
|
38
|
+
t2 = Another::Task.new
|
39
|
+
t2.enq('two', 'three')
|
40
|
+
|
41
|
+
Any number of tasks, configurations, and inputs may be specified in this way.
|
42
|
+
|
43
|
+
==== Task Lookup
|
44
|
+
|
45
|
+
Tap can find and run tasks from multiple environments, for instance from multiple gems. Tap provides a compact way to specify which task to run in the event of a name conflict. The actual process involves minimizing the path to the environment and the relative path to the task file, but from the command line all of the details are hidden:
|
46
|
+
|
47
|
+
% tap run -T
|
48
|
+
one:
|
49
|
+
sample/task # some sample task
|
50
|
+
another/task # another task
|
51
|
+
two:
|
52
|
+
sample/task # a conflicting sample task
|
53
|
+
|
54
|
+
In this situation, these commands run the 'one' sample/task:
|
55
|
+
|
56
|
+
% tap run -- sample/task
|
57
|
+
% tap run -- one:sample/task
|
58
|
+
|
59
|
+
While this runs the 'two' sample/task:
|
60
|
+
|
61
|
+
% tap run -- two::sample/task
|
62
|
+
|
63
|
+
Additionally, base-fragments of the minimized paths can be specified (if laziness strikes); they will be resolved in order from top to bottom within the specified environment.
|
64
|
+
|
65
|
+
Runs the 'one' sample/task:
|
66
|
+
|
67
|
+
% tap run -- task
|
68
|
+
|
69
|
+
Runs the 'two' sample/task:
|
70
|
+
|
71
|
+
% tap run -- two::task
|
72
|
+
|
73
|
+
The full minimized path must be specified for another/task:
|
74
|
+
|
75
|
+
% tap run -- another/task
|
76
|
+
% tap run -- one:another/task
|
77
|
+
|
78
|
+
==== Rounds
|
79
|
+
|
80
|
+
Run allows specification of a number of rounds of tasks. All tasks in a round are run to completion before the next round begins. Rounds are specified by adding '+' characters after the double-dash task break.
|
81
|
+
|
82
|
+
% tap run -- round_one_task --+ round_two_task
|
83
|
+
|
84
|
+
Tasks may be added to rounds in any order. This is equivalent to the last:
|
85
|
+
|
86
|
+
% tap run --+ round_two_task -- round_one_task
|
87
|
+
|
88
|
+
Rounds are particularly useful for dump tasks; add a dump task as a final round to capture all results from previous rounds:
|
89
|
+
|
90
|
+
% tap run -- task -- task --+ dump
|
91
|
+
|
92
|
+
==== YAML inputs
|
93
|
+
|
94
|
+
Non-string inputs can be provided through run. If an input begins with "---\n" then it is loaded as YAML into an object before being passed to a task. The syntax can be a lot to type, but is very handy to have around. The following enques sample/task with a hash input, {'number' => 1}.
|
95
|
+
|
96
|
+
On *nix, just hit enter to get the next line:
|
97
|
+
|
98
|
+
% tap run -- sample/task '---
|
99
|
+
> number: 1'
|
100
|
+
|
101
|
+
On Windows, you need to pull some tricks to get newlines into your argument. Cleverly use a caret to ignore the next line feed:
|
102
|
+
|
103
|
+
% tap run -- sample/task '---^
|
104
|
+
More?
|
105
|
+
More? number: 1'
|
106
|
+
|
107
|
+
Notice that pressing enter <em>every other line</em> is what actually puts the "\n" into the parameter. Keep using carets to enter more lines. The syntax on Windows isn't exactly pretty, and it only works with a caveat: the latest execution script generated by rubygems (tap.bat) re-processes inputs to tap before executing the command for real. I haven't found a workaround short of invoking tap from ruby itself:
|
108
|
+
|
109
|
+
% ruby C:/ruby/bin/tap run -- sample/task '---^
|
110
|
+
More?
|
111
|
+
More? number: 1'
|
112
|
+
|
113
|
+
In these cases, consider putting the inputs into a file and load them to the command line with the <tt>--use</tt> option:
|
114
|
+
|
115
|
+
[inputs.yml]
|
116
|
+
number: 1
|
117
|
+
|
118
|
+
% tap run -- sample/task --use inputs.yml
|
119
|
+
|
120
|
+
=== tap console
|
121
|
+
|
122
|
+
Console opens an irb session with Tap loaded and configured using <tt>tap.yml</tt>. Console defines variables 'app' and 'env' referencing Tap::App.instance and Tap::Env.instance, for easy access.
|
123
|
+
|
124
|
+
% tap console
|
125
|
+
irb(main):001:0> app.log(:hello)
|
126
|
+
I[17:18:53] hello
|
127
|
+
=> true
|
128
|
+
irb(main):002:0>
|
129
|
+
|
130
|
+
=== tap generate/destroy
|
131
|
+
|
132
|
+
Generate and destory launch generator scripts, similar to those in Rails. By default Tap provides generators for:
|
133
|
+
|
134
|
+
{root}[link:classes/Tap/Generator/Generators/RootGenerator.html]:: the basic Tap directory structure
|
135
|
+
{task}[link:classes/Tap/Generator/Generators/TaskGenerator.html]:: a Tap::Task and test
|
136
|
+
{file_task}[link:classes/Tap/Generator/Generators/FileTaskGenerator.html]:: a Tap::FileTask and test
|
137
|
+
{config}[link:classes/Tap/Generator/Generators/ConfigGenerator.html]:: a yaml config file for the specified task
|
138
|
+
{command}[link:classes/Tap/Generator/Generators/CommandGenerator.html]:: a new command
|
139
|
+
|
140
|
+
--
|
141
|
+
{generator}[link:classes/Tap/Generator/GeneratorseneratorGenerator.html]:: a new generator
|
142
|
+
{workflow}[link:classes/Tap/Generator/Generators/Workflow/WorkflowGenerator.html]:: a Tap::Workflow and test
|
143
|
+
++
|
144
|
+
|
145
|
+
For example:
|
146
|
+
|
147
|
+
% tap generate root .
|
148
|
+
% tap generate task sample_task
|
149
|
+
% tap generate config sample_task
|
150
|
+
|
151
|
+
% tap destroy config sample_task
|
152
|
+
% tap destroy task sample_task
|
153
|
+
% tap destroy root .
|