lib/WWW/Hetzner/CLI/Cmd/Volume/Cmd/Create.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 47 CC 2 SCAR 12.0
CC
2
Cov
0%
execute
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.3
1 package WWW::Hetzner::CLI::Cmd::Volume::Cmd::Create;
2 # ABSTRACT: Create a volume
3  
4 our $VERSION = '0.100';
5  
6 use Moo;
7 use MooX::Cmd;
8 use MooX::Options usage_string => 'USAGE: hcloud.pl volume create --name <name> --size <gb> --location <loc>';
9 use JSON::MaybeXS qw(encode_json);
10  
11 option name => (
12 is => 'ro',
13 format => 's',
14 required => 1,
15 doc => 'Volume name',
16 );
17  
18 option size => (
19 is => 'ro',
20 format => 'i',
21 required => 1,
22 doc => 'Volume size in GB (min 10)',
23 );
24  
25 option location => (
26 is => 'ro',
27 format => 's',
28 required => 1,
29 doc => 'Location (e.g., fsn1, nbg1, hel1)',
30 );
31  
32 option format => (
33 is => 'ro',
34 format => 's',
35 doc => 'Filesystem format: ext4, xfs (default: ext4)',
36 default => 'ext4',
37 );
38  
39 option server => (
40 is => 'ro',
41 format => 'i',
42 doc => 'Server ID to attach to',
43 );
44  
45 option automount => (
46 is => 'ro',
47 doc => 'Automount volume after attach',
48 default => 0,
49 );
50  
51 sub execute {
52 my ($self, $args, $chain) = @_;
53  
54 my $main = $chain->[0];
55 my $cloud = $main->cloud;
56  
57 print "Creating volume '", $self->name, "'...\n";
58  
59 my $volume = $cloud->volumes->create(
60 name => $self->name,
61 size => $self->size,
62 location => $self->location,
63 format => $self->format,
64 server => $self->server,
65 automount => $self->automount,
66 );
67  
68 if ($main->output eq 'json') {
69 print encode_json($volume->data), "\n";
70 return;
71 }
72  
73 print "Volume created:\n";
74 printf " ID: %s\n", $volume->id;
75 printf " Name: %s\n", $volume->name;
76 printf " Size: %s GB\n", $volume->size;
77 printf " Location: %s\n", $volume->location;
78 printf " Device: %s\n", $volume->linux_device // '-';
79 printf " Server: %s\n", $volume->server // 'not attached';
80 }
81  
82 1;
83  
84 __END__