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