[842] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use LATMOS::Accounts; |
---|
| 6 | use Getopt::Long; |
---|
| 7 | use Pod::Usage; |
---|
[2209] | 8 | use LATMOS::Accounts::Cli::Context; |
---|
[844] | 9 | use LATMOS::Accounts::Cli; |
---|
[842] | 10 | |
---|
| 11 | =head1 NAME |
---|
| 12 | |
---|
[849] | 13 | la-cli - A powerfull commandline tool to manage LATMOS::Accounts contents |
---|
[842] | 14 | |
---|
| 15 | =head1 SYNOPSIS |
---|
| 16 | |
---|
[849] | 17 | la-cli [options] |
---|
[842] | 18 | |
---|
| 19 | =cut |
---|
| 20 | |
---|
| 21 | GetOptions( |
---|
[849] | 22 | 'c|config=s' => \my $config, |
---|
| 23 | 'b|base=s' => \my $base, |
---|
[2209] | 24 | 't|transaction' => \my $transmode, |
---|
[849] | 25 | 'no-unexp|wo-unexp' => \my $nounexp, |
---|
| 26 | 'with-unexp' => \my $unexp, |
---|
[2282] | 27 | 'u|username=s' => \my $username, |
---|
[849] | 28 | 'help' => sub { pod2usage(0) }, |
---|
[842] | 29 | ) or pod2usage(); |
---|
| 30 | |
---|
| 31 | =head1 OPTIONS |
---|
| 32 | |
---|
| 33 | =over 4 |
---|
| 34 | |
---|
[861] | 35 | =item -c|--config configdir |
---|
[842] | 36 | |
---|
[861] | 37 | Use this configuration directory instead of the default one. |
---|
[842] | 38 | |
---|
| 39 | =item -b|--base basename |
---|
| 40 | |
---|
| 41 | Query this specific base instead of the default one. |
---|
| 42 | |
---|
[2203] | 43 | =item -t|--transaction |
---|
| 44 | |
---|
| 45 | Enable transaction mode: don't commit at earch command |
---|
| 46 | |
---|
[849] | 47 | =item --unexp |
---|
[842] | 48 | |
---|
| 49 | Take into account all objects (even non propagated ones, with attribute 'exported'=0) |
---|
| 50 | |
---|
[849] | 51 | =item --no-unexp |
---|
[842] | 52 | |
---|
| 53 | Take into account only propagated objects (attribute 'exported'=1) (default) |
---|
| 54 | |
---|
[2282] | 55 | =item -u|--username USER |
---|
| 56 | |
---|
| 57 | Simulated access like user USER is login |
---|
| 58 | |
---|
[842] | 59 | =back |
---|
| 60 | |
---|
| 61 | =cut |
---|
| 62 | |
---|
[2282] | 63 | my $LA = LATMOS::Accounts->new($config, noacl => $username ? 0 : 1); |
---|
[1044] | 64 | my $labase = $LA->base($base); |
---|
[842] | 65 | $labase && $labase->load or die "Cannot load base"; |
---|
| 66 | |
---|
[849] | 67 | $labase->unexported($nounexp ? 0 : 1); |
---|
[842] | 68 | |
---|
[2209] | 69 | my $Context = LATMOS::Accounts::Cli::Context->new( |
---|
[2285] | 70 | La => $LA, |
---|
[2209] | 71 | base => $labase, |
---|
| 72 | TransMode => $transmode ? 1 : 0, |
---|
| 73 | ); |
---|
[842] | 74 | |
---|
[2209] | 75 | my $Env = LATMOS::Accounts::Cli->new( |
---|
| 76 | Context => $Context, |
---|
| 77 | ); |
---|
| 78 | |
---|
[844] | 79 | if (@ARGV) { |
---|
[2285] | 80 | $Context->Interractive( 0 ); |
---|
[2209] | 81 | $Env->run(@ARGV); |
---|
[844] | 82 | } else { |
---|
[2209] | 83 | my $history = "$ENV{HOME}/.lacli_history"; |
---|
| 84 | $Env->Context->Term->ReadHistory($history); |
---|
| 85 | $Env->cli; |
---|
| 86 | if (! $Env->Context->Term->WriteHistory($history)) { |
---|
| 87 | warn "Cannot write history: $!\n"; |
---|
| 88 | } |
---|
[842] | 89 | } |
---|
| 90 | print "\n"; |
---|
| 91 | |
---|
| 92 | exit 0; |
---|
| 93 | |
---|