| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Cinnamon::CLI; |
|
2
|
2
|
|
|
2
|
|
310555
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
63
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
46
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
2456
|
use Getopt::Long; |
|
|
2
|
|
|
|
|
24547
|
|
|
|
2
|
|
|
|
|
13
|
|
|
6
|
2
|
|
|
2
|
|
1468
|
use Cinnamon::Context; |
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
79
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
13
|
use constant { SUCCESS => 0, ERROR => 1 }; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1109
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
12
|
|
|
12
|
0
|
73932
|
my $class = shift; |
|
12
|
12
|
|
|
|
|
74
|
bless { }, $class; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub run { |
|
16
|
12
|
|
|
12
|
0
|
39
|
my ($self, @args) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
12
|
|
|
|
|
38
|
local @ARGV = @args; |
|
19
|
12
|
|
|
|
|
125
|
my $p = Getopt::Long::Parser->new( |
|
20
|
|
|
|
|
|
|
config => ["no_ignore_case", "pass_through"], |
|
21
|
|
|
|
|
|
|
); |
|
22
|
12
|
|
|
|
|
1215
|
$p->getoptions( |
|
23
|
|
|
|
|
|
|
"h|help" => \$self->{help}, |
|
24
|
|
|
|
|
|
|
"i|info" => \$self->{info}, |
|
25
|
|
|
|
|
|
|
"c|config=s" => \$self->{config}, |
|
26
|
|
|
|
|
|
|
"s|set=s%" => \$self->{override_settings}, |
|
27
|
|
|
|
|
|
|
"I|ignore-errors" => \$self->{ignore_errors}, |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# --help option |
|
31
|
12
|
100
|
|
|
|
6219
|
if ($self->{help}) { |
|
32
|
1
|
|
|
|
|
5
|
$self->usage; |
|
33
|
1
|
|
|
|
|
13
|
return SUCCESS; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# check config exists |
|
37
|
11
|
|
100
|
|
|
68
|
$self->{config} ||= 'config/deploy.pl'; |
|
38
|
11
|
100
|
|
|
|
224
|
if (!-e $self->{config}) { |
|
39
|
1
|
|
|
|
|
8
|
$self->print("cannot find config file for deploy : $self->{config}\n"); |
|
40
|
1
|
|
|
|
|
5
|
$self->usage; |
|
41
|
1
|
|
|
|
|
15
|
return ERROR; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# check role and task exists |
|
45
|
10
|
|
|
|
|
25
|
my $role = shift @ARGV; |
|
46
|
10
|
|
|
|
|
29
|
my @tasks = @ARGV; |
|
47
|
10
|
50
|
33
|
|
|
99
|
if (!$self->{info} && (!$role || scalar @tasks == 0)) { |
|
|
|
|
66
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$self->print("please specify role and task\n"); |
|
49
|
0
|
|
|
|
|
0
|
$self->usage; |
|
50
|
0
|
|
|
|
|
0
|
return ERROR; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
10
|
100
|
|
|
|
28
|
@tasks = (undef) if (@tasks == 0); |
|
54
|
10
|
|
|
|
|
15
|
my $error_occured = 0; |
|
55
|
10
|
|
|
|
|
274
|
my $context = Cinnamon::Context->new; |
|
56
|
10
|
|
|
|
|
444
|
local $Cinnamon::Context::CTX = $context; |
|
57
|
10
|
|
|
|
|
25
|
for my $task (@tasks) { |
|
58
|
14
|
|
|
|
|
86
|
my ($success, $error) = $context->run( |
|
59
|
|
|
|
|
|
|
$role, |
|
60
|
|
|
|
|
|
|
$task, |
|
61
|
|
|
|
|
|
|
config => $self->{config}, |
|
62
|
|
|
|
|
|
|
override_settings => $self->{override_settings}, |
|
63
|
|
|
|
|
|
|
info => $self->{info}, |
|
64
|
|
|
|
|
|
|
); |
|
65
|
14
|
100
|
|
|
|
55
|
last if ($self->{info}); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# check execution error |
|
68
|
13
|
|
100
|
|
|
51
|
$error_occured ||= ! defined $success; |
|
69
|
13
|
|
100
|
|
|
46
|
$error_occured ||= scalar @$error > 0; |
|
70
|
|
|
|
|
|
|
|
|
71
|
13
|
100
|
100
|
|
|
56
|
last if ($error_occured && !$self->{ignore_errors}); |
|
72
|
11
|
|
|
|
|
216
|
print "\n"; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
10
|
100
|
|
|
|
159
|
return $error_occured ? ERROR : SUCCESS; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub usage { |
|
79
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
|
80
|
2
|
|
|
|
|
4
|
my $msg = <<"HELP"; |
|
81
|
|
|
|
|
|
|
Usage: cinnamon [--config=] [--set=] [--ignore-errors] [--help] [--info] |
|
82
|
|
|
|
|
|
|
HELP |
|
83
|
2
|
|
|
|
|
9
|
$self->print($msg); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub print { |
|
87
|
3
|
|
|
3
|
0
|
5
|
my ($self, $msg) = @_; |
|
88
|
3
|
|
|
|
|
164
|
print STDERR $msg; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
!!1; |