line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cinnamon::CLI; |
2
|
2
|
|
|
2
|
|
335948
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
43
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
46
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
2153
|
use Getopt::Long; |
|
2
|
|
|
|
|
20991
|
|
|
2
|
|
|
|
|
10
|
|
6
|
2
|
|
|
2
|
|
1470
|
use Cinnamon::Context; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { SUCCESS => 0, ERROR => 1 }; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
my $class = shift; |
12
|
|
|
|
|
|
|
bless { }, $class; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub run { |
16
|
|
|
|
|
|
|
my ($self, @args) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
local @ARGV = @args; |
19
|
|
|
|
|
|
|
my $p = Getopt::Long::Parser->new( |
20
|
|
|
|
|
|
|
config => ["no_ignore_case", "pass_through"], |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
if ($self->{help}) { |
32
|
|
|
|
|
|
|
$self->usage; |
33
|
|
|
|
|
|
|
return SUCCESS; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# check config exists |
37
|
|
|
|
|
|
|
$self->{config} ||= 'config/deploy.pl'; |
38
|
|
|
|
|
|
|
if (!-e $self->{config}) { |
39
|
|
|
|
|
|
|
$self->print("cannot find config file for deploy : $self->{config}\n"); |
40
|
|
|
|
|
|
|
$self->usage; |
41
|
|
|
|
|
|
|
return ERROR; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# check role and task exists |
45
|
|
|
|
|
|
|
my $role = shift @ARGV; |
46
|
|
|
|
|
|
|
my @tasks = @ARGV; |
47
|
|
|
|
|
|
|
if (!$self->{info} && (!$role || scalar @tasks == 0)) { |
48
|
|
|
|
|
|
|
$self->print("please specify role and task\n"); |
49
|
|
|
|
|
|
|
$self->usage; |
50
|
|
|
|
|
|
|
return ERROR; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
@tasks = (undef) if (@tasks == 0); |
54
|
|
|
|
|
|
|
my $error_occured = 0; |
55
|
|
|
|
|
|
|
my $context = Cinnamon::Context->new; |
56
|
|
|
|
|
|
|
local $Cinnamon::Context::CTX = $context; |
57
|
|
|
|
|
|
|
for my $task (@tasks) { |
58
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
last if ($self->{info}); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# check execution error |
68
|
|
|
|
|
|
|
$error_occured ||= ! defined $success; |
69
|
|
|
|
|
|
|
$error_occured ||= scalar @$error > 0; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
last if ($error_occured && !$self->{ignore_errors}); |
72
|
|
|
|
|
|
|
print "\n"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $error_occured ? ERROR : SUCCESS; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub usage { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
my $msg = <<"HELP"; |
81
|
|
|
|
|
|
|
Usage: cinnamon [--config=] [--set=] [--ignore-errors] [--help] [--info] |
82
|
|
|
|
|
|
|
HELP |
83
|
|
|
|
|
|
|
$self->print($msg); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub print { |
87
|
|
|
|
|
|
|
my ($self, $msg) = @_; |
88
|
|
|
|
|
|
|
print STDERR $msg; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
!!1; |