#!/usr/bin/env perl

# linode-cli
# Copyright (C) 2015 Linode, LLC

use 5.010;
use strict;
use warnings;

use FindBin;
use lib "$FindBin::RealBin/lib";

use Getopt::Long (qw(:config pass_through));
use Linode::CLI::Util ':basic';

my $object;

if ( defined( $ARGV[0] ) && ( my @found = grep { $_ eq lc( $ARGV[0] ) } @MODES ) ) {
    $object = shift;
}
elsif ( defined( $ARGV[0] ) && $ARGV[0] =~ 'help' ) {
	Linode::CLI::Util::eat_cmdargs;
}
else {
    GetOptions( 'o|object=s' => \$object ) or die "Unable to parse options\n";
}

$object = 'linode'
    unless ( defined($object) && ( my @found = grep { $_ eq $object } @MODES ) );

exec( $FindBin::RealBin . "/linode-$object", @ARGV );

__END__

=head1 NAME

linode - command-line interface to the Linode platform

=head1 SYNOPSIS

B<linode> [B<--object> object] [object-options...]

This is a wrapper utility to the suite of Linode command line tools.

=head2 Objects

The following command line tools are available, and can be called directly or
with B<linode object>, e.g.: B<linode domain list>. Each has its own help
documentation accessible with B<--help>; for instance: B<linode -o domain
--help>.

If no object is specified, B<-o linode> is implied.

=over

=item S<-o account,       --object account       account information>

=item S<-o domain,        --object domain        domains and DNS records>

=item S<-o linode,        --object linode        Linode instances>

=item S<-o nodebalancer,  --object nodebalancer  NodeBalancer configs and nodes>

=item S<-o stackscript,   --object stackscript   available StackScripts>

=back

=head1 COPYRIGHT/LICENSE

Copyright 2015 Linode, LLC.  Linode CLI is made available under the terms
of the Perl Artistic License, or GPLv2 at the recipients discretion.

=head2 Perl Artistic License

Read it at L<http://dev.perl.org/licenses/artistic.html>.

=head2 GNU General Public License (GPL) Version 2

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see http://www.gnu.org/licenses/

See the full license at L<http://www.gnu.org/licenses/>.

=cut
