#!/usr/bin/perl

use strict;
use warnings;
use LATMOS::Accounts;
use Getopt::Long;
use Pod::Usage;
use LATMOS::Accounts::Cli;

=head1 NAME

    la-cli - A powerfull commandline tool to manage LATMOS::Accounts contents

=head1 SYNOPSIS

    la-cli [options]

=cut

GetOptions(
    'c|config=s'        => \my $config,
    'b|base=s'          => \my $base,
    'no-unexp|wo-unexp' => \my $nounexp,
    'with-unexp'        => \my $unexp,
    'help'              => sub { pod2usage(0) },
) or pod2usage();

=head1 OPTIONS

=over 4

=item -c|--config configfile

Use this configuration file instead of the default one.

=item -b|--base basename

Query this specific base instead of the default one.

=item --unexp

Take into account all objects (even non propagated ones, with attribute 'exported'=0)

=item --no-unexp

Take into account only propagated objects (attribute 'exported'=1) (default)

=back

=cut

my $LA = LATMOS::Accounts->new($config, noacl => 1);
my $labase = $base ? $LA->base($base) : $LA->default_base;
$labase && $labase->load or die "Cannot load base";

$labase->unexported($nounexp ? 0 : 1);

my $globalenv = LATMOS::Accounts::Cli::globalenv($labase);

if (@ARGV) {
    $globalenv->run(@ARGV);
} else {
    $globalenv->cli;
}
print "\n";

exit 0;

