Dist-Zilla-App-Command-distversion

 view release on metacpan or  search on metacpan

lib/Dist/Zilla/App/Command/distversion.pm  view on Meta::CPAN

package Dist::Zilla::App::Command::distversion;
use Capture::Tiny qw/capture capture_stdout/;
use Sort::Naturally qw/nsort/;

use strict;
use warnings;

our $VERSION = '0.03';

use Dist::Zilla::App -command;

sub abstract    { "Prints your dist version on the command line" }
sub description { "Asks dzil what version the dist is on, then prints that" }
sub usage_desc  { "%c" }
sub opt_spec    { (
    [ rc => "Produce a release candidate version" ]
) }
sub execute {
    my $self = shift;
    my $opt = shift;

    # Something might output.
    capture {
        # https://metacpan.org/source/RJBS/Dist-Zilla-6.010/lib/Dist/Zilla/Dist/Builder.pm#L344,348-352
        $_->before_build       for @{ $self->zilla->plugins_with(-BeforeBuild) };
        $_->gather_files       for @{ $self->zilla->plugins_with(-FileGatherer) };
        $_->set_file_encodings for @{ $self->zilla->plugins_with(-EncodingProvider) };
        $_->prune_files        for @{ $self->zilla->plugins_with(-FilePruner) };

        $self->zilla->version;
    };

    my $distver = $self->zilla->version;
    if ($opt->{rc}) {
        # TODO: configure this
        my @tags = split /\n/, capture_stdout { system qw/git tag/ };
        my @relevant = grep /^v$distver/, @tags;

        if (grep /^v$distver$/, @relevant) {
            warn "$distver appears to already have a release tag\n";
        }

        my $currc = 1;
        if (my $latest = (nsort @relevant)[-1]) {
            ($currc) = $latest =~ /-rc(\d+)$/;
            $currc++;
        }
        print "$distver-rc$currc\n";
    }
    else {
        print $distver, "\n";
    }
}

1;

=head1 NAME

Dist::Zilla::App::Command::distversion - report your dist version

=head1 DESCRIPTION

Tries to output the current version of your distribution onto stdout



( run in 1.428 second using v1.01-cache-2.11-cpan-524268b4103 )