die with missing old version
[p5sagit/Distar.git] / helpers / bump-version
index 5244750..5373656 100755 (executable)
@@ -3,18 +3,28 @@
 use strict;
 use warnings FATAL => 'all';
 use File::Find;
-use Getopt::Long qw(:config gnu_compat);
+use Getopt::Long qw(:config gnu_getopt);
 use File::Temp ();
 
 GetOptions(
   "git"     => \my $git,
+  "force"   => \my $force,
 ) or die("Error in command line arguments\n");
 
-my ($old_version, $bump) = @ARGV;
+my $old_version = shift
+  or die "no old version provided!\n";
+my $bump = shift;
 my ($new_decimal, $new_vstring) = bump_version($old_version, $bump);
 
 warn "Bumping $old_version -> $new_decimal\n";
 
+my $file_match = qr{^(?:
+  Makefile\.PL
+  |lib[/\\].*\.(?:pod|pm)
+  |bin[/\\].*
+  |script[/\\].*
+)$}x;
+
 my %files;
 if ($git) {
   if (system "git diff --quiet --cached HEAD") {
@@ -23,7 +33,7 @@ if ($git) {
   for (`git ls-files`) {
     chomp;
     next
-      unless /^lib\/.*\.(?:pod|pm)$/ || /^Makefile\.PL$/;
+      unless /$file_match/;
     $files{$_} = `git show HEAD:"$_"`;
   }
 }
@@ -34,13 +44,13 @@ else {
       next
         unless -f;
       next
-        unless /^lib\/.*\.(?:pod|pm)$/ || /^Makefile\.PL$/;
+        unless /(?:\.[\/\\])?$file_match/;
       open my $fh, '<', $_
         or die "can't open $_: $!";
       $files{$_} = do { local $/; <$fh> };
       close $fh;
     },
-  }, 'lib');
+  }, '.');
 }
 
 my $FILE_RE = qr{
@@ -54,7 +64,7 @@ my $FILE_RE = qr{
   (.*)$
 }x;
 my $MAKE_RE = qr{
-  (^.* version \s* => \s* )
+  (^.* ['"]?version['"] \s* => \s* )
   (['"]?) v?([0-9]+(?:[._][0-9]+)*) \2
   ( \s*, )
   (?:
@@ -74,7 +84,7 @@ for my $file (sort keys %files) {
     my $line = $lines[$ln];
     if ($lines[$ln] =~ $re) {
       die "unable to bump version number in $file from $old_version, found $3\n"
-        if $3 ne $old_version;
+        if !$force && $3 ne $old_version;
       my $comment = ($5 ? $5 . $new_vstring : '');
       my $new_line = "$1'$new_decimal'$4$comment$6";
       $file_diff .= <<"END_DIFF";