#!/usr/bin/perl

=head1 NAME

otptool - one-time password tool

=head1 SYNOPSIS

otptool URI | -

    URI: otpauth://

    If invoked with '-', the URI is read from standard input.

=cut

use utf8;
use strict;
use warnings;
use open qw(:std :utf8);

use Getopt::Long;
use Pod::Usage;
use Pass::OTP qw(otp);
use Pass::OTP::URI qw(parse);

our $VERSION = $Pass::OTP::VERSION;
my $uri = '';

Getopt::Long::Configure(qw(auto_version));
GetOptions(
    'help|h|?' => sub { pod2usage(-verbose => 2) },
) || pod2usage(2);

pod2usage(2) if @ARGV == 0;

if ($ARGV[0] eq '-') {
    $uri = <>;
} elsif ($ARGV[0] =~ m#^otpauth://#) {
    $uri = $ARGV[0];
} else {
    pod2usage(2);
}

printf("%s\n", otp(parse($uri)));
exit 0;

__END__
=head1 SEE ALSO

L<Pass::OTP>

L<oathtool(1)>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2020 Jan Baier

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See L<http://dev.perl.org/licenses/> for more information.

=cut
