line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
2979
|
use v5.14.0; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
112
|
|
2
|
3
|
|
|
3
|
|
11
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
164
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package OS::Package::CLI; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: OS::Package application initialization. |
7
|
|
|
|
|
|
|
our $VERSION = '0.2.6'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
2997
|
use English qw(-no_match_vars); |
|
3
|
|
|
|
|
4862
|
|
|
3
|
|
|
|
|
11
|
|
10
|
3
|
|
|
3
|
|
2737
|
use Env qw( $HOME ); |
|
3
|
|
|
|
|
4106
|
|
|
3
|
|
|
|
|
16
|
|
11
|
3
|
|
|
3
|
|
444
|
use File::Basename; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
177
|
|
12
|
3
|
|
|
3
|
|
2234
|
use Getopt::Long; |
|
3
|
|
|
|
|
27835
|
|
|
3
|
|
|
|
|
16
|
|
13
|
3
|
|
|
3
|
|
1198
|
use OS::Package::Application; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
114
|
|
14
|
3
|
|
|
3
|
|
835
|
use OS::Package::Config qw($OSPKG_CONFIG); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use OS::Package::Factory; |
16
|
|
|
|
|
|
|
use OS::Package::Init; |
17
|
|
|
|
|
|
|
use OS::Package::Log; |
18
|
|
|
|
|
|
|
use Path::Tiny; |
19
|
|
|
|
|
|
|
use Pod::Usage; |
20
|
|
|
|
|
|
|
use Try::Tiny; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub run { |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my ( $COMMAND, $APP, %OPT ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
GetOptions( \%OPT, 'build_id|b=s', 'config_dir|c=s', 'pkg_dir|p=s' ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$COMMAND = shift @ARGV; |
29
|
|
|
|
|
|
|
$APP = shift @ARGV; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if ( !defined $COMMAND ) { |
32
|
|
|
|
|
|
|
$LOGGER->warn('please tell me what to do'); |
33
|
|
|
|
|
|
|
exit; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if ( $COMMAND =~ m{^(help|--help|-h)$} ) { |
37
|
|
|
|
|
|
|
pod2usage( |
38
|
|
|
|
|
|
|
-exitstatus => '1', |
39
|
|
|
|
|
|
|
-message => 'See --man for full documentation' |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif ( $COMMAND =~ m{^(man|--man|-m)$} ) { |
43
|
|
|
|
|
|
|
pod2usage( -exitstatus => '0', -verbose => 2 ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif ( $COMMAND =~ m{^(version|--version|-v)$} ) { |
46
|
|
|
|
|
|
|
printf "%s %s\n", basename($PROGRAM_NAME), $VERSION; |
47
|
|
|
|
|
|
|
exit; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if ( defined $OPT{config_dir} ) { |
51
|
|
|
|
|
|
|
$OSPKG_CONFIG->dir->configs( $OPT{config_dir} ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
if ( defined $OPT{pkg_dir} ) { |
55
|
|
|
|
|
|
|
$OSPKG_CONFIG->dir->packages( $OPT{pkg_dir} ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if ( $COMMAND eq 'init' ) { |
59
|
|
|
|
|
|
|
init_ospkg; |
60
|
|
|
|
|
|
|
$LOGGER->info( sprintf 'put configs in %s', |
61
|
|
|
|
|
|
|
$OSPKG_CONFIG->dir->configs ); |
62
|
|
|
|
|
|
|
exit; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
if ( !path( $OSPKG_CONFIG->dir->base )->exists ) { |
66
|
|
|
|
|
|
|
$LOGGER->info('initializing'); |
67
|
|
|
|
|
|
|
init_ospkg; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
if ( !defined $APP ) { |
71
|
|
|
|
|
|
|
$LOGGER->warn('missing app'); |
72
|
|
|
|
|
|
|
exit; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $app = { name => $APP }; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$LOGGER = Log::Log4perl->get_logger( $app->{name} ); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
if ( defined $OPT{build_id} ) { |
80
|
|
|
|
|
|
|
$app->{build_id} = $OPT{build_id}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $pkg = vivify($app); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$LOGGER->info( sprintf 'processing: %s %s', $pkg->name, $pkg->application->version ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
if ( $COMMAND eq 'download' ) { |
88
|
|
|
|
|
|
|
$pkg->artifact->download; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
elsif ( $COMMAND eq 'extract' ) { |
92
|
|
|
|
|
|
|
$pkg->artifact->extract; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ( $COMMAND eq 'build' ) { |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
if ( defined $pkg->artifact ) { |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$pkg->artifact->download |
99
|
|
|
|
|
|
|
|| ( $LOGGER->fatal('download failed') && die ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$pkg->artifact->extract |
102
|
|
|
|
|
|
|
|| ( $LOGGER->fatal('extract failed') && die ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$pkg->build || ( $LOGGER->fatal('build failed') && die ); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$pkg->prune || ( $LOGGER->fatal('prune failed') && die ); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$pkg->create || ( $LOGGER->fatal('create failed') && die ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ( $COMMAND eq 'prune' ) { |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$pkg->application->prune; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif ( $COMMAND eq 'clean' ) { |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$pkg->clean; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |