Minor style cleanups, version bump.

FossilOrigin-Name: 57f9fdc9c093cdb13c45a219d0a56902b9d6b23b6f82adf5ed5c08855753dc6a
This commit is contained in:
mahlon@laika.com 2014-12-04 22:15:09 +00:00
parent 7cc910744f
commit fb34a4b020

142
shelldap
View file

@ -667,6 +667,7 @@ sub ldif
} }
# ldif -> stdout # ldif -> stdout
#
else { else {
$self->{'ldif'} = Net::LDAP::LDIF->new( \*STDOUT, 'w', sort => 1, wrap => $self->wrapsize ); $self->{'ldif'} = Net::LDAP::LDIF->new( \*STDOUT, 'w', sort => 1, wrap => $self->wrapsize );
} }
@ -803,6 +804,74 @@ sub is_valid_dn
} }
### Emit LDIF to the terminal.
###
sub display
{
my $self = shift;
my $dn = shift;
my @attrs = @{;shift};
my $use_pager = shift;
unless ( $dn ) {
print "No dn provided.\n";
return;
}
# support '.'
$dn = $self->base() if $dn eq '.';
# support globbing
#
my $s;
if ( $dn eq '*' ) {
$s = $self->search({
scope => 'one',
vals => 1,
attrs => \@attrs
});
}
elsif ( $dn =~ /\*/ ) {
$s = $self->search({
scope => 'one',
vals => 1,
filter => $dn,
attrs => \@attrs
});
}
# absolute/relative dn
#
else {
$dn = $self->path_to_dn( $dn );
$s = $self->search({
base => $dn,
vals => 1,
attrs => \@attrs
});
}
# emit error, if any
#
if ( $s->{'code'} ) {
print $s->{'message'} . "\n";
return;
}
# display to stdout or pager
#
my $ldif = $self->ldif( $use_pager );
foreach my $e ( @{ $s->{'entries'} } ) {
$ldif->write_entry( $e );
}
if( $use_pager ) {
system( $self->{'pager'}, $self->{'ldif_fname'} );
unlink $self->{'ldif_fname'};
}
return;
}
### Perform an LDAP search. ### Perform an LDAP search.
### ###
### Returns a hashref containing the return code and ### Returns a hashref containing the return code and
@ -1202,80 +1271,19 @@ sub run_cat
my $dn = shift; my $dn = shift;
my @attrs = (@_) ? @_ : ('*'); my @attrs = (@_) ? @_ : ('*');
display($self, $dn, \@attrs, 0); $self->display( $dn, \@attrs, 0 );
} }
### Display an entry as LDIF to the terminal with external pagination.
###
sub run_less sub run_less
{ {
my $self = shift; my $self = shift;
my $dn = shift; my $dn = shift;
my @attrs = (@_) ? @_ : ('*'); my @attrs = (@_) ? @_ : ('*');
display($self, $dn, \@attrs, 1); $self->display( $dn, \@attrs, 1 );
}
sub display{
my $self = shift;
my $dn = shift;
my @attrs = @{;shift};
my $use_pager = shift;
unless ( $dn ) {
print "No dn provided.\n";
return;
}
# support '.'
$dn = $self->base() if $dn eq '.';
# support globbing
#
my $s;
if ( $dn eq '*' ) {
$s = $self->search({
scope => 'one',
vals => 1,
attrs => \@attrs
});
}
elsif ( $dn =~ /\*/ ) {
$s = $self->search({
scope => 'one',
vals => 1,
filter => $dn,
attrs => \@attrs
});
}
# absolute/relative dn
#
else {
$dn = $self->path_to_dn( $dn );
$s = $self->search({
base => $dn,
vals => 1,
attrs => \@attrs
});
}
# emit error, if any
#
if ( $s->{'code'} ) {
print $s->{'message'} . "\n";
return;
}
# display to stdout or pager
#
my $ldif = $self->ldif($use_pager);
foreach my $e ( @{ $s->{'entries'} } ) {
$ldif->write_entry( $e );
}
if($use_pager) {
system( $self->{'pager'}, $self->{'ldif_fname'} );
unlink $self->{'ldif_fname'};
}
return;
} }
@ -2278,7 +2286,7 @@ use strict;
use warnings; use warnings;
$0 = 'shelldap'; $0 = 'shelldap';
my $VERSION = '1.2.0'; my $VERSION = '1.3.0';
use Getopt::Long; use Getopt::Long;
use YAML::Syck; use YAML::Syck;