line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
1522
|
use v5.14.0; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
102
|
|
2
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
127
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package OS::Package::CLI; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: OS::Package application initialization. |
7
|
|
|
|
|
|
|
our $VERSION = '0.2.5'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1337
|
use English qw(-no_match_vars); |
|
3
|
|
|
|
|
4993
|
|
|
3
|
|
|
|
|
12
|
|
10
|
3
|
|
|
3
|
|
2963
|
use Env qw( $HOME ); |
|
3
|
|
|
|
|
5796
|
|
|
3
|
|
|
|
|
12
|
|
11
|
3
|
|
|
3
|
|
452
|
use File::Basename; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
165
|
|
12
|
3
|
|
|
3
|
|
1946
|
use Getopt::Long; |
|
3
|
|
|
|
|
24518
|
|
|
3
|
|
|
|
|
10
|
|
13
|
3
|
|
|
3
|
|
878
|
use OS::Package::Application; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use OS::Package::Config qw($OSPKG_CONFIG); |
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->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__ |