From aa809d2f144d4146321f13646786a5a42de028cb Mon Sep 17 00:00:00 2001 From: "Andreas J. Koenig" Date: Wed, 16 Mar 2011 21:54:26 +0100 Subject: [PATCH] make 04-run.t pass; introduce Pod::Usage --- bin/rrr-client | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/bin/rrr-client b/bin/rrr-client index 91f717c..b4e6948 100755 --- a/bin/rrr-client +++ b/bin/rrr-client @@ -1,8 +1,8 @@ #!/usr/bin/env perl use strict; use warnings; -use local::lib; use Getopt::Long; +use Pod::Usage qw(pod2usage); =head1 NAME @@ -12,6 +12,8 @@ rrr-client - continously mirror recent updates rrr-client [options] + rrr-client --source some.mirror::module/ --target /some/dir/ + =head1 OPTIONS =over 8 @@ -20,25 +22,29 @@ rrr-client - continously mirror recent updates my @opt = <<'=back' =~ /B<--(\S+)>/g; -=item B<--source> +=item B<--help|h> + +Prints a brief message and exists. + +=item B<--source=s> Source to mirror from, including the name of the RECENT metadata file. For example C. -=item B<--target> +=item B<--target=s> Destination directory for the mirror. -=item B<--user> +=item B<--user=s> Username if the rsync source requires it. -=item B<--password> +=item B<--password=s> Password if the rsync source requires it. Can also be set by setting the environment variable RSYNC_PASSWORD. -=item B<--tmpdir> +=item B<--tmpdir=s> Directory for temporary files; should be on the same file system partition as the C<--target> directory. @@ -52,25 +58,26 @@ uptodate. Depends on inotify which probably only exists on linux. =cut -GetOptions("user=s" => \(my $opt_user), - "password=s" => \(my $opt_password), - "source=s" => \(my $opt_source), - "target=s" => \(my $opt_target), - "tmpdir=s" => \(my $opt_tmpdir), -); +our %Opt; +GetOptions + (\%Opt, + @opt, + ) or pod2usage(1); + +if ($Opt{help}) { + pod2usage(0); +} +pod2usage(1) unless $Opt{source} and $Opt{target}; -die "$0 --source some.mirror::module/ --target /some/dir/\n" - unless $opt_source and $opt_target; - -$ENV{RSYNC_PASSWORD} = $opt_password if $opt_password; +$ENV{RSYNC_PASSWORD} = $Opt{password} if $Opt{password}; use File::Rsync::Mirror::Recent; my $rrr = File::Rsync::Mirror::Recent->new ( ignore_link_stat_errors => 1, - localroot => $opt_target, - ($opt_tmpdir ? (tempdir => $opt_tmpdir) : ()), - remote => ($opt_user ? $opt_user . '@' : '') . $opt_source, + localroot => $Opt{target}, + ($Opt{tmpdir} ? (tempdir => $Opt{tmpdir}) : ()), + remote => ($Opt{user} ? $Opt{user} . '@' : '') . $Opt{source}, max_files_per_connection => 20000, rsync_options => { compress => 1, @@ -78,7 +85,7 @@ my $rrr = File::Rsync::Mirror::Recent->new 'safe-links' => 1, times => 1, checksum => 0, - ($opt_tmpdir ? ('temp-dir' => $opt_tmpdir) : ()), + ($Opt{tmpdir} ? ('temp-dir' => $Opt{tmpdir}) : ()), }, verbose => 1, _runstatusfile => "recent-rmirror-state.yml", -- 2.11.4.GIT