Commit 2c512dbc authored by Xavier Guimard's avatar Xavier Guimard

First Cli : get base keys only for now

parent 2b35cb6e
package Lemonldap::NG::Manager::Cli;
use strict;
use Mouse;
use 5.14.0;
use Data::Dumper;
extends('Lemonldap::NG::Manager::Cli::Lib');
has cfgNum => (
is => 'rw',
isa => 'Int',
trigger => sub {
$_[0]->{req} =
Lemonldap::NG::Manager::Cli::Request->new(
cfgNum => $_[0]->{cfgNum} );
}
);
has req => ( is => 'ro' );
sub get {
my ( $self, @values ) = @_;
$self->cfgNum( $self->lastCfg ) unless ( $self->cfgNum );
die 'get requires at least one key' unless (@values);
L: foreach my $key (@values) {
unless ( $key =~ /^\w+(?:\/[\w\.]+)*$/ ) {
warn "Unknown key $key";
next L;
}
my $value = $self->mgr->getConfKey( $self->req, $key );
#$value = Dumper($value);
#$value =~ s/\$VAR1/$key/;
#print $value;
if(ref $value eq 'HASH') {
print "$key has the following keys:\n";
print " $_\n" foreach(sort keys %$value);
}
else {
print "$key = $value\n";
}
}
}
sub lastCfg {
my ($self) = @_;
return $self->jsonResponse('/confs/latest')->{cfgNum};
}
sub run {
my $self = shift;
unless (@_) {
die 'nothing to do, aborting';
}
my $action = shift;
unless ( $action =~ /^(?:get|set)$/ ) {
die "unknown action $action";
}
$self->$action(@_);
}
package Lemonldap::NG::Manager::Cli::Request;
use Mouse;
has cfgNum => ( is => 'rw' );
has error => ( is => 'rw' );
sub params {
my ( $self, $key ) = @_;
return $self->{$key};
}
1;
......@@ -4,18 +4,20 @@ use JSON::MaybeXS;
use Mouse;
use Lemonldap::NG::Manager;
has iniFile => ( is => 'ro', isa => 'Str', required => 1 );
has iniFile => ( is => 'ro', isa => 'Str' );
has mgr => ( is => 'ro', isa => 'Lemonldap::NG::Manager' );
has app => (
is => 'ro',
isa => 'CodeRef',
builder => sub {
return Lemonldap::NG::Manager->run(
{
configStorage => { confFile => $_[0]->{iniFile} },
protection => 'none',
}
);
is => 'ro',
isa => 'CodeRef',
builder => sub {
my $args = { protection => 'none' };
$args->{configStorage} = { confFile => $_[0]->{iniFile} }
if ( $_[0]->{iniFile} );
$_[0]->{mgr} = Lemonldap::NG::Manager->new($args);
$_[0]->{mgr}->init($args);
return $_[0]->{mgr}->run();
}
);
......
#!/usr/bin/env perl
use warnings;
use strict;
use Lemonldap::NG::Manager::Cli;
my $cli = Lemonldap::NG::Manager::Cli->new(iniFile=>'t/lemonldap-ng.ini');
$cli->run(@ARGV);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment