about summary refs log tree commit homepage
path: root/bin/dtas-archive
diff options
context:
space:
mode:
Diffstat (limited to 'bin/dtas-archive')
-rwxr-xr-xbin/dtas-archive14
1 files changed, 11 insertions, 3 deletions
diff --git a/bin/dtas-archive b/bin/dtas-archive
index f47f05a..7c0e4f7 100755
--- a/bin/dtas-archive
+++ b/bin/dtas-archive
@@ -1,5 +1,5 @@
 #!/usr/bin/env ruby
-# Copyright (C) 2015-2016 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 usage = "#$0 SOURCE DESTINATION"
@@ -29,6 +29,8 @@ repeat = 1
 stats = false
 keep_going = false
 compression = []
+comment = []
+match = nil
 
 OptionParser.new('', 24, '  ') do |op|
   op.banner = usage
@@ -36,6 +38,7 @@ OptionParser.new('', 24, '  ') do |op|
   op.on('-C', '--compression [FACTOR]', 'compression factor for sox') { |c|
     compression = [ '-C', c ]
   }
+  op.on('--comment=TEXT', String) { |c| comment.push('--comment', c) }
   op.on('-j', '--jobs [JOBS]', Integer) { |j| jobs = j }
   op.on('-S', '--stats', 'save stats on the file') { stats = true }
   op.on('-k', '--keep-going', 'continue after error') { keep_going = true }
@@ -45,6 +48,7 @@ OptionParser.new('', 24, '  ') do |op|
   op.on('-r', '--repeat [COUNT]', 'number of times to check', Integer) do |r|
     repeat = r
   end
+  op.on('-m', '--match=REGEX', String) { |s| match = Regexp.new(s) }
   op.on('-s', '--quiet', '--silent') { silent = true }
   op.on('-h', '--help') do
     puts(op.to_s)
@@ -53,6 +57,9 @@ OptionParser.new('', 24, '  ') do |op|
   op.parse!(ARGV)
 end
 
+match ||= %r/./
+comment.push('--comment', '') if comment.empty?
+
 dst = ARGV.pop
 src = ARGV.dup
 
@@ -63,6 +70,7 @@ src.each do |s|
   src_st = File.stat(s)
   if src_st.directory?
     Find.find(s) do |path|
+      path =~ match or next
       File.file?(path) or next
       dir = File.dirname(path)
       dir_st = File.stat(dir)
@@ -137,7 +145,7 @@ thrs = jobs.times.map do |i|
 
       if dry_run || !silent
         names = job.map { |x| Shellwords.escape(x) }
-        cmd = [ 'sox', *names ]
+        cmd = [ 'sox', names[0], *compression, *comment, names[1] ]
         if stats
           cmd << 'stats'
           cmd << "2>#{Shellwords.escape(stats_out)}"
@@ -151,7 +159,7 @@ thrs = jobs.times.map do |i|
         end
       end
 
-      cmd = [ 'sox', input, *compression, output ]
+      cmd = [ 'sox', input, *compression, *comment, output ]
       if stats
         cmd << 'stats'
         cmd = [ *cmd, { err: stats_out } ]