#!/usr/bin/env perl

# PODNAME: ncp

use strict;
use warnings;
use Pod::Usage;
use Device::Network::ConfigParser qw{app};


app(@ARGV);

__END__

=pod

=encoding UTF-8

=head1 NAME

ncp

=head1 VERSION

version 0.003

=head1 SYNOPSIS

./ncp [options] [file1 file2 ...]

=over 4

-v, --vendor=STRING     vendor type

-t, --type=STRING       type of vendor device

-f, --format=STRING     format of the output configuration, defaults to raw Perl.

-o, --output=STRING     file to write to, defaults to STDOUT.

Type 'man ncp' for more information.

=back

=head1 NAME

ncp - parse network device configurations.

=head1 OPTIONS

=over 4

=item B<-v|--vendor> <string>

Specfies the vendor of the configuration to be parsed - e.g. 'CheckPoint', 'Cisco'. This is combined with the '--type' command line argument to load the appropriate parser.

=item B<-t|--type> <string>

Specifies the type of vendor device the configuration is for - e.g. 'Gaia', 'ASA'. This is combined with the '--vendor' command line argument to load the appropriate parser.

=item B<-f|--format> <string>

Specify the format of the output parsed configuration. The 'raw' type is always available, and this will output the raw Perl structures. This is the default if no format is specified.

Other types available are dependent on the parser module loaded. Examples may incude 'json' for JavaScript Object Notation and 'csv' for comma separated values. 

=item B<-o|--output> <string>

Specifies the file to write the output to. The content of the file is parser module dependent.

If not specified (or the special file '-' is used) it defaults to STDOUT. The file is opened in append mode, so the current contents will not be clobbered.

The special variable I<%in_file%> contains the input config filename and can be used to split the output when multiple input files are used, for example:

    ncp --vendor Cisco --type ASA --type raw --output converted_%in_file% file1.conf file2.conf

would output 'converted_file1.conf' and 'converted_file2.conf'. On the other hand:

    ncp --vendor Cisco --type ASA --type raw --output converted.conf file1.conf file2.conf

would output a single 'converted.conf' containing the output from both file1.conf and file2.conf.

=item [file1 file2 ...]

A list of configuration files to parse. If no configuration files are listed it reads from STDIN until EOF (Ctrl + D). When reading from STDIN, the %in_file% variable used in I<--output> is 'STDIN'.

=back

=head1 Examples

    # Use the CheckPoint::Gaia module parse a configuration file and output Perl format to STDOUT
    ncp checkpoint_gaia.conf
    
    # Use the Cisco::ASA module to parse the configuration to JSON 
    ncp --vendor Cisco --type ASA --format json --output asa.conf


    # Use the Cisco::ASA module to parse the configuration of three config files, outputting JSON
    # to three separate output files
    ncp --vendor Cisco --type ASA --format csv --output %in_file%.csv fw1.conf fw2.conf fw3.conf

=head1 AUTHOR

Greg Foletta <greg@foletta.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Greg Foletta.

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

=cut
