| 1 | package Dist::Zilla::App::Command::distversion; | ||
| 2 | use Capture::Tiny qw/capture capture_stdout/; | ||
| 3 | use Sort::Naturally qw/nsort/; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | our $VERSION = '0.03'; | ||
| 9 | |||
| 10 | use Dist::Zilla::App -command; | ||
| 11 | |||
| 12 | sub abstract { "Prints your dist version on the command line" } | ||
| 13 | sub description { "Asks dzil what version the dist is on, then prints that" } | ||
| 14 | sub usage_desc { "%c" } | ||
| 15 | sub opt_spec { ( | ||
| 16 | [ rc => "Produce a release candidate version" ] | ||
| 17 | ) } | ||
| 18 | sub execute { | ||
| 19 | my $self = shift; | ||
| 20 | my $opt = shift; | ||
| 21 | |||
| 22 | # Something might output. | ||
| 23 | capture { | ||
| 24 | # https://metacpan.org/source/RJBS/Dist-Zilla-6.010/lib/Dist/Zilla/Dist/Builder.pm#L344,348-352 | ||
| 25 | $_->before_build for @{ $self->zilla->plugins_with(-BeforeBuild) }; | ||
| 26 | $_->gather_files for @{ $self->zilla->plugins_with(-FileGatherer) }; | ||
| 27 | $_->set_file_encodings for @{ $self->zilla->plugins_with(-EncodingProvider) }; | ||
| 28 | $_->prune_files for @{ $self->zilla->plugins_with(-FilePruner) }; | ||
| 29 | |||
| 30 | $self->zilla->version; | ||
| 31 | }; | ||
| 32 | |||
| 33 | my $distver = $self->zilla->version; | ||
| 34 | if ($opt->{rc}) { | ||
| 35 | # TODO: configure this | ||
| 36 | my @tags = split /\n/, capture_stdout { system qw/git tag/ }; | ||
| 37 | my @relevant = grep /^v$distver/, @tags; | ||
| 38 | |||
| 39 | if (grep /^v$distver$/, @relevant) { | ||
| 40 | warn "$distver appears to already have a release tag\n"; | ||
| 41 | } | ||
| 42 | |||
| 43 | my $currc = 1; | ||
| 44 | if (my $latest = (nsort @relevant)[-1]) { | ||
| 45 | ($currc) = $latest =~ /-rc(\d+)$/; | ||
| 46 | $currc++; | ||
| 47 | } | ||
| 48 | print "$distver-rc$currc\n"; | ||
| 49 | } | ||
| 50 | else { | ||
| 51 | print $distver, "\n"; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 | |||
| 57 | =head1 NAME | ||
| 58 | |||
| 59 | Dist::Zilla::App::Command::distversion - report your dist version | ||
| 60 | |||
| 61 | =head1 DESCRIPTION | ||
| 62 | |||
| 63 | Tries to output the current version of your distribution onto stdout | ||
| 64 | |||
| 65 | =head1 SYNOPSIS | ||
| 66 | |||
| 67 | $ dzil distversion | ||
| 68 | 0.01 | ||
| 69 | |||
| 70 | $ dzil distversion --rc | ||
| 71 | 0.01-rc1 | ||
| 72 | |||
| 73 | =head1 OPTIONS | ||
| 74 | |||
| 75 | =head2 rc | ||
| 76 | |||
| 77 | Produce a release candidate version. This is defined as your dist version with | ||
| 78 | the suffix C<-rcN>, where N is either 1, or 1 more than the previous RC version. | ||
| 79 | |||
| 80 | Since dzil doesn't care about the output of this module, nor tracks RC versions | ||
| 81 | for you, the module currently looks for git tags matching your dist version. | ||
| 82 | Later, this will be configurable. Any tag matching /^v$distversion-rc(\d+)/ is | ||
| 83 | considered a release candidate tag, and if none is found, we use 1. | ||
| 84 | |||
| 85 | Any tag matching /^v$distversion/ is considered a problem and we emit a warning. |