lib/WWW/Hetzner/Robot/CLI/Cmd/Boot/Cmd/Linux.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 50.0% 13 / 26 Conditioncond 45.4% 5 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 70.2% 66 / 94 CC 19 SCAR 24.7
CC
19
Cov
74%
execute
15.5
_print_install
11.1
BEGIN
1.0
CRAP 11.9
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Subaccount/Cmd/Update.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Iso.pm »
1 package WWW::Hetzner::Robot::CLI::Cmd::Boot::Cmd::Linux;
2 # ABSTRACT: Linux installation boot configuration
3  
4 1 our $VERSION = '0.102';
5  
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooX::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MooX::Options protect_argv => 0, usage_string => 'USAGE: hrobot.pl boot linux <server-number> [--enable --dist <dist> --lang <lang> | --disable]';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 1 option enable => (
12 is => 'ro',
13 short => 'e',
14 doc => 'Activate the Linux installation',
15 default => 0,
16 );
17  
18 1 option disable => (
19 is => 'ro',
20 short => 'd',
21 doc => 'Deactivate the Linux installation',
22 default => 0,
23 );
24  
25 1 option dist => (
26 is => 'ro',
27 format => 's',
28 doc => 'Distribution to install - required with --enable',
29 );
30  
31 1 option lang => (
32 is => 'ro',
33 format => 's',
34 doc => 'Installation language - required with --enable',
35 );
36  
37 1 option key => (
38 is => 'ro',
39 format => 's@',
40 doc => 'Authorized SSH key fingerprint (repeatable)',
41 autosplit => ',',
42 );
43  
44 2 ▶sub execute {
Subroutine execute: called CC=11 SCAR=27.4
Pod undocumented
45 2 my ($self, $args, $chain) = @_;
46 2 my $root = $chain->[0];
47 2 my $robot = $root->robot;
48  
49 2 ▶ my $server_number = $args->[0]
Branch: 1 branch
BranchTrueFalseTotal
my $server_number = $args->[0] or die "Usage: hrobot.pl boot linux <server-number> [--enable --dist <dist> --lang <lang> | --disable]\n" 2 0 2
50 or die "Usage: hrobot.pl boot linux <server-number> [--enable --dist <dist> --lang <lang> | --disable]\n";
51  
52 2 ▶ die "--enable and --disable are mutually exclusive\n"
Branch: 1 branch
BranchTrueFalseTotal
if $self->enable and $self->disable 0 2 2
Condition33%1/3
$self->enable and $self->disable
!ll&&!rl&&r
020
MC/DC0%0/2
$self->enable and $self->disable
$self->enable $self->disable
Truth table33%1/3
A and B
A= $self->enableB= $self->disable
ABresult
0X0
100
111
53 if $self->enable && $self->disable;
54  
55 2 my $linux;
56 2 ▶ if ($self->enable) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->enable) { } 2 0 2
elsif ($self->disable) { } 0 0 0
57 2 ▶ die "--dist is required with --enable\n" unless $self->dist;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dist 0 2 2
58 2 ▶ die "--lang is required with --enable\n" unless $self->lang;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->lang 0 2 2
59 2 ▶ $linux = $robot->boot->enable_linux(
Branch: 1 branch
BranchTrueFalseTotal
$self->key ? : 0 2 2
60 $server_number,
61 dist => $self->dist,
62 lang => $self->lang,
63 ($self->key ? (authorized_key => $self->key) : ()),
64 );
65 } elsif ($self->disable) {
66 0 $linux = $robot->boot->disable_linux($server_number);
67 } else {
68 0 $linux = $robot->boot->linux($server_number);
69 }
70  
71 2 ▶ if ($root->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($root->output eq 'json') { } 1 1 2
72 1 require JSON::MaybeXS;
73 1 print JSON::MaybeXS::encode_json($linux);
74 1 print "\n";
75 } else {
76 1 _print_install($linux);
77 1 ▶ print "\nReset the server to start the installation.\n" if $self->enable;
Branch: 1 branch
BranchTrueFalseTotal
if $self->enable 1 0 1
78 }
79 }
80  
81 1 ▶sub _print_install {
Subroutine _print_install: called CC=9 SCAR=24.1
82 1 my ($i) = @_;
83 1 my $dist = $i->{dist};
84 1 ▶ $dist = join(', ', @$dist) if ref $dist eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $dist eq "ARRAY" 0 1 1
85 1 my $lang = $i->{lang};
86 1 ▶ $lang = join(', ', @$lang) if ref $lang eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $lang eq "ARRAY" 0 1 1
87 1 ▶ print "Server Number: ", $i->{server_number} // '', "\n";
Condition50%1/2
$i->{"server_number"} // ""
l!l
10
MC/DC0%0/1
$i->{"server_number"} // ""
$i->{"server_number"}
Truth table50%1/2
A
A= $i->{"server_number"}
Aresult
11
00
88 1 ▶ print "Server IP: ", $i->{server_ip} // '', "\n";
Condition50%1/2
$i->{"server_ip"} // ""
l!l
10
MC/DC0%0/1
$i->{"server_ip"} // ""
$i->{"server_ip"}
Truth table50%1/2
A
A= $i->{"server_ip"}
Aresult
11
00
89 1 ▶ print "Active: ", $i->{active} ? 'yes' : 'no', "\n";
Branch: 1 branch
BranchTrueFalseTotal
$i->{'active'} ? : 1 0 1
90 1 ▶ print "Dist: ", $dist // '', "\n";
Condition50%1/2
$dist // ""
l!l
10
MC/DC0%0/1
$dist // ""
$dist
Truth table50%1/2
A
A= $dist
Aresult
11
00
91 1 ▶ print "Lang: ", $lang // '', "\n";
Condition50%1/2
$lang // ""
l!l
10
MC/DC0%0/1
$lang // ""
$lang
Truth table50%1/2
A
A= $lang
Aresult
11
00
92 1 ▶ print "Password: ", $i->{password}, "\n" if defined $i->{password};
Branch: 1 branch
BranchTrueFalseTotal
if defined $i->{"password"} 1 0 1
93 }
94  
95 1 1.
96  
97 __END__
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Subaccount/Cmd/Update.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Iso.pm »