Helm/Task/run.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 46 CC 3 SCAR 13.9
CC
3
Cov
0%
validate
6.0
help
6.0
execute
2.0
CRAP 4.0
1 package Helm::Task::run;
2 use strict;
3 use warnings;
4 use Moose;
5  
6 extends 'Helm::Task';
7 has command => (is => 'ro', writer => '_command', isa => 'Str');
8  
9 sub validate {
10 my $self = shift;
11 my $helm = $self->helm;
12 my $cmd = $helm->extra_options->{command} || $helm->extra_args->[0];
13  
14 $helm->die('Missing option: command') unless $cmd;
15 $self->_command($cmd);
16 }
17  
18 sub help {
19 my ($self, $task) = @_;
20 my $text = <<END;
21 Run a command on a remote server(s). This command can either
22 be specified as the first positional argument:
23  
24 helm $task 'ls /'
25  
26 Or as the named --command option:
27  
28 helm $task --command 'ls /'
29 END
30 $text .= qq(\nThis is just an alias for the "run" task) if $task eq 'exec';
31 return $text;
32 }
33  
34  
35 sub execute {
36 my ($self, %args) = @_;
37 my $server = $args{server};
38 my $ssh = $args{ssh};
39 my $helm = $self->helm;
40 my $command = $self->command;
41  
42 $helm->log->info("Running command ($command) on remote server $server");
43 $helm->run_remote_command(command => $command, ssh => $ssh, ssh_options => {tty => 1});
44 }
45  
46 __PACKAGE__->meta->make_immutable;
47  
48 1;