ratch 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/HISTORY.rdoc +87 -0
- data/README.rdoc +86 -66
- data/bin/ludo +26 -10
- data/lib/ratch/batch.rb +115 -74
- data/lib/ratch/core_ext/facets.rb +2 -1
- data/lib/ratch/core_ext/to_console.rb +11 -11
- data/lib/ratch/file_list.rb +6 -15
- data/lib/ratch/script.rb +1 -1
- data/lib/ratch/shell.rb +356 -518
- data/lib/ratch/utils/config.rb +4 -4
- data/lib/ratch/utils/email.rb +20 -97
- data/lib/ratch/utils/rdoc.rb +4 -7
- data/lib/ratch/utils/tar.rb +94 -50
- data/lib/ratch/utils/xdg.rb +2 -3
- data/lib/ratch/utils/zlib.rb +5 -4
- data/lib/ratch/version.rb +3 -0
- data/lib/ratch.rb +8 -24
- metadata +134 -157
- data/.ruby +0 -99
- data/History.rdoc +0 -35
- data/License.txt +0 -204
- data/Version +0 -1
- data/lib/ratch/console.rb +0 -199
- data/lib/ratch/system.rb +0 -15
- data/lib/ratch/utils/ftp.rb +0 -134
- data/lib/ratch/utils/pom.rb +0 -22
- data/lib/ratch.yml +0 -99
- data/man/ratch.1 +0 -28
- data/spec/01_shell.rdoc +0 -198
- data/spec/02_script.rdoc +0 -34
- data/spec/03_batch.rdoc +0 -71
- data/spec/04_system.rdoc +0 -3
- data/spec/applique/array.rb +0 -8
- data/spec/applique/setup.rb +0 -20
- data/test/case_batch.rb +0 -63
- data/test/case_shell.rb +0 -46
- data/test/core_ext/case_pathname.rb +0 -361
- data/test/helper.rb +0 -4
- data/test/utils/case_cli.rb +0 -6
- data/test/utils/case_config.rb +0 -12
- data/test/utils/case_email.rb +0 -10
- data/test/utils/case_ftp.rb +0 -6
- data/test/utils/case_pom.rb +0 -17
- data/test/utils/case_rdoc.rb +0 -23
- data/test/utils/case_tar.rb +0 -6
- data/test/utils/case_zlib.rb +0 -11
- data/test/utils/fixtures/pom_sample/Profile +0 -4
- data/test/utils/fixtures/rdoc_sample/README.rdoc +0 -4
- data/test/utils/fixtures/rdoc_sample/lib/rdoc_sample/rdoc_sample.rb +0 -9
- /data/{COPYING → LICENSE.txt} +0 -0
data/lib/ratch/batch.rb
CHANGED
|
@@ -11,23 +11,35 @@ module Ratch
|
|
|
11
11
|
class Batch
|
|
12
12
|
include Enumerable
|
|
13
13
|
|
|
14
|
-
#
|
|
14
|
+
# A batch of the files matching +patterns+ under the present
|
|
15
|
+
# directory.
|
|
15
16
|
def self.[](*patterns)
|
|
16
17
|
new('.', *patterns)
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
#
|
|
20
|
+
# Like #new, but without the usual exclusions (version control
|
|
21
|
+
# directories, backup and core files).
|
|
22
|
+
def self.all(local, *patterns)
|
|
23
|
+
options = (Hash === patterns.last ? patterns.pop.dup : {})
|
|
24
|
+
new(local, *patterns, options.merge(:all=>true))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# New batch of the files matching +patterns+, which are relative to
|
|
28
|
+
# the directory +local+. A final Hash gives options: :noop, :verbose
|
|
29
|
+
# (or :trace) and :dryrun, as for Shell, and :all to leave nothing out.
|
|
20
30
|
def initialize(local, *patterns)
|
|
21
|
-
@local = Pathname.new(local)
|
|
22
|
-
@options =
|
|
31
|
+
@local = Pathname.new(local.to_s)
|
|
32
|
+
@options = {}
|
|
33
|
+
(Hash === patterns.last ? patterns.pop : {}).each{ |k, v| @options[k.to_sym] = v }
|
|
23
34
|
|
|
24
|
-
@file_list = FileList.all
|
|
35
|
+
@file_list = @options[:all] ? FileList.all : FileList.new
|
|
25
36
|
|
|
26
|
-
patterns.each do |pattern|
|
|
27
|
-
|
|
37
|
+
patterns.flatten.each do |pattern|
|
|
38
|
+
pattern = pattern.to_s
|
|
39
|
+
if @local == Pathname.new('.') || FileTest.absolute?(pattern)
|
|
28
40
|
@file_list.add(pattern)
|
|
29
41
|
else
|
|
30
|
-
@file_list.add(File.join(local,pattern))
|
|
42
|
+
@file_list.add(File.join(@local.to_s, pattern))
|
|
31
43
|
end
|
|
32
44
|
end
|
|
33
45
|
end
|
|
@@ -103,7 +115,7 @@ module Ratch
|
|
|
103
115
|
def readable? ; all?{ |path| FileTest.readable?(path) } ; end
|
|
104
116
|
def chardev? ; all?{ |path| FileTest.chardev?(path) } ; end
|
|
105
117
|
def exist? ; all?{ |path| FileTest.exist?(path) } ; end
|
|
106
|
-
def exists? ; all?{ |path| FileTest.
|
|
118
|
+
def exists? ; all?{ |path| FileTest.exist?(path) } ; end
|
|
107
119
|
def zero? ; all?{ |path| FileTest.zero?(path) } ; end
|
|
108
120
|
def pipe? ; all?{ |path| FileTest.pipe?(path) } ; end
|
|
109
121
|
def file? ; all?{ |path| FileTest.file?(path) } ; end
|
|
@@ -170,7 +182,7 @@ module Ratch
|
|
|
170
182
|
raise Errno::EEXIST, "File exists - #{dir}"
|
|
171
183
|
end
|
|
172
184
|
end
|
|
173
|
-
list.map{ |dir|
|
|
185
|
+
list.map{ |dir| fu(:mkdir, options, dir){ |opts| ::FileUtils.mkdir(dir, **opts) } }
|
|
174
186
|
end
|
|
175
187
|
|
|
176
188
|
# Make a directory for every entry.
|
|
@@ -180,42 +192,36 @@ module Ratch
|
|
|
180
192
|
raise Errno::EEXIST, "File exists - #{dir}"
|
|
181
193
|
end
|
|
182
194
|
end
|
|
183
|
-
list.map{ |dir|
|
|
195
|
+
list.map{ |dir| fu(:mkdir_p, options, dir){ |opts| ::FileUtils.mkdir_p(dir, **opts) } }
|
|
184
196
|
end
|
|
185
197
|
alias_method :mkpath, :mkdir_p
|
|
186
198
|
|
|
187
199
|
# Remove every directory.
|
|
188
200
|
def rmdir(options={})
|
|
189
|
-
list.map{ |dir|
|
|
201
|
+
list.map{ |dir| fu(:rmdir, options, dir){ |opts| ::FileUtils.rmdir(dir, **opts) } }
|
|
190
202
|
end
|
|
191
203
|
|
|
192
204
|
# ln(list, destdir, options={})
|
|
193
205
|
def ln(dir, options={})
|
|
194
|
-
|
|
195
|
-
#new = localize(new)
|
|
196
|
-
fileutils.ln(list, dir, options)
|
|
206
|
+
fu(:ln, options, list, dir){ |opts| ::FileUtils.ln(list, localize(dir), **opts) }
|
|
197
207
|
end
|
|
198
208
|
alias_method :link, :ln
|
|
199
209
|
|
|
200
210
|
# ln_s(list, destdir, options={})
|
|
201
211
|
def ln_s(dir, options={})
|
|
202
|
-
|
|
203
|
-
#new = localize(new)
|
|
204
|
-
fileutils.ln_s(list, dir, options)
|
|
212
|
+
fu(:ln_s, options, list, dir){ |opts| ::FileUtils.ln_s(list, localize(dir), **opts) }
|
|
205
213
|
end
|
|
206
214
|
alias_method :symlink, :ln_s
|
|
207
215
|
|
|
208
216
|
def ln_sf(dir, options={})
|
|
209
|
-
|
|
210
|
-
#new = localize(new)
|
|
211
|
-
fileutils.ln_sf(list, dir, options)
|
|
217
|
+
fu(:ln_sf, options, list, dir){ |opts| ::FileUtils.ln_sf(list, localize(dir), **opts) }
|
|
212
218
|
end
|
|
213
219
|
|
|
214
220
|
# cp(list, dir, options={})
|
|
215
221
|
def cp(dir, options={})
|
|
216
222
|
#src = list.to_a
|
|
217
223
|
#dest = localize(dest)
|
|
218
|
-
|
|
224
|
+
fu(:cp, options, list, dir){ |opts| ::FileUtils.cp(list, localize(dir), **opts) }
|
|
219
225
|
end
|
|
220
226
|
alias_method :copy, :cp
|
|
221
227
|
|
|
@@ -223,21 +229,20 @@ module Ratch
|
|
|
223
229
|
def cp_r(dir, options={})
|
|
224
230
|
#src = list.to_a
|
|
225
231
|
#dest = localize(dest)
|
|
226
|
-
|
|
232
|
+
fu(:cp_r, options, list, dir){ |opts| ::FileUtils.cp_r(list, localize(dir), **opts) }
|
|
227
233
|
end
|
|
228
234
|
|
|
229
235
|
# mv(list, dir, options={})
|
|
230
236
|
def mv(dir, options={})
|
|
231
237
|
#src = list.to_a
|
|
232
238
|
#dest = localize(dest)
|
|
233
|
-
|
|
239
|
+
fu(:mv, options, list, dir){ |opts| ::FileUtils.mv(list, localize(dir), **opts) }
|
|
234
240
|
end
|
|
235
241
|
alias_method :move, :mv
|
|
236
242
|
|
|
237
243
|
#
|
|
238
244
|
def rm(options={})
|
|
239
|
-
list
|
|
240
|
-
fileutils.rm(list, options)
|
|
245
|
+
fu(:rm, options, list){ |opts| ::FileUtils.rm(list, **opts) }
|
|
241
246
|
end
|
|
242
247
|
|
|
243
248
|
# Alias for #rm.
|
|
@@ -245,68 +250,68 @@ module Ratch
|
|
|
245
250
|
|
|
246
251
|
# Remove, recursively removing the contents of directories.
|
|
247
252
|
def rm_r(options={})
|
|
248
|
-
|
|
249
|
-
fileutils.rm_r(list, options)
|
|
253
|
+
fu(:rm_r, options, list){ |opts| ::FileUtils.rm_r(list, **opts) }
|
|
250
254
|
end
|
|
251
255
|
|
|
252
256
|
# Remove, with force option.
|
|
253
257
|
def rm_f(options={})
|
|
254
|
-
|
|
255
|
-
fileutils.rm_f(list, options)
|
|
258
|
+
fu(:rm_f, options, list){ |opts| ::FileUtils.rm_f(list, **opts) }
|
|
256
259
|
end
|
|
257
260
|
|
|
258
261
|
# Remove with force option, recursively removing the contents of directories.
|
|
259
262
|
def rm_rf(options={})
|
|
260
|
-
|
|
261
|
-
fileutils.rm_rf(list, options)
|
|
263
|
+
fu(:rm_rf, options, list){ |opts| ::FileUtils.rm_rf(list, **opts) }
|
|
262
264
|
end
|
|
263
265
|
|
|
264
266
|
# Install files to a directory with given mode. Unlike #cp, this will
|
|
265
267
|
# not copy the file if an up-to-date copy already exists.
|
|
266
268
|
def install(dir, mode, options={})
|
|
267
|
-
#src = list.to_a
|
|
268
269
|
#dest = localize(dest)
|
|
269
|
-
|
|
270
|
+
fu(:install, options.merge(:mode=>mode), list, dir){ |opts| ::FileUtils.install(list, localize(dir), **opts) }
|
|
270
271
|
end
|
|
271
272
|
|
|
272
273
|
# Change mode of files.
|
|
273
274
|
def chmod(mode, options={})
|
|
274
|
-
|
|
275
|
-
fileutils.chmod(mode, list, options)
|
|
275
|
+
fu(:chmod, options, mode, list){ |opts| ::FileUtils.chmod(mode, list, **opts) }
|
|
276
276
|
end
|
|
277
277
|
|
|
278
278
|
# Change mode of files, following directories recursively.
|
|
279
279
|
def chmod_r(mode, options={})
|
|
280
|
-
|
|
281
|
-
fileutils.chmod_r(mode, list, options)
|
|
280
|
+
fu(:chmod_R, options, mode, list){ |opts| ::FileUtils.chmod_R(mode, list, **opts) }
|
|
282
281
|
end
|
|
283
282
|
#alias_method :chmod_R, :chmod_r
|
|
284
283
|
|
|
285
284
|
# Change owner of files.
|
|
286
285
|
def chown(user, group, options={})
|
|
287
|
-
|
|
288
|
-
fileutils.chown(user, group, list, options)
|
|
286
|
+
fu(:chown, options, user, group, list){ |opts| ::FileUtils.chown(user, group, list, **opts) }
|
|
289
287
|
end
|
|
290
288
|
|
|
291
289
|
# Change owner of files, following directories recursively.
|
|
292
290
|
def chown_r(user, group, options={})
|
|
293
|
-
|
|
294
|
-
fileutils.chown_r(user, group, list, options)
|
|
291
|
+
fu(:chown_R, options, user, group, list){ |opts| ::FileUtils.chown_R(user, group, list, **opts) }
|
|
295
292
|
end
|
|
296
293
|
#alias_method :chown_R, :chown_r
|
|
297
294
|
|
|
298
295
|
# Touch each file.
|
|
299
296
|
def touch(options={})
|
|
300
|
-
|
|
301
|
-
fileutils.touch(list, options)
|
|
297
|
+
fu(:touch, options, list){ |opts| ::FileUtils.touch(list, **opts) }
|
|
302
298
|
end
|
|
303
299
|
|
|
304
|
-
# Stage files
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
300
|
+
# Stage files: hard link each into +dir+, at its path relative to
|
|
301
|
+
# the batch's own directory. This is like #install but uses hardlinks.
|
|
302
|
+
def stage(dir, options={})
|
|
303
|
+
stage = localize(dir)
|
|
304
|
+
entries.each do |entry|
|
|
305
|
+
src = localize(entry)
|
|
306
|
+
dest = File.join(stage, entry.to_s)
|
|
307
|
+
if File.directory?(src)
|
|
308
|
+
fu(:mkdir_p, options, dest){ |opts| ::FileUtils.mkdir_p(dest, **opts) }
|
|
309
|
+
else
|
|
310
|
+
fu(:mkdir_p, options, File.dirname(dest)){ |opts| ::FileUtils.mkdir_p(File.dirname(dest), **opts) }
|
|
311
|
+
fu(:ln, options, src, dest){ |opts| ::FileUtils.ln(src, dest, **opts) }
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
dir
|
|
310
315
|
end
|
|
311
316
|
|
|
312
317
|
# Convenient alias for #map_mv.
|
|
@@ -324,7 +329,7 @@ module Ratch
|
|
|
324
329
|
#
|
|
325
330
|
# Returns the changed FileList instance.
|
|
326
331
|
def map_mv(options={}, &block)
|
|
327
|
-
@file_list = map_send(:mv, options
|
|
332
|
+
@file_list = map_send(:mv, options, &block)
|
|
328
333
|
end
|
|
329
334
|
|
|
330
335
|
# Hard link the list of files in batch, using a block to determine the new
|
|
@@ -332,7 +337,7 @@ module Ratch
|
|
|
332
337
|
#
|
|
333
338
|
# This is similar to #ln, but allows for detailed control over the link names.
|
|
334
339
|
def map_ln(options={}, &block)
|
|
335
|
-
map_send(:ln, options
|
|
340
|
+
map_send(:ln, options, &block)
|
|
336
341
|
end
|
|
337
342
|
|
|
338
343
|
# Soft link the list of files in batch, using a block to determine the new
|
|
@@ -340,7 +345,7 @@ module Ratch
|
|
|
340
345
|
#
|
|
341
346
|
# This is similar to #ln_s, but allows for detailed control over the link names.
|
|
342
347
|
def map_ln_s(options={}, &block)
|
|
343
|
-
map_send(:ln_s, options
|
|
348
|
+
map_send(:ln_s, options, &block)
|
|
344
349
|
end
|
|
345
350
|
|
|
346
351
|
# Force soft linking of the list of files in batch, using a block to
|
|
@@ -350,7 +355,7 @@ module Ratch
|
|
|
350
355
|
# This is similar to #ln_sf, but allows for detailed control over the
|
|
351
356
|
# link names.
|
|
352
357
|
def map_ln_sf(options={}, &block)
|
|
353
|
-
map_send(:ln_sf, options
|
|
358
|
+
map_send(:ln_sf, options, &block)
|
|
354
359
|
end
|
|
355
360
|
|
|
356
361
|
# Copy the list of files in batch, using a block to determine the new
|
|
@@ -359,7 +364,7 @@ module Ratch
|
|
|
359
364
|
# This is similar to #cp, but allows for detailed control over the new
|
|
360
365
|
# file names.
|
|
361
366
|
def map_cp(options={}, &block)
|
|
362
|
-
map_send(:cp, options
|
|
367
|
+
map_send(:cp, options, &block)
|
|
363
368
|
end
|
|
364
369
|
|
|
365
370
|
# Copy the list of files recursively in batch, using a block to determine
|
|
@@ -368,7 +373,7 @@ module Ratch
|
|
|
368
373
|
# This is similar to #cp_r, but allows for detailed control over the new
|
|
369
374
|
# file names.
|
|
370
375
|
def map_cp_r(options={}, &block)
|
|
371
|
-
map_send(:cp_r, options
|
|
376
|
+
map_send(:cp_r, options, &block)
|
|
372
377
|
end
|
|
373
378
|
|
|
374
379
|
# # Force copy the list of files recursively in batch, using a block to
|
|
@@ -378,7 +383,7 @@ module Ratch
|
|
|
378
383
|
# # This is similar to #cp_rf, but allows for detailed control over the new
|
|
379
384
|
# # file names.
|
|
380
385
|
# def map_cp_rf(options={}, &block)
|
|
381
|
-
# map_send(:cp_rf, options
|
|
386
|
+
# map_send(:cp_rf, options, &block)
|
|
382
387
|
# end
|
|
383
388
|
|
|
384
389
|
private
|
|
@@ -404,7 +409,12 @@ module Ratch
|
|
|
404
409
|
end
|
|
405
410
|
|
|
406
411
|
map.each do |src, dest|
|
|
407
|
-
|
|
412
|
+
fu(method, options, src, dest) do |opts|
|
|
413
|
+
takes = ::FileUtils.method(method).parameters.map{ |_, name| name }
|
|
414
|
+
opts.delete(:force) unless takes.include?(:force)
|
|
415
|
+
::FileUtils.rm_f(dest) if options[:force] && !takes.include?(:force) && File.file?(dest)
|
|
416
|
+
::FileUtils.__send__(method, src, dest, **opts)
|
|
417
|
+
end
|
|
408
418
|
end
|
|
409
419
|
FileList.all(*map.values)
|
|
410
420
|
end
|
|
@@ -415,7 +425,7 @@ module Ratch
|
|
|
415
425
|
# If nota file rrror is raised.
|
|
416
426
|
def ensure_safe(map)
|
|
417
427
|
map.each do |src, dest|
|
|
418
|
-
raise unless File.exist?(src)
|
|
428
|
+
raise Errno::ENOENT, src.to_s unless File.exist?(src)
|
|
419
429
|
if File.directory?(src)
|
|
420
430
|
if File.directory?(dest)
|
|
421
431
|
new_map = {}
|
|
@@ -423,7 +433,7 @@ module Ratch
|
|
|
423
433
|
next if e == '.' or e == '..'
|
|
424
434
|
new_map[File.join(src, e)] = File.join(dest, e)
|
|
425
435
|
end
|
|
426
|
-
|
|
436
|
+
ensure_safe(new_map)
|
|
427
437
|
else
|
|
428
438
|
raise Errno::EISDIR, "Is a directory - #{src}"
|
|
429
439
|
end
|
|
@@ -456,23 +466,27 @@ module Ratch
|
|
|
456
466
|
|
|
457
467
|
# Is +path+ out-of-date in comparsion to all files in batch.
|
|
458
468
|
def outofdate?(path)
|
|
459
|
-
|
|
469
|
+
path = localize(path)
|
|
470
|
+
return true unless File.exist?(path)
|
|
471
|
+
return true if list.empty?
|
|
472
|
+
File.mtime(path) < list.map{ |f| File.mtime(f) }.max
|
|
460
473
|
end
|
|
461
474
|
|
|
462
475
|
# Is +path+ up-to-date in comparsion to all files in batch.
|
|
463
476
|
def uptodate?(path)
|
|
464
|
-
|
|
477
|
+
::FileUtils.uptodate?(localize(path), list)
|
|
465
478
|
end
|
|
466
479
|
|
|
467
480
|
#
|
|
468
481
|
def noop?
|
|
469
|
-
@options[:noop] or @options[:dryrun]
|
|
482
|
+
!!(@options[:noop] or @options[:nowrite] or @options[:dryrun])
|
|
470
483
|
end
|
|
471
484
|
|
|
472
485
|
#
|
|
473
486
|
def verbose?
|
|
474
|
-
@options[:verbose] or @options[:dryrun]
|
|
487
|
+
!!(@options[:verbose] or @options[:trace] or @options[:dryrun])
|
|
475
488
|
end
|
|
489
|
+
alias_method :trace?, :verbose?
|
|
476
490
|
|
|
477
491
|
#
|
|
478
492
|
def dryrun?
|
|
@@ -481,17 +495,44 @@ module Ratch
|
|
|
481
495
|
|
|
482
496
|
private
|
|
483
497
|
|
|
484
|
-
#
|
|
485
|
-
def
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
498
|
+
# A path taken from the batch's own directory, unless it is absolute.
|
|
499
|
+
def localize(path)
|
|
500
|
+
path = path.to_s
|
|
501
|
+
return path if FileTest.absolute?(path) || local.to_s == '.'
|
|
502
|
+
File.join(local.to_s, path)
|
|
503
|
+
end
|
|
504
|
+
|
|
505
|
+
# How each file operation reads in a trace.
|
|
506
|
+
FU_COMMANDS = {
|
|
507
|
+
:mkdir_p=>'mkdir -p', :rm_r=>'rm -r', :rm_f=>'rm -f', :rm_rf=>'rm -rf',
|
|
508
|
+
:ln_s=>'ln -s', :ln_sf=>'ln -sf', :cp_r=>'cp -r',
|
|
509
|
+
:chmod_R=>'chmod -R', :chown_R=>'chown -R'
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
# Carry out a file operation in the batch's mode: report it if
|
|
513
|
+
# tracing, with the paths as they were given, and yield the options
|
|
514
|
+
# for FileUtils unless this is a noop.
|
|
515
|
+
def fu(name, options, *args)
|
|
516
|
+
opts = fu_options(options)
|
|
517
|
+
noop = opts.delete(:noop)
|
|
518
|
+
verbose = opts.delete(:verbose)
|
|
519
|
+
if verbose
|
|
520
|
+
$stderr.puts [FU_COMMANDS[name] || name.to_s, *args.flatten].join(' ')
|
|
494
521
|
end
|
|
522
|
+
yield(opts) unless noop
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
# The options given for one command, with :noop and :verbose turned
|
|
526
|
+
# on if the batch's mode says so.
|
|
527
|
+
def fu_options(options)
|
|
528
|
+
opts = {}
|
|
529
|
+
(options || {}).each{ |k, v| opts[k.to_sym] = v }
|
|
530
|
+
given = [:dryrun, :nowrite, :noop, :trace, :verbose].select{ |k| opts.delete(k) }
|
|
531
|
+
dryrun = given.include?(:dryrun)
|
|
532
|
+
opts[:noop] = true if noop? || dryrun || given.include?(:nowrite) || given.include?(:noop)
|
|
533
|
+
opts[:verbose] = true if verbose? || dryrun || given.include?(:trace) || given.include?(:verbose)
|
|
534
|
+
opts.delete(:safe)
|
|
535
|
+
opts
|
|
495
536
|
end
|
|
496
537
|
|
|
497
538
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# I know some people will be deterred by the dependency on Facets b/c they
|
|
2
2
|
# see it as a "heavy" dependency. But really that is far from true, consider
|
|
3
|
-
# the following libs are all that it used.
|
|
3
|
+
# the facet that the following libs are all that it used.
|
|
4
4
|
|
|
5
5
|
require 'facets/array/not_empty'
|
|
6
6
|
require 'facets/dir/multiglob' # DEPRECATE: when new #glob is working.
|
|
@@ -13,3 +13,4 @@ require 'facets/kernel/disable_warnings'
|
|
|
13
13
|
require 'facets/pathname'
|
|
14
14
|
require 'facets/filetest'
|
|
15
15
|
require 'facets/fileutils'
|
|
16
|
+
require 'facets/hash/rekey'
|
|
@@ -8,10 +8,8 @@ class Array #:nodoc:
|
|
|
8
8
|
# method arguments --ie. [arg1, arg2, ..., hash]
|
|
9
9
|
|
|
10
10
|
def to_console
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
#flags + ' ' + join(" ")
|
|
14
|
-
to_argv.join(' ')
|
|
11
|
+
require 'shellwords'
|
|
12
|
+
Shellwords.join(to_argv)
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
# TODO: DEPRECATE
|
|
@@ -19,9 +17,9 @@ class Array #:nodoc:
|
|
|
19
17
|
|
|
20
18
|
#
|
|
21
19
|
def to_argv
|
|
22
|
-
|
|
23
|
-
flags =
|
|
24
|
-
flags +
|
|
20
|
+
args = dup
|
|
21
|
+
flags = (Hash===args.last ? args.pop : {})
|
|
22
|
+
flags.to_argv + args.map{ |a| a.to_s }
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
# def to_console
|
|
@@ -50,10 +48,12 @@ class Hash
|
|
|
50
48
|
# The array is accepted in the format of Ruby
|
|
51
49
|
# method arguments --ie. [arg1, arg2, ..., hash]
|
|
52
50
|
def to_console
|
|
53
|
-
|
|
51
|
+
require 'shellwords'
|
|
52
|
+
Shellwords.join(to_argv)
|
|
54
53
|
end
|
|
55
54
|
|
|
56
|
-
# Convert a Hash into command line parameters
|
|
55
|
+
# Convert a Hash into command line parameters, one string per
|
|
56
|
+
# parameter, as a program receives them (so with no quoting).
|
|
57
57
|
# The array is accepted in the format of Ruby
|
|
58
58
|
# method arguments --ie. [arg1, arg2, ..., hash]
|
|
59
59
|
def to_argv
|
|
@@ -62,13 +62,13 @@ class Hash
|
|
|
62
62
|
m = f.to_s.size == 1 ? '-' : '--'
|
|
63
63
|
case v
|
|
64
64
|
when Array
|
|
65
|
-
v.each{ |e| flags << "
|
|
65
|
+
v.each{ |e| flags << (m == '-' ? "-#{f}#{e}" : "--#{f}=#{e}") }
|
|
66
66
|
when true
|
|
67
67
|
flags << "#{m}#{f}"
|
|
68
68
|
when false, nil
|
|
69
69
|
# nothing
|
|
70
70
|
else
|
|
71
|
-
flags << "
|
|
71
|
+
flags << (m == '-' ? "-#{f}#{v}" : "--#{f}=#{v}")
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
flags
|
data/lib/ratch/file_list.rb
CHANGED
|
@@ -265,26 +265,17 @@ module Ratch
|
|
|
265
265
|
self
|
|
266
266
|
end
|
|
267
267
|
|
|
268
|
-
#
|
|
269
|
-
#
|
|
270
|
-
# details.)
|
|
271
|
-
def pathmap(spec=nil)
|
|
272
|
-
collect { |fn| fn.pathmap(spec) }
|
|
273
|
-
end
|
|
274
|
-
|
|
275
|
-
# Return a new FileList with <tt>String#ext</tt> method applied to
|
|
276
|
-
# each member of the array.
|
|
268
|
+
# Return a new FileList with the extension of each file name changed
|
|
269
|
+
# to +newext+, or removed if none is given.
|
|
277
270
|
#
|
|
278
|
-
#
|
|
271
|
+
# FileList['a.c', 'b.c'].ext('o') #=> ['a.o', 'b.o']
|
|
279
272
|
#
|
|
280
|
-
# array.collect { |item| item.ext(newext) }
|
|
281
|
-
#
|
|
282
|
-
# +ext+ is a user added method for the Array class.
|
|
283
273
|
def ext(newext='')
|
|
284
|
-
|
|
274
|
+
newext = newext.to_s
|
|
275
|
+
newext = '.' + newext unless newext.empty? || newext.start_with?('.')
|
|
276
|
+
collect { |fn| fn.chomp(File.extname(fn)) + newext }
|
|
285
277
|
end
|
|
286
278
|
|
|
287
|
-
|
|
288
279
|
# Grep each of the files in the filelist using the given pattern. If a
|
|
289
280
|
# block is given, call the block on each matching line, passing the file
|
|
290
281
|
# name, line number, and the matching line of text. If no block is given,
|
data/lib/ratch/script.rb
CHANGED
|
@@ -92,7 +92,7 @@ module Ratch
|
|
|
92
92
|
|
|
93
93
|
# Pass-thru to singleton class.
|
|
94
94
|
def define_method(name, &block)
|
|
95
|
-
(class << self; self; end).__send__(:define_method, &block)
|
|
95
|
+
(class << self; self; end).__send__(:define_method, name, &block)
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
## If method is missing, try the singleton class. This allows the script
|