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