The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/env perl

use 5.006002;

use strict;
use warnings;

use Getopt::Long 2.33 qw{ :config auto_version };
use Astro::SpaceTrack;
use Pod::Usage;

our $VERSION = '0.106';

my %opt;

GetOptions( \%opt,
    qw{ basic! },
    help => sub { pod2usage( { -verbose => 2 } ) },
) or pod2usage( { -verbose => 0 } );

my $st;
eval {
    # Default identity to true
    local $ENV{SPACETRACK_IDENTITY} = 1;
    $st = Astro::SpaceTrack->new();
} or die "Unable to instantiate Astro::SpaceTrack\n";

my %info;
foreach my $key ( qw{ username password } ) {
    defined( $info{$key} = $st->getv( $key ) )
	or die "Unable to determine $key\n";
}

my $delim = $opt{basic} ? ':' : '/';

print "SPACETRACK_USER=$info{username}$delim$info{password}\n";

__END__

=head1 TITLE

spacetrack-identity - Report the user's Space Track identity

=head1 SYNOPSIS

 spacetrack-identity
 spacetrack-identity -help
 spacetrack-identity -version

or, if you have any of a number of Unix shells,

 export eval `spacetrack-identity`

=head1 OPTIONS

=head2 -basic

If asserted, this option causes the output to be punctuated with a colon
(C<':'>, think HTTP basic authentication) rather then a slash (C<'/'>,
think Oracle). Both are understood by
L<Astro::SpaceTrack|Astro::SpaceTrack>.

The default is C<-nobasic>.

=head2 -help

This option displays the documentation for this script. The script then
exits.

=head2 -version

This option displays the version of this script. The script then exits.

=head1 DETAILS

This Perl script reports the user's Space Track identity. On success,
the output is

 SPACETRACK_USER=username/password

unless C<-basic> is specified, in which case you get a colon (C<':'>)
rather than a slash (C<'/'>).

On failure, the script dies.

=head1 AUTHOR

Tom Wyant (wyant at cpan dot org)

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2016-2018 by Thomas R. Wyant, III

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl 5.10.0. For more details, see the full text
of the licenses in the directory LICENSES.

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.

=cut

# ex: set textwidth=72 :