File Coverage

blib/lib/Shipwright/Script.pm
Criterion Covered Total %
statement 33 37 89.1
branch 11 18 61.1
condition 4 6 66.6
subroutine 9 9 100.0
pod 4 4 100.0
total 61 74 82.4


line stmt bran cond sub pod time code
1             package Shipwright::Script;
2 2     2   18636 use strict;
  2         2  
  2         72  
3 2     2   8 use warnings;
  2         2  
  2         38  
4 2     2   877 use App::CLI;
  2         25212  
  2         36  
5 2     2   447 use Shipwright::Util;
  2         4  
  2         203  
6 2     2   12 use base qw/App::CLI Shipwright::Base/;
  2         3  
  2         921  
7              
8             __PACKAGE__->mk_accessors(qw/repository log_file log_level/);
9              
10             =head2 alias
11             =cut
12              
13             sub alias {
14             return (
15 9     9 1 3711 ls => 'list',
16             del => 'delete',
17             up => 'update',
18             init => 'create',
19             initialize => 'create',
20             );
21             }
22              
23             =head2 global_options
24              
25             =cut
26              
27             sub global_options {
28             (
29 8     8 1 71 'r|repository=s' => 'repository',
30             'l|log-level=s' => 'log_level',
31             'log-file=s' => 'log_file',
32             );
33             }
34              
35             =head2 prepare
36             =cut
37              
38             sub prepare {
39 8     8 1 3229 my $self = shift;
40 8 100       28 $ARGV[0] = 'help' unless @ARGV;
41              
42 8 100       46 if ( $ARGV[0] =~ /--?h(elp)?/i ) {
    50          
43 2         4 $ARGV[0] = 'help';
44             }
45             elsif ( $ARGV[0] =~ /^(-v|--version|version)$/ ) {
46 0         0 print( "This is Shipwright, version $Shipwright::VERSION" . "\n" );
47 0         0 exit 0;
48             }
49              
50 8         9 my $action = $ARGV[0];
51              
52 8         40 my $cmd = $self->SUPER::prepare(@_);
53              
54 6 100       1318 unless ( ref $cmd eq 'Shipwright::Script::Help' ) {
55 3 50 66     28 $cmd->repository( $ENV{SHIPWRIGHT_SHIPYARD} )
56             if !$cmd->repository && $ENV{SHIPWRIGHT_SHIPYARD};
57 3 50 66     15 $cmd->repository( $ENV{SHIPWRIGHT_REPOSITORY} )
58             if !$cmd->repository && $ENV{SHIPWRIGHT_REPOSITORY};
59 3 100       11 if ( $cmd->repository ) {
60 2         536 require Shipwright::Backend;
61 2         24 my $backend = Shipwright::Backend->new(
62             repository => $cmd->repository,
63             no_sync_local_dir => 1,
64             );
65              
66             # this $shipwright object will do nothing, except for init logging
67 0         0 my $shipwright = Shipwright->new(
68             repository => $cmd->repository,
69             log_level => $cmd->log_level,
70             log_file => $cmd->log_file,
71             );
72 0 0       0 confess_or_die 'invalid repository: '
    0          
73             . $cmd->repository
74             unless $backend->check_repository(
75             action => $action,
76             $action eq 'create' ? ( force => $cmd->force ) : ()
77             );
78             }
79             else {
80 1         5 confess_or_die "need repository arg\n";
81             }
82             }
83 3         8 return $cmd;
84             }
85              
86             =head2 log
87             =cut
88              
89             sub log {
90 1     1 1 3 my $self = shift;
91              
92             # init logging is done in prepare, no need to init here, just returns logger
93 1         7 return Log::Log4perl->get_logger( ref $self );
94             }
95              
96             1;
97              
98             __END__