#!/usr/bin/perl -w
#    Copyright (c) 2011 Raphaël Pinson.
#
#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Lesser Public License as
#    published by the Free Software Foundation; either version 2.1 of
#    the License, or (at your option) any later version.
#
#    Config-Model 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.  See the GNU
#    Lesser Public License for more details.
#
#    You should have received a copy of the GNU Lesser Public License
#    along with Config-Model; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
#    02110-1301 USA


use strict;
use Getopt::Long;
use Pod::Usage;
use Config::Augeas::Validator;


################
# Parse options
################

my $conffile;
my $rulesdir = "/etc/augeas-validator/rules.d";
my $verbose = 0;
my $man = 0;
my $help = 0;

my $opts = GetOptions(
   'help|?'     => \$help,
   'man'        => \$man,
   "verbose"    => \$verbose,,
   "conf=s"     => \$conffile,
   "rulesdir=s" => \$rulesdir,
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;

my @files = @ARGV;



my $validator;

if ($conffile) {
   $validator = Config::Augeas::Validator->new(conf => $conffile);
   $validator->play(@files);
   exit $validator->{err};
} else {
   $validator = Config::Augeas::Validator->new(rulesdir => $rulesdir);
   $validator->play(@files);
   exit $validator->{err};
}


__END__

=head1 NAME

   augeas-validator - A generic configuration validator

=head1 SYNOPSIS

   augeas-validator [options] [file ...]

    Options:
      -help brief help message
      -man full documentation
      -verbose be verbose
      -conf <conffile> specify which configuration file to use
      -rulesdir <rules directory> specify a directory of rules to use

=head1 OPTIONS

=over 8

=item B<-help>

Print a brief help message and exits.

=item B<-man>

Prints the manual page and exits.

=item B<-verbose>

Print verbose information.

=item B<-rulesdir rulesdir>

Specify the rules directory to use.

=item B<-conf conffile>

Specify a configuration file to use. When this option is specified, the rules
directory is bypassed, and only the given configuration file is used.
Patterns and excludes are ignored.

=back

=head1 DESCRIPTION

B<Augeas-validator> is a generic configuration validator based on B<Augeas>.
It takes a configuration file (by default F<augeas-validator.ini>)
which contains a set of rules for a given B<Augeas> lens and applies them to the given files.

=head1 CONFIGURATION

See the L<Config::Augeas::Validator> manual.


=head1 SEE ALSO

L<Config::Augeas>

=head1 FILES

F<augeas-validator.ini>
    The default configuration file for B<Augeas-validator>.

=cut



