File: | blib/lib/Git/ReleaseRepo/Command/init.pm |
Coverage: | 96.2% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package Git::ReleaseRepo::Command::init; | ||||||
2 | # ABSTRACT: Initialize Git::ReleaseRepo | ||||||
3 | |||||||
4 | 2 2 2 | 1590 2 30 | use strict; | ||||
5 | 2 2 2 | 5 1 24 | use warnings; | ||||
6 | 2 2 2 | 4 17 5 | use Moose; | ||||
7 | 2 2 2 | 10141 20506 6 | use MooseX::CoverableModifiers; | ||||
8 | 2 2 2 | 131 2 7 | use Git::ReleaseRepo -command; | ||||
9 | 2 2 2 | 276 0 54 | use Cwd qw( getcwd abs_path ); | ||||
10 | 2 2 2 | 5 1 46 | use File::Spec::Functions qw( catdir catfile ); | ||||
11 | 2 2 2 | 4 1 43 | use File::HomeDir; | ||||
12 | 2 2 2 | 4 0 40 | use File::Path qw( make_path ); | ||||
13 | 2 2 2 | 6 2 100 | use YAML qw( DumpFile ); | ||||
14 | |||||||
15 | sub description { | ||||||
16 | 0 | 1 | 0 | return 'Initialize Git::ReleaseRepo'; | |||
17 | } | ||||||
18 | |||||||
19 | sub validate_args { | ||||||
20 | 6 | 1 | 5540 | my ( $self, $opt, $args ) = @_; | |||
21 | 6 | 20 | if ( !$opt->{version_prefix} ) { | ||||
22 | 1 | 14 | $self->usage_error( "Must have a --version_prefix" ); | ||||
23 | } | ||||||
24 | } | ||||||
25 | |||||||
26 | around opt_spec => sub { | ||||||
27 | 6 | 76898 | my ( $orig, $self ) = @_; | ||||
28 | return ( | ||||||
29 | 6 | 21 | $self->$orig, | ||||
30 | [ 'version_prefix:s' => 'Set the version prefix of the release repository' ], | ||||||
31 | ); | ||||||
32 | }; | ||||||
33 | |||||||
34 | augment execute => sub { | ||||||
35 | my ( $self, $opt, $args ) = @_; | ||||||
36 | my $dir = $self->git->git_dir; | ||||||
37 | my $conf_file = catfile( $dir, 'release' ); | ||||||
38 | if ( -e $conf_file ) { | ||||||
39 | die "Cannot initialize: File '$conf_file' already exists!\n"; | ||||||
40 | } | ||||||
41 | my $repo_conf = {}; | ||||||
42 | for my $conf ( qw( version_prefix ) ) { | ||||||
43 | if ( exists $opt->{$conf} ) { | ||||||
44 | $repo_conf->{$conf} = $opt->{$conf}; | ||||||
45 | } | ||||||
46 | } | ||||||
47 | DumpFile( $conf_file, $repo_conf ); | ||||||
48 | }; | ||||||
49 | |||||||
50 | 1; |