script/hcloud.pl untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 65 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 # PODNAME: hcloud.pl
3 # ABSTRACT: Hetzner Cloud CLI (Perl implementation)
4  
5 use strict;
6 use warnings;
7 use lib 'lib';
8  
9 # Map hyphenated commands to MooX::Cmd package names
10 # (Perl packages can't have hyphens, so we translate)
11 my %cmd_aliases = (
12 'floating-ip' => 'floatingip',
13 'primary-ip' => 'primaryip',
14 'load-balancer' => 'loadbalancer',
15 'placement-group' => 'placementgroup',
16 'add-subnet' => 'addsubnet',
17 'add-route' => 'addroute',
18 'add-rule' => 'addrule',
19 'apply-to' => 'applyto',
20 'remove-from' => 'removefrom',
21 'add-target' => 'addtarget',
22 'add-service' => 'addservice',
23 );
24  
25 for my $i (0 .. $#ARGV) {
26 if (exists $cmd_aliases{lc $ARGV[$i]}) {
27 $ARGV[$i] = $cmd_aliases{lc $ARGV[$i]};
28 }
29 }
30  
31 # Custom help for commands with hyphenated subcommands
32 # (MooX::Cmd shows package names, we want hyphenated names)
33 my %custom_help = (
34 network => sub {
35 print "Usage: hcloud.pl network <subcommand>\n\n";
36 print "Subcommands:\n";
37 print " list List all networks\n";
38 print " describe Show network details\n";
39 print " create Create a network\n";
40 print " delete Delete a network\n";
41 print " add-subnet Add a subnet to network\n";
42 print " add-route Add a route to network\n";
43 },
44 firewall => sub {
45 print "Usage: hcloud.pl firewall <subcommand>\n\n";
46 print "Subcommands:\n";
47 print " list List all firewalls\n";
48 print " describe Show firewall details\n";
49 print " create Create a firewall\n";
50 print " delete Delete a firewall\n";
51 print " add-rule Add a rule to firewall\n";
52 print " apply-to Apply firewall to server\n";
53 print " remove-from Remove firewall from server\n";
54 },
55 loadbalancer => sub {
56 print "Usage: hcloud.pl load-balancer <subcommand>\n\n";
57 print "Subcommands:\n";
58 print " list List all load balancers\n";
59 print " describe Show load balancer details\n";
60 print " create Create a load balancer\n";
61 print " delete Delete a load balancer\n";
62 print " add-target Add a target to load balancer\n";
63 print " add-service Add a service to load balancer\n";
64 },
65 );
66  
67 # Check if help was requested for a command with custom help
68 # Only intercept if: command --help (not: command subcommand --help)
69 if (@ARGV >= 1) {
70 my $cmd = lc $ARGV[0];
71 $cmd =~ s/-//g; # normalize: load-balancer -> loadbalancer
72 if (exists $custom_help{$cmd}) {
73 # Check second arg: is it --help or a subcommand?
74 my $second = $ARGV[1] // '';
75 if ($second =~ /^(-h|--help|--usage|--man)$/) {
76 $custom_help{$cmd}->();
77 exit 0;
78 }
79 }
80 }
81  
82 use WWW::Hetzner::CLI;
83  
84 WWW::Hetzner::CLI->new_with_cmd;
85  
86 __END__