#!/usr/bin/perl -w

use strict;
use Config::Augeas::Exporter;
use Getopt::Long;

my $path = '/files';
my $root = '/';
my $excludes;
my $verbose;
my $debug;
my $help;

my $result = GetOptions (
   "path=s" => \$path,
   "root=s" => \$root,
   "exclude=s@" => \$excludes,
   "verbose" => \$verbose,
   "debug" => \$debug,
   "help" => \$help,
   );

if ($help) {
   usage();
   exit 0;
}

$verbose ||= $debug;

my $aug = Config::Augeas::Exporter->new(root => $root);

my $doc;
if ($#$excludes >= 0) {
   $doc = $aug->to_xml(path => $path, exclude => @$excludes);
} else {
   $doc = $aug->to_xml(path => $path);
}

print $doc->toString;


#######
# Subs
#######

sub usage {
   print "$0 [-p <path>] [-r fakeroot] [-v] [-d] [-h]

 Flags:
   -h, --help             Show this help
   -v, --verbose          Verbose mode
   -d, --debug            Debug mode

 Options:
   -p, --path <path>       Set path to export
   -r, --root <fakeroot>   Set fakeroot for Augeas
   -e, --exclude <pattern> Label pattern to exclude
";
}


