File: | blib/lib/Git/ReleaseRepo/CreateCommand.pm |
Coverage: | 74.4% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package Git::ReleaseRepo::CreateCommand; | ||||||
2 | # ABSTRACT: Base class for commands that have to create a new repository | ||||||
3 | |||||||
4 | 2 2 2 | 1737 1 29 | use strict; | ||||
5 | 2 2 2 | 4 2 21 | use warnings; | ||||
6 | 2 2 2 | 4 2 5 | use Moose; | ||||
7 | extends 'Git::ReleaseRepo::Command'; | ||||||
8 | 2 2 2 | 7159 2 54 | use File::Spec::Functions qw( catfile ); | ||||
9 | 2 2 2 | 4 2 273 | use YAML qw( LoadFile DumpFile ); | ||||
10 | |||||||
11 | sub update_config { | ||||||
12 | 3 | 0 | 12 | my ( $self, $opt, $repo, $extra ) = @_; | |||
13 | 3 | 18 | my $config_file = catfile( $repo->git_dir, 'release' ); | ||||
14 | 3 | 150 | my $config = -f $config_file ? LoadFile( $config_file ) : {}; | ||||
15 | |||||||
16 | 3 | 7 | for my $conf ( qw( version_prefix ) ) { | ||||
17 | 3 | 12 | if ( exists $opt->{$conf} ) { | ||||
18 | 3 | 11 | $config->{$conf} = $opt->{$conf}; | ||||
19 | } | ||||||
20 | } | ||||||
21 | |||||||
22 | 3 | 12 | $config = { %$config, %$extra }; | ||||
23 | 3 | 21 | DumpFile( $config_file, $config ); | ||||
24 | } | ||||||
25 | |||||||
26 | sub validate_args { | ||||||
27 | 0 | 1 | my ( $self, $opt, $args ) = @_; | ||||
28 | 0 | $self->usage_error( "Must give a repository URL!" ) if ( @$args < 1 ); | |||||
29 | 0 | $self->usage_error( "Too many arguments" ) if ( @$args > 2 ); | |||||
30 | } | ||||||
31 | |||||||
32 | around opt_spec => sub { | ||||||
33 | my ( $orig, $self ) = @_; | ||||||
34 | return ( | ||||||
35 | $self->$orig, | ||||||
36 | [ 'version_prefix:s' => 'Set the version prefix of the release repository' ], | ||||||
37 | ); | ||||||
38 | }; | ||||||
39 | |||||||
40 | 1; |