* [PATCH] dtas-archive: support -m/--match=REGEXP switch
@ 2023-07-03 0:43 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-07-03 0:43 UTC (permalink / raw)
To: dtas-all
Sometimes I only want to archive files matching a certain regexp pattern.
---
Documentation/dtas-archive.pod | 11 ++++++++++-
bin/dtas-archive | 6 +++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/Documentation/dtas-archive.pod b/Documentation/dtas-archive.pod
index 157ea70..50237e8 100644
--- a/Documentation/dtas-archive.pod
+++ b/Documentation/dtas-archive.pod
@@ -52,11 +52,20 @@ Continue after error
Number of times to repeat the L<sndfile-cmp(1)> check. Default: 1
+=item -m, --match REGEX
+
+Only archive files matching a given Ruby (or Perl-compatible) regular
+expression. The regular expression is implementation-dependent and
+using the Perl-compatible subset of Ruby regexps is recommended as dtas
+will be moving away from Ruby at some point.
+
+Added for dtas v0.22.0
+
=back
=head1 COPYRIGHT
-Copyright 2013-2020 all contributors L<mailto:dtas-all@nongnu.org>
+Copyright all contributors L<mailto:dtas-all@nongnu.org>
License: GPL-3.0+ L<https://www.gnu.org/licenses/gpl-3.0.txt>
diff --git a/bin/dtas-archive b/bin/dtas-archive
index c88873e..7c0e4f7 100755
--- a/bin/dtas-archive
+++ b/bin/dtas-archive
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
-# Copyright (C) 2015-2020 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"
@@ -30,6 +30,7 @@
keep_going = false
compression = []
comment = []
+match = nil
OptionParser.new('', 24, ' ') do |op|
op.banner = usage
@@ -47,6 +48,7 @@
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)
@@ -55,6 +57,7 @@
op.parse!(ARGV)
end
+match ||= %r/./
comment.push('--comment', '') if comment.empty?
dst = ARGV.pop
@@ -67,6 +70,7 @@
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)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-07-03 0:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 0:43 [PATCH] dtas-archive: support -m/--match=REGEXP switch Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/dtas.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).