Commit | Line | Data |
c6b7b384 |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings FATAL => 'all'; |
4 | use Getopt::Long qw(:config gnu_getopt); |
5 | GetOptions( |
6 | "p|prefix=s@" => \(my $prefix = []), |
7 | "s|suffix=s@" => \(my $suffix = []), |
8 | ) or die "Error in command line arguments\n"; |
9 | |
10 | my $version = shift or die "no version specified!\n"; |
11 | my $changelog = @ARGV ? shift : 'Changes'; |
12 | |
13 | $version =~ s/\Av//; |
14 | |
15 | open my $fh, '<:raw', $changelog |
16 | or die "can't open $changelog: $!\n"; |
17 | my $version_log = ''; |
18 | my $found_version; |
19 | while (my $line = <$fh>) { |
20 | if ($found_version) { |
21 | last |
22 | if $line =~ /^\S/; |
23 | $version_log .= $line; |
24 | } |
25 | elsif ($line =~ /^v?\Q$version\E/) { |
26 | $found_version = 1; |
27 | } |
28 | } |
29 | close $fh; |
30 | die "couldn't find heading for $version in $changelog!\n" |
31 | unless $found_version; |
32 | |
33 | $version_log =~ s/\r\n?/\n/g; |
34 | $version_log =~ s/\n+\z//; |
35 | |
36 | s/\n\z// |
37 | for @$prefix, @$suffix; |
38 | |
39 | print join("\n\n", @$prefix, $version_log, @$suffix) . "\n"; |