File: tidy_changelog

package info (click to toggle)
libcpan-changes-perl 0.400002-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 324 kB
  • ctags: 41
  • sloc: perl: 509; makefile: 2
file content (103 lines) | stat: -rwxr-xr-x 2,111 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl

use CPAN::Changes;

use Getopt::Long qw(GetOptions);
use Pod::Usage   qw(pod2usage);

GetOptions( \my %opt,
   'next!',
   'token:s',
   'headers!',
   'reverse',
   'check',
   'help',
) or pod2usage( -verbose => 2 );
pod2usage( -verbose => 2 ) if $opt{help};

$opt{token} ||= qr/\{\{\$NEXT\}\}/;

my $changelog = shift;

unless ( $changelog ) {
    # try to guess it
    opendir my $dir, '.';
    my @files = grep { -f $_ and /^change/i } readdir $dir;
    die "changelog not provided and couldn't be guessed\n"
        unless @files == 1;

    $changelog = shift @files;
    warn "changelog not provided, guessing '$changelog'\n\n";
}

if ($opt{check}) {
    require Test::CPAN::Changes;
    require Test::More;
    Test::CPAN::Changes::changes_file_ok();
    exit;
}

my $changes = CPAN::Changes->load(
    $changelog,
    ( next_token => $opt{token} ) x $opt{next},
);

if( $opt{headers} ) {
    $_->clear_changes for $changes->releases;
}

print $changes->serialize(
    reverse => $opt{reverse},
);

__END__

=head1 NAME

tidy_changelog - command-line tool for CPAN::Changes

=head1 SYNOPSIS

    $ tidy_changelog Changelog

=head1 DESCRIPTION

Takes a changelog file, parse it using L<CPAN::Changes> and prints out
the resulting output.  If a file is not given, the program will see if
there is one file in the current directory beginning by 'change'
(case-insensitive) and, if so, assume it to be the changelog.

=head1 ARGUMENTS

=head2 --next

If provided, assumes that there is a placeholder
header for an upcoming next release. The placeholder token
is given via I<--token>.

=head2 --token

Regular expression to use to detect the token for an upcoming
release if I<--next> is used. If not explicitly given, defaults
to C<\{\{\$NEXT\}\}>.

=head2 --headers

If given, only print out the release header lines, without any of the
changes.

=head2 --reverse

Prints the releases in reverse order (from the oldest to latest).


=head2 --check

Only check if the changelog is formatted properly using the changes_file_ok
function of L<Test::CPAN::Changes>.


=head2 --help

This help