| 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 | our $VERSION = '0.102'; | ||
| 10 | |||
| 11 | # Map hyphenated commands to MooX::Cmd package names | ||
| 12 | # (Perl packages can't have hyphens, so we translate) | ||
| 13 | my %cmd_aliases = ( | ||
| 14 | 'floating-ip' => 'floatingip', | ||
| 15 | 'primary-ip' => 'primaryip', | ||
| 16 | 'load-balancer' => 'loadbalancer', | ||
| 17 | 'load-balancer-type' => 'loadbalancertype', | ||
| 18 | 'placement-group' => 'placementgroup', | ||
| 19 | 'storage-box' => 'storagebox', | ||
| 20 | 'change-type' => 'changetype', | ||
| 21 | 'reset-password' => 'resetpassword', | ||
| 22 | 'enable-protection' => 'enableprotection', | ||
| 23 | 'disable-protection' => 'disableprotection', | ||
| 24 | 'enable-snapshot-plan' => 'enablesnapshotplan', | ||
| 25 | 'disable-snapshot-plan' => 'disablesnapshotplan', | ||
| 26 | 'rollback-snapshot' => 'rollbacksnapshot', | ||
| 27 | 'update-access-settings' => 'updateaccesssettings', | ||
| 28 | 'add-label' => 'addlabel', | ||
| 29 | 'remove-label' => 'removelabel', | ||
| 30 | 'change-home-directory' => 'changehomedirectory', | ||
| 31 | 'add-subnet' => 'addsubnet', | ||
| 32 | 'add-route' => 'addroute', | ||
| 33 | 'add-rule' => 'addrule', | ||
| 34 | 'apply-to' => 'applyto', | ||
| 35 | 'remove-from' => 'removefrom', | ||
| 36 | 'add-target' => 'addtarget', | ||
| 37 | 'add-service' => 'addservice', | ||
| 38 | ); | ||
| 39 | |||
| 40 | for my $i (0 .. $#ARGV) { | ||
| 41 | if (exists $cmd_aliases{lc $ARGV[$i]}) { | ||
| 42 | $ARGV[$i] = $cmd_aliases{lc $ARGV[$i]}; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | # Custom help for commands with hyphenated subcommands | ||
| 47 | # (MooX::Cmd shows package names, we want hyphenated names) | ||
| 48 | my %custom_help = ( | ||
| 49 | network => sub { | ||
| 50 | print "Usage: hcloud.pl network <subcommand>\n\n"; | ||
| 51 | print "Subcommands:\n"; | ||
| 52 | print " list List all networks\n"; | ||
| 53 | print " describe Show network details\n"; | ||
| 54 | print " create Create a network\n"; | ||
| 55 | print " delete Delete a network\n"; | ||
| 56 | print " add-subnet Add a subnet to network\n"; | ||
| 57 | print " add-route Add a route to network\n"; | ||
| 58 | }, | ||
| 59 | firewall => sub { | ||
| 60 | print "Usage: hcloud.pl firewall <subcommand>\n\n"; | ||
| 61 | print "Subcommands:\n"; | ||
| 62 | print " list List all firewalls\n"; | ||
| 63 | print " describe Show firewall details\n"; | ||
| 64 | print " create Create a firewall\n"; | ||
| 65 | print " delete Delete a firewall\n"; | ||
| 66 | print " add-rule Add a rule to firewall\n"; | ||
| 67 | print " apply-to Apply firewall to server\n"; | ||
| 68 | print " remove-from Remove firewall from server\n"; | ||
| 69 | }, | ||
| 70 | loadbalancer => sub { | ||
| 71 | print "Usage: hcloud.pl load-balancer <subcommand>\n\n"; | ||
| 72 | print "Subcommands:\n"; | ||
| 73 | print " list List all load balancers\n"; | ||
| 74 | print " describe Show load balancer details\n"; | ||
| 75 | print " create Create a load balancer\n"; | ||
| 76 | print " delete Delete a load balancer\n"; | ||
| 77 | print " add-target Add a target to load balancer\n"; | ||
| 78 | print " add-service Add a service to load balancer\n"; | ||
| 79 | }, | ||
| 80 | storagebox => sub { | ||
| 81 | print "Usage: hcloud.pl storage-box <subcommand>\n\n"; | ||
| 82 | print "Subcommands:\n"; | ||
| 83 | print " list, describe, create, update, delete\n"; | ||
| 84 | print " change-type, reset-password\n"; | ||
| 85 | print " enable-protection, disable-protection\n"; | ||
| 86 | print " enable-snapshot-plan, disable-snapshot-plan, rollback-snapshot\n"; | ||
| 87 | print " update-access-settings, folders, add-label, remove-label\n"; | ||
| 88 | print " snapshot Manage Storage Box snapshots\n"; | ||
| 89 | print " subaccount Manage Storage Box subaccounts\n"; | ||
| 90 | }, | ||
| 91 | ); | ||
| 92 | |||
| 93 | # Check if help was requested for a command with custom help | ||
| 94 | # Only intercept if: command --help (not: command subcommand --help) | ||
| 95 | if (@ARGV >= 1) { | ||
| 96 | my $cmd = lc $ARGV[0]; | ||
| 97 | $cmd =~ s/-//g; # normalize: load-balancer -> loadbalancer | ||
| 98 | if (exists $custom_help{$cmd}) { | ||
| 99 | # Check second arg: is it --help or a subcommand? | ||
| 100 | my $second = $ARGV[1] // ''; | ||
| 101 | if ($second =~ /^(-h|--help|--usage|--man)$/) { | ||
| 102 | $custom_help{$cmd}->(); | ||
| 103 | exit 0; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | use WWW::Hetzner::CLI; | ||
| 109 | |||
| 110 | WWW::Hetzner::CLI->new_with_cmd; | ||
| 111 | |||
| 112 | __END__ |