#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

use strict;
use warnings;

use VMware::vSphere::App;

my $app = VMware::vSphere::App->new();
my $ret;
eval { $ret = $app->run(@ARGV) };
exit 0 if @ARGV and $ARGV[0] eq 'comp';
if ($@) {
    $@ =~ s/at [^ ]+ line \d+\.$//s;
    print STDERR $@;
    exit 2;
}
exit ($ret ? 0 : 1);

__END__

=head1 NAME

vsphere - command line interface for VMware::vSphere::Simple perl module

=head1 SYNOPSIS

    vsphere <METHOD> [[PARAMETER1] [PARAMETER2]...]

    export VSPHERE_HOST=vc.example.com
    export VSPHERE_USER=root
    export VSPHERE_PASS=vmware

    vsphere shutdown_vm "My VM1"
    vsphere create_snapshot vm_name "My VM1" name "snapshot1"
    vsphere linked_clone "My VM1" "My VM2"
    vsphere poweron_vm "My VM2"

=head1 DESCRIPTION

This is a simple CLI utility to manage VMware vSphere services (vCenter or
ESXi). The utility makes login to vSphere service using credentials from
environment variables (VSPHERE_HOST, VSPHERE_USER, VSPHERE_PASS), performs the
specified method and makes logout on exit. It isn't effective if you perform
several methods in row. In this case use perl module L<VMware::vSphere::Simple>
directly.

Parameters are translating to perl data structures if it begins with C<[> and
C<{> and ends with C<]> or C<}> characters respectively.

=head1 ENVIRONMENT VARIABLES

=over

=item VSPHERE_HOST

Hostname or IP address of the VMware vSphere Web Service (vCenter or ESXi).

=item VSPHERE_USER

Username for login to the VMware vSphere Web Service.

=item VSPHERE_PASS

Password for login to the VMware vSphere Web Service.

=item VSPHERE_DEBUG

Enable verbose output for debugging.

=back

=head1 SEE ALSO

=over

=item L<VMware::vSphere>

Raw interface to VMware vSphere Web Services.

=item L<VMware::vSphere::Simple>

Simplifies common vSphere methods and makes it more perlish.

=item L<https://www.vmware.com/support/developer/vc-sdk/index.html>

Official VMware vSphere Web Services SDK Documentation.

=back


=head1 AUTHOR

Mikhail Telnov E<lt>Mikhail.Telnov@gmail.comE<gt>

=head1 COPYRIGHT

This software is copyright (c) 2016 by Mikhail Telnov.

This library is free software; you may redistribute and/or modify it
under the same terms as Perl itself.

=cut
