| 1 | package WWW::Hetzner::CLI; | ||
| 2 | |||
| 3 | # ABSTRACT: Hetzner Cloud CLI | ||
| 4 | |||
| 5 | use Moo; | ||
| 6 | use MooX::Cmd; | ||
| 7 | use MooX::Options; | ||
| 8 | use WWW::Hetzner::Cloud; | ||
| 9 | |||
| 10 | our $VERSION = '0.100'; | ||
| 11 | |||
| 12 | |||
| 13 | option token => ( | ||
| 14 | is => 'ro', | ||
| 15 | format => 's', | ||
| 16 | short => 't', | ||
| 17 | doc => 'API token (default: HETZNER_API_TOKEN env)', | ||
| 18 | default => sub { $ENV{HETZNER_API_TOKEN} }, | ||
| 19 | ); | ||
| 20 | |||
| 21 | |||
| 22 | option output => ( | ||
| 23 | is => 'ro', | ||
| 24 | format => 's', | ||
| 25 | short => 'o', | ||
| 26 | doc => 'Output format: table, json (default: table)', | ||
| 27 | default => 'table', | ||
| 28 | ); | ||
| 29 | |||
| 30 | |||
| 31 | has cloud => ( | ||
| 32 | is => 'lazy', | ||
| 33 | builder => sub { | ||
| 34 | my ($self) = @_; | ||
| 35 | WWW::Hetzner::Cloud->new(token => $self->token); | ||
| 36 | }, | ||
| 37 | ); | ||
| 38 | |||
| 39 | |||
| 40 | sub execute { | ||
| 41 | my ($self, $args, $chain) = @_; | ||
| 42 | |||
| 43 | # No subcommand given, show help | ||
| 44 | print "Usage: hcloud.pl [options] <command> [command-options]\n\n"; | ||
| 45 | print "Global options (must come BEFORE the command):\n"; | ||
| 46 | print " -t, --token API token\n"; | ||
| 47 | print " -o, --output Output format: table, json\n"; | ||
| 48 | print "\nServer & Compute:\n"; | ||
| 49 | print " server Manage cloud servers\n"; | ||
| 50 | print " servertype List server types\n"; | ||
| 51 | print " image List images\n"; | ||
| 52 | print " sshkey Manage SSH keys\n"; | ||
| 53 | print " placement-group Manage placement groups\n"; | ||
| 54 | print "\nNetworking:\n"; | ||
| 55 | print " network Manage private networks\n"; | ||
| 56 | print " firewall Manage firewalls\n"; | ||
| 57 | print " floating-ip Manage floating IPs\n"; | ||
| 58 | print " primary-ip Manage primary IPs\n"; | ||
| 59 | print " load-balancer Manage load balancers\n"; | ||
| 60 | print "\nStorage:\n"; | ||
| 61 | print " volume Manage volumes\n"; | ||
| 62 | print "\nDNS:\n"; | ||
| 63 | print " zone Manage DNS zones\n"; | ||
| 64 | print " record Manage DNS records\n"; | ||
| 65 | print "\nSecurity:\n"; | ||
| 66 | print " certificate Manage TLS certificates\n"; | ||
| 67 | print "\nInfo:\n"; | ||
| 68 | print " location List locations\n"; | ||
| 69 | print " datacenter List datacenters\n"; | ||
| 70 | print "\nExamples:\n"; | ||
| 71 | print " hcloud.pl server list\n"; | ||
| 72 | print " hcloud.pl -t mytoken server list\n"; | ||
| 73 | print " hcloud.pl --output json server describe 12345\n"; | ||
| 74 | print " hcloud.pl volume create --name data --size 50 --location fsn1\n"; | ||
| 75 | print " hcloud.pl firewall create --name web-fw\n"; | ||
| 76 | print "\nEnvironment variables:\n"; | ||
| 77 | print " HETZNER_API_TOKEN Default for --token\n"; | ||
| 78 | print "\nRun 'hcloud.pl <command> --help' for command-specific options.\n"; | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | |||
| 83 | 1; | ||
| 84 | |||
| 85 | __END__ |