| 1 | package Cinnamon::CLI; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Cinnamon::Context; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use constant { SUCCESS => 0, ERROR => 1 }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | bless { }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=15 SCAR=27.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | 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 | 12 | ); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # --help option | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 12 | ▶ | if ($self->{help}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $self->usage; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | return SUCCESS; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # check config exists | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 11 | ▶ | $self->{config} ||= 'config/deploy.pl'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"config"} ||= "config/deploy.pl"
MC/DC100%1/1
$self->{"config"} ||= "config/deploy.pl"
$self->{"config"}
Truth table100%2/2
A
A= $self->{"config"}
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 11 | ▶ | if (!-e $self->{config}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | $self->print("cannot find config file for deploy : $self->{config}\n"); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | $self->usage; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | return ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # check role and task exists | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 10 | my $role = shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 10 | my @tasks = @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | ▶ | if (!$self->{info} && (!$role || scalar @tasks == 0)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not $self->{"info"} and !$role || scalar @tasks == 0
not $role or scalar @tasks == 0
MC/DC0%0/3
not $self->{"info"} and !$role || scalar @tasks == 0
not $self->{"info"}
not $role
scalar @tasks == 0
Truth table50%2/4
not(A) and not(B) or C
A= not $self->{"info"}B= not $roleC= scalar @tasks == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $self->print("please specify role and task\n"); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $self->usage; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 10 | ▶ | @tasks = (undef) if (@tasks == 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | my $error_occured = 0; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 10 | my $context = Cinnamon::Context->new; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 10 | local $Cinnamon::Context::CTX = $context; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | 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 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 14 | ▶ | last if ($self->{info}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # check execution error | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 13 | ▶ | $error_occured ||= ! defined $success; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$error_occured ||= !defined($success)
MC/DC100%2/2
$error_occured ||= !defined($success)
$error_occured
!defined($success)
Truth table100%3/3
A ||= not(B)
A= $error_occuredB= !defined($success)
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | ▶ | $error_occured ||= scalar @$error > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$error_occured ||= scalar @$error > 0
MC/DC100%2/2
$error_occured ||= scalar @$error > 0
$error_occured
scalar @$error > 0
Truth table100%3/3
A ||= B
A= $error_occuredB= scalar @$error > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 13 | ▶ | last if ($error_occured && !$self->{ignore_errors}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$error_occured and not $self->{"ignore_errors"}
MC/DC100%2/2
$error_occured and not $self->{"ignore_errors"}
$error_occured
not $self->{"ignore_errors"}
Truth table100%3/3
A and not(B)
A= $error_occuredB= not $self->{"ignore_errors"}
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 11 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | ▶ | return $error_occured ? ERROR : SUCCESS; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | my $msg = <<"HELP"; | |||||||||||||||||||||||||||||||||||||||||
| 81 | Usage: cinnamon [--config=<path>] [--set=<parameter>] [--ignore-errors] [--help] [--info] <role> <task ...> | ||||||||||||||||||||||||||||||||||||||||||
| 82 | HELP | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | $self->print($msg); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | sub print { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | print STDERR $msg; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | !!1; | |||||||||||||||||||||||||||||||||||||||||