Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gethrefre: --print option

  • Loading branch information...
commit 7a03ac10c9ccd8a9209c292ae90e9f9f7e4efcfa 1 parent 0ebde5f
Ævar Arnfjörð Bjarmason authored
Showing with 17 additions and 10 deletions.
  1. +17 −10 gethrefre
27 gethrefre
View
@@ -1,4 +1,5 @@
#!/usr/bin/env perl
+
=head1 NAME
gethrefre
@@ -11,6 +12,7 @@ gethrefre [ [ -h | --help ] | [ [ -r | --re ] pattern ] url ]
-h --help Print this usage message and exit
-r --re The pattern to compare href attributes against
+ -p --print Just print the URLs, progress to stderr
=head1 DESCRIPTION
@@ -31,8 +33,9 @@ Getopt::Long::Configure qw(bundling no_ignore_case no_require_order);
my %opt;
Getopt::Long::GetOptions(
- 'h|help' => \&help,
- 'r|re=s' => \$opt{re},
+ 'h|help' => \&help,
+ 'r|re=s' => \$opt{re},
+ 'p|print' => \$opt{print},
);
my @url = @ARGV;
@@ -42,28 +45,32 @@ my $ua = LWP::UserAgent->new(
);
for my $url (@url) {
- print "* Getting $url ...";
+ print STDERR "* Getting $url ...";
my $cont = getobj($url);
unless (defined $cont) {
- print "failed\n";
+ print STDERR "failed\n";
next;
} else {
- print "done\n";
+ print STDERR "done\n";
my @href = gethrefs($url, $cont);
my @munge = map { s[/src\.cgi/][/cgi/]; $_ } @href;
for my $href (@munge) {
- print "** Getting $href ...";
+ print STDERR "** Getting $href ...";
my $file = (split m!/!, $href)[-1];
if (-e $file) {
- print "exists\n";
+ print STDERR "exists\n";
next;
}
- $ua->mirror($href, uri_unescape($file));
- print "done\n";
+ if ($opt{print}) {
+ print "$href\n";
+ } else {
+ $ua->mirror($href, uri_unescape($file));
+ }
+ print STDERR "done\n"
}
- print "done\n";
+ print STDERR "done\n";
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.