« blib/lib/Tapper/CLI/DbDeploy/Command/saveschema.pm
↑ Summary
blib/lib/Tapper/CLI/DbDeploy/Command/upgrade.pm »
| 1 | package Tapper::CLI::HostFeature; | ||||||||||||||||||||||||||||
| 2 | 72 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 3 | 72 | $Tapper::CLI::HostFeature::VERSION = '5.0.8'; | |||||||||||||||||||||||||||
| 4 | 72 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 72 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 72 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 72 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | sub ar_get_host_feature_parameters { | ||||||||||||||||||||||||||
|
Subroutine
ar_get_host_feature_parameters: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 4 | my ( $s_cmd ) = @_; | |||||||||||||||||||||||||||
| 13 | return [ | ||||||||||||||||||||||||||||
| 14 | 4 | ▶ | [ 'id|i=i' , 'get host by id', ], | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | [ 'name|n=s' , 'get host by name', ], | ||||||||||||||||||||||||||||
| 16 | [ 'entry|e=s' , 'host feature entry', ], | ||||||||||||||||||||||||||||
| 17 | ( | ||||||||||||||||||||||||||||
| 18 | $s_cmd ne 'host-feature-delete' | ||||||||||||||||||||||||||||
| 19 | ? ( [ 'value=s' , 'host feature value', ] ) | ||||||||||||||||||||||||||||
| 20 | : ( [ 'force|f' , 'really delete host feature', ] ) | ||||||||||||||||||||||||||||
| 21 | ), | ||||||||||||||||||||||||||||
| 22 | [ 'verbose|v' , 'some more informational output', ], | ||||||||||||||||||||||||||||
| 23 | [ 'help|?' , 'Print this help message and exit.', ], | ||||||||||||||||||||||||||||
| 24 | ]; | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 4 | ▶ | sub b_init_host_feature_command { | ||||||||||||||||||||||||||
|
Subroutine
b_init_host_feature_command: called CC=7 SCAR=24.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 4 | my ( $or_app_rad, $s_cmd ) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | my $ar_parameters = ar_get_host_feature_parameters( $s_cmd ); | |||||||||||||||||||||||||||
| 33 | 4 | $or_app_rad->getopt( map { $_->[0] } @{$ar_parameters} ); | |||||||||||||||||||||||||||
| 34 | 4 | my $hr_options = $or_app_rad->options; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 4 | ▶ | if ( $hr_options->{help} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | say {*STDERR} "Usage: $PROGRAM_NAME $s_cmd [options]"; | |||||||||||||||||||||||||||
| 38 | 0 | require Tapper::CLI::Base; | |||||||||||||||||||||||||||
| 39 | 0 | Tapper::CLI::Base::b_print_help( $ar_parameters ); | |||||||||||||||||||||||||||
| 40 | 0 | return; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 4 | ▶ | if (! ($hr_options->{name} || $hr_options->{id}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hr_options->{"name"} or $hr_options->{"id"}
MC/DC0%0/2
$hr_options->{"name"} or $hr_options->{"id"}
$hr_options->{"name"}
$hr_options->{"id"}
Truth table33%1/3
A or B
A= $hr_options->{"name"}B= $hr_options->{"id"}
| |||||||||||||||||||||||||||||
| 44 | 0 | die "error: one of parameter 'name' or 'id' is required\n"; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 4 | ▶ | if (! $hr_options->{entry} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | die "error: missing parameter 'entry'\n"; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 4 | ▶ | if ( $s_cmd ne 'host-feature-delete' && !$hr_options->{value} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$s_cmd ne "host-feature-delete" and not $hr_options->{"value"}
MC/DC0%0/2
$s_cmd ne "host-feature-delete" and not $hr_options->{"value"}
$s_cmd ne "host-feature-delete"
not $hr_options->{"value"}
Truth table66%2/3
A and not(B)
A= $s_cmd ne "host-feature-delete"B= not $hr_options->{"value"}
| |||||||||||||||||||||||||||||
| 50 | 0 | die "error: missing parameter 'value'\n"; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 4 | return $hr_options; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub b_host_feature_new { | ||||||||||||||||||||||||||
|
Subroutine
b_host_feature_new: called CC=6 SCAR=20.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | my ( $or_app_rad ) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | my $hr_options = b_init_host_feature_command( | |||||||||||||||||||||||||||
| 63 | $or_app_rad, 'host-feature-new', | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # help command is called | ||||||||||||||||||||||||||||
| 67 | 1 | ▶ | if (! $hr_options ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | return; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | require Tapper::Model; | |||||||||||||||||||||||||||
| 72 | 1 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 73 | my $or_host = | ||||||||||||||||||||||||||||
| 74 | Tapper::Model::model('TestrunDB') | ||||||||||||||||||||||||||||
| 75 | ->resultset('Host') | ||||||||||||||||||||||||||||
| 76 | ->search( | ||||||||||||||||||||||||||||
| 77 | $hr_options->{id} ? { id => $hr_options->{id} } : { name => $hr_options->{name} }, | ||||||||||||||||||||||||||||
| 78 | { rows => 1 }, | ||||||||||||||||||||||||||||
| 79 | ) | ||||||||||||||||||||||||||||
| 80 | ->first | ||||||||||||||||||||||||||||
| 81 | ) { | ||||||||||||||||||||||||||||
| 82 | 1 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | my $or_host_feature = | ||||||||||||||||||||||||||||
| 84 | Tapper::Model::model('TestrunDB') | ||||||||||||||||||||||||||||
| 85 | ->resultset('HostFeature') | ||||||||||||||||||||||||||||
| 86 | ->search({ | ||||||||||||||||||||||||||||
| 87 | host_id => $or_host->id, | ||||||||||||||||||||||||||||
| 88 | entry => $hr_options->{entry}, | ||||||||||||||||||||||||||||
| 89 | },{ | ||||||||||||||||||||||||||||
| 90 | rows => 1, | ||||||||||||||||||||||||||||
| 91 | }) | ||||||||||||||||||||||||||||
| 92 | ->first | ||||||||||||||||||||||||||||
| 93 | ) { | ||||||||||||||||||||||||||||
| 94 | 0 | die "error: feature already exists\n"; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||||||||||
| 97 | 1 | require DateTime; | |||||||||||||||||||||||||||
| 98 | my $or_host_feature_new = | ||||||||||||||||||||||||||||
| 99 | Tapper::Model::model('TestrunDB') | ||||||||||||||||||||||||||||
| 100 | ->resultset('HostFeature') | ||||||||||||||||||||||||||||
| 101 | ->new({ | ||||||||||||||||||||||||||||
| 102 | host_id => $or_host->id, | ||||||||||||||||||||||||||||
| 103 | entry => $hr_options->{entry}, | ||||||||||||||||||||||||||||
| 104 | value => $hr_options->{value}, | ||||||||||||||||||||||||||||
| 105 | 1 | created_at => DateTime->now->strftime('%F %T'), | |||||||||||||||||||||||||||
| 106 | }) | ||||||||||||||||||||||||||||
| 107 | ; | ||||||||||||||||||||||||||||
| 108 | 1 | ▶ | if ( $or_host_feature_new->insert ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 1 | say 'info: successfully inserted host feature ' . $or_host_feature_new->id; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||
| 112 | 0 | die "error: cannot insert host feature\n"; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | else { | ||||||||||||||||||||||||||||
| 117 | 0 | die "error: host not found\n"; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | return; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | ▶ | sub b_host_feature_delete { | ||||||||||||||||||||||||||
|
Subroutine
b_host_feature_delete: called CC=8 SCAR=23.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 2 | my ( $or_app_rad ) = @_; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 2 | my $hr_options = b_init_host_feature_command( | |||||||||||||||||||||||||||
| 130 | $or_app_rad, 'host-feature-delete', | ||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # help command is called | ||||||||||||||||||||||||||||
| 134 | 2 | ▶ | if (! $hr_options ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 0 | return; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 2 | ▶ | if (! $hr_options->{force} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 1 | say {*STDERR} "info: Skip actual host-feature-delete unless --force is used."; | |||||||||||||||||||||||||||
| 140 | 1 | return; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | require Tapper::Model; | |||||||||||||||||||||||||||
| 144 | 1 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 145 | my $or_host = | ||||||||||||||||||||||||||||
| 146 | Tapper::Model::model('TestrunDB') | ||||||||||||||||||||||||||||
| 147 | ->resultset('Host') | ||||||||||||||||||||||||||||
| 148 | ->search( | ||||||||||||||||||||||||||||
| 149 | $hr_options->{id} ? { id => $hr_options->{id} } : { name => $hr_options->{name} }, | ||||||||||||||||||||||||||||
| 150 | { rows => 1 }, | ||||||||||||||||||||||||||||
| 151 | ) | ||||||||||||||||||||||||||||
| 152 | ->first | ||||||||||||||||||||||||||||
| 153 | ) { | ||||||||||||||||||||||||||||
| 154 | 1 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | my $or_host_feature = | ||||||||||||||||||||||||||||
| 156 | Tapper::Model::model('TestrunDB') | ||||||||||||||||||||||||||||
| 157 | ->resultset('HostFeature') | ||||||||||||||||||||||||||||
| 158 | ->search({ | ||||||||||||||||||||||||||||
| 159 | host_id => $or_host->id, | ||||||||||||||||||||||||||||
| 160 | entry => $hr_options->{entry}, | ||||||||||||||||||||||||||||
| 161 | },{ | ||||||||||||||||||||||||||||
| 162 | rows => 1, | ||||||||||||||||||||||||||||
| 163 | }) | ||||||||||||||||||||||||||||
| 164 | ->first | ||||||||||||||||||||||||||||
| 165 | ) { | ||||||||||||||||||||||||||||
| 166 | 1 | ▶ | if (! $or_host_feature->delete ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 167 | 0 | die "error: cannot delete host feature\n"; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | elsif ( $hr_options->{verbose} ) { | ||||||||||||||||||||||||||||
| 170 | 0 | say 'info: successfully delete host feature ' . $or_host_feature->id; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | else { | ||||||||||||||||||||||||||||
| 174 | 0 | die "error: feature not exists\n"; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||
| 178 | 0 | die "error: host not found\n"; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 1 | return; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 1 | ▶ | sub b_host_feature_update { | ||||||||||||||||||||||||||
|
Subroutine
b_host_feature_update: called CC=7 SCAR=22.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 1 | my ( $or_app_rad ) = @_; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 1 | my $hr_options = b_init_host_feature_command( | |||||||||||||||||||||||||||
| 191 | $or_app_rad, 'host-feature-update', | ||||||||||||||||||||||||||||
| 192 | ); | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # help command is called | ||||||||||||||||||||||||||||
| 195 | 1 | ▶ | if (! $hr_options ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | return; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 1 | require Tapper::Model; | |||||||||||||||||||||||||||
| 200 | 1 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 201 | my $or_host = | ||||||||||||||||||||||||||||
| 202 | Tapper::Model::model('TestrunDB') | ||||||||||||||||||||||||||||
| 203 | ->resultset('Host') | ||||||||||||||||||||||||||||
| 204 | ->search( | ||||||||||||||||||||||||||||
| 205 | $hr_options->{id} ? { id => $hr_options->{id} } : { name => $hr_options->{name} }, | ||||||||||||||||||||||||||||
| 206 | { rows => 1 }, | ||||||||||||||||||||||||||||
| 207 | ) | ||||||||||||||||||||||||||||
| 208 | ->first | ||||||||||||||||||||||||||||
| 209 | ) { | ||||||||||||||||||||||||||||
| 210 | 1 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | my $or_host_feature = | ||||||||||||||||||||||||||||
| 212 | Tapper::Model::model('TestrunDB') | ||||||||||||||||||||||||||||
| 213 | ->resultset('HostFeature') | ||||||||||||||||||||||||||||
| 214 | ->search({ | ||||||||||||||||||||||||||||
| 215 | host_id => $or_host->id, | ||||||||||||||||||||||||||||
| 216 | entry => $hr_options->{entry} | ||||||||||||||||||||||||||||
| 217 | }, { | ||||||||||||||||||||||||||||
| 218 | rows => 1 | ||||||||||||||||||||||||||||
| 219 | }) | ||||||||||||||||||||||||||||
| 220 | ->first | ||||||||||||||||||||||||||||
| 221 | ) { | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 1 | require DateTime; | |||||||||||||||||||||||||||
| 224 | 1 | $or_host_feature->value( $hr_options->{value} ); | |||||||||||||||||||||||||||
| 225 | 1 | $or_host_feature->updated_at( DateTime->now->strftime('%F %T') ); | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 1 | ▶ | if ( $or_host_feature->update ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 1 | ▶ | if ( $hr_options->{verbose} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 0 | say sprintf "Updated feature for host '%s': %s = %s", | |||||||||||||||||||||||||||
| 230 | $or_host->name, | ||||||||||||||||||||||||||||
| 231 | $or_host_feature->entry, | ||||||||||||||||||||||||||||
| 232 | $or_host_feature->value | ||||||||||||||||||||||||||||
| 233 | ; | ||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | else { | ||||||||||||||||||||||||||||
| 237 | 0 | die "error: cannot update feature\n"; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | else { | ||||||||||||||||||||||||||||
| 242 | 0 | die "error: host not found\n"; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 1 | return; | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 71 | ▶ | sub setup { | ||||||||||||||||||||||||||
|
Subroutine
setup: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 251 | 71 | my ($c) = @_; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 71 | $c->register('host-feature-new' , \&b_host_feature_new , 'Create a new host feature'); | |||||||||||||||||||||||||||
| 254 | 71 | $c->register('host-feature-update', \&b_host_feature_update, 'Update host feature'); | |||||||||||||||||||||||||||
| 255 | 71 | $c->register('host-feature-delete', \&b_host_feature_delete, 'Delete host feature'); | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 71 | ▶ | if ($c->can('group_commands')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 0 | $c->group_commands( | |||||||||||||||||||||||||||
| 259 | 'Host commands', | ||||||||||||||||||||||||||||
| 260 | 'host-feature-new', | ||||||||||||||||||||||||||||
| 261 | 'host-feature-update', | ||||||||||||||||||||||||||||
| 262 | 'host-feature-delete', | ||||||||||||||||||||||||||||
| 263 | ); | ||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | 71 | return; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 72 | 1; # End of Tapper::CLI | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | __END__ | ||||||||||||||||||||||||||||