#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use Pod::Usage;
use Getopt::Long;
use CPAN::Audit;

my $opt_no_color;
my $opt_ascii;
my $opt_verbose;
my $opt_help;
GetOptions(
    'no-color'  => \$opt_no_color,
    'ascii'     => \$opt_ascii,
    'verbose|v' => \$opt_verbose,
    'help|h'    => \$opt_help,
) or die("Error in command line arguments\n");

pod2usage( -input => $FindBin::Bin . "/" . $FindBin::Script ) if $opt_help;

my ($command) = shift @ARGV;

if ( !$command ) {
    pod2usage( -input => $FindBin::Bin . "/" . $FindBin::Script );
}

my $audit = CPAN::Audit->new(
    no_color    => $opt_no_color,
    ascii       => $opt_ascii,
    verbose     => $opt_verbose,
    interactive => ( -t STDIN && -t STDOUT ),
);

exit $audit->command( $command, @ARGV );

__END__

=head1 NAME

cpan-audit - Audit CPAN modules

=head1 SYNOPSIS

cpan-audit [command] [options...]

Commands:

    module         [version range]    audit module with optional version range (all by default)
    dist|release   [version range]    audit distribution with optional version range (all by default)
    deps           [directory]        audit dependencies from the directory (. by default)
    installed                         audit all installed modules
    show           [advisory id]      show information about specific advisory

Options:

    --no-color     switch off colors
    --ascii        use ascii output
    --help|h       help message

Examples:

    cpan-audit dist Catalyst-Runtime
    cpan-audit dist Catalyst-Runtime 7.0
    cpan-audit dist Catalyst-Runtime >5.48

    cpan-audit module Catalyst 7.0

    cpan-audit deps .
    cpan-audit deps /path/to/distribution

    cpan-audit installed
    cpan-audit installed local/

    cpan-audit show CPANSA-Mojolicious-2018-03

=head1 DESCRIPTION

C<cpan-audit> is a command line application that checks the modules or distributions for known vulnerabilities. It is using
its internal database that is automatically generated from a hand-picked database
L<https://github.com/vti/cpan-security-advisory>.

C<cpan-audit> does not connect to anything, that is why it is important to keep it up to date. Every update of the internal
database is released as a new version.

C<cpan-audit> can automatically detect dependencies from the following sources:

=over

=item C<Carton>

Parses C<cpanfile.snapshot> file and checks the distribution versions.

=item C<cpanfile>

Parses C<cpanfile> taking into account the required versions.

=back

It is assumed that if the required version of the module is less than a version of a release with a known vulnerability
fix, then the module is considered affected.

=head1 LICENSE

Copyright (C) Viacheslav Tykhanovskyi.

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

=cut
