Ordo/Command/Job/Update.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 113 CC 18 SCAR 54.7
CC
18
Cov
0%
execute
342.0
name
2.0
summary
2.0
CRAP 237.4
1 package App::Ordo::Command::Job::Update;
2 use Moo;
3 use feature qw(say);
4 extends 'App::Ordo::Command::Base';
5  
6 use App::Ordo qw($CURRENT_PATH);
7 use Term::ANSIColor qw(colored);
8  
9 sub name { "job update" }
10 sub summary { "Update an existing job" }
11 sub usage { "<path/name> [options]" }
12  
13 sub option_spec {
14 return {
15 'server|s=s' => 'Change server',
16 'script=s' => 'Change script',
17 'description=s' => 'Change description',
18 'needs=s@' => 'Replace AND dependencies',
19 'needs_any=s@' => 'Replace OR dependencies',
20 'remove_needs' => 'Remove all dependencies',
21 'retrys=i' => 'Change retry count',
22 'loops=i' => 'Change loop count',
23 'delay=i' => 'Change delay',
24 'clonable=i' => 'Change clonable flag',
25 'on_fail=i' => 'Cluster to run on failure',
26 'json=s' => 'Change JSON data',
27 };
28 }
29  
30 sub execute {
31 my ($self, $opt, $name) = @_;
32  
33 unless ($name) {
34 say colored(["bold red"], "Usage: job update <path/name> [options]");
35 return;
36 }
37  
38 my $payload = { name => $name };
39  
40 if ($opt->{needs}) {
41 my @expanded;
42 for my $item (@{$opt->{needs}}) {
43 push @expanded, split /,/, $item;
44 }
45 $opt->{needs} = \@expanded;
46 }
47  
48 if ($opt->{needs_any}) {
49 my @expanded;
50 for my $item (@{$opt->{needs_any}}) {
51 push @expanded, split /,/, $item;
52 }
53 $opt->{needs_any} = \@expanded;
54 }
55  
56 # Only include options that were provided
57 $payload->{server} = $opt->{server} if $opt->{server};
58 $payload->{script} = $opt->{script} if $opt->{script};
59 $payload->{description} = $opt->{description} if $opt->{description};
60 $payload->{needs} = $opt->{needs} if $opt->{needs};
61 $payload->{needs_any} = $opt->{needs_any} if $opt->{needs_any};
62 $payload->{retrys} = $opt->{retrys} if defined $opt->{retrys};
63 $payload->{loops} = $opt->{loops} if defined $opt->{loops};
64 $payload->{delay} = $opt->{delay} if defined $opt->{delay};
65 $payload->{clonable} = $opt->{clonable} if defined $opt->{clonable};
66 $payload->{on_fail} = $opt->{on_fail} if defined $opt->{on_fail};
67 $payload->{json} = $opt->{json} if $opt->{json};
68 $payload->{remove_needs} = 1 if $opt->{remove_needs};
69  
70 unless (keys %$payload > 1) { # only name
71 say colored(["bold yellow"], "No changes specified");
72 return;
73 }
74  
75 my $res = $self->api->call('update_job_config', $payload);
76  
77 if ($res->{success}) {
78 say colored(["bold green"], "Job '$name' updated");
79 } else {
80 say colored(["bold red"], "Failed: " . ($res->{message} || 'unknown error'));
81 }
82 }
83  
84 1;