bin/archive-dir

changeset 761
21d7274d64a4
parent 689
840057d4b493
equal deleted inserted replaced
760:d439bf421f1b 761:21d7274d64a4
12 use Getopt::Long::Descriptive; 12 use Getopt::Long::Descriptive;
13 13
14 sub main { 14 sub main {
15 my ($opt, $usage) = describe_options( 15 my ($opt, $usage) = describe_options(
16 'archive-dir %o <directory> ...', 16 'archive-dir %o <directory> ...',
17 ['dest|d=s' => "destination path"], 17 ['dest|d=s' => 'destination path' => {default => '.'}],
18 ['subdir' => hidden => { 18 ['fileinto|F=s' => 'file into, a strftime format', {default => '%Y'}],
19 one_of => [ 19 ['age|a=i' => "minimum age in days for archival", {default => 60}],
20 ['year|y' => 'file by year'], 20 ['files|f' => "operate on plain files only"],
21 ['month|m' => 'file by month'], 21 [],
22 ], 22 ['yes|Y' => "actually move stuff"],
23 default => 'year', 23 ['help|h' => "print usage message and exit", {shortcircuit => 1}],
24 } 24 {show_defaults => 1}
25 ],
26 ['age|a=i' => "minimum age in days for archival", {default => 60}],
27 ['files|f' => "operate on plain files only"],
28 ['yes|Y' => "actually move stuff"],
29 ['help|h' => "print usage message and exit", {shortcircuit => 1}],
30 ); 25 );
31 print($usage->text), exit if $opt->help || !@ARGV; 26 print($usage->text), exit if $opt->help || !@ARGV;
32 27
33 archive_dir($opt, $_) for @ARGV; 28 archive_dir($opt, $_) for @ARGV;
34 } 29 }
35 30
36 sub archive_dir { 31 sub archive_dir {
37 my $opt = shift; 32 my $opt = shift;
38 my $dir = path(shift); 33 my $dir = path(shift);
39 my $destdir = path($opt->dest // '.'); 34 my $destdir = path($opt->dest);
40 $destdir = $dir->child($destdir) if $destdir->is_relative; 35 $destdir = $dir->child($destdir) if $destdir->is_relative;
41 my $destfmt = ($opt->subdir eq 'month') ? '%Y-%m' : '%Y'; 36 my $destfmt = $opt->fileinto;
42 my $nowish = time; 37 my $nowish = time;
43 my $age = $opt->age * 24 * 60 * 60; 38 my $age = $opt->age * 24 * 60 * 60;
44 39
45 my @work; 40 my @work;
46 41

mercurial