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

150
shelldap
View file

@ -476,8 +476,8 @@ sub init
$self->{'API'}->{'match_uniq'} = 0;
$self->{'editor'} = $conf->{'editor'} || $ENV{'EDITOR'} || 'vi';
$self->{'pager'} = $conf->{'pager'} || $ENV{'PAGER'} || 'less';
$self->{'env'} = [ qw/ debug cacheage timeout / ];
$self->{'pager'} = $conf->{'pager'} || $ENV{'PAGER'} || 'less';
$self->{'env'} = [ qw/ debug cacheage timeout / ];
# let autocomplete work with the '=' character
my $term = $self->term();
@ -667,6 +667,7 @@ sub ldif
}
# ldif -> stdout
#
else {
$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.
###
### Returns a hashref containing the return code and
@ -1129,8 +1198,8 @@ sub comp_inspect
my $sub = "comp_$_";
*$sub = \&autocomplete_cwd;
}
*comp_touch = \&comp_create;
*comp_export = \&comp_setenv;
*comp_touch = \&comp_create;
*comp_export = \&comp_setenv;
# setup alias subs
#
@ -1202,80 +1271,19 @@ sub run_cat
my $dn = shift;
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
{
my $self = shift;
my $dn = shift;
my @attrs = (@_) ? @_ : ('*');
display($self, $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;
$self->display( $dn, \@attrs, 1 );
}
@ -2278,7 +2286,7 @@ use strict;
use warnings;
$0 = 'shelldap';
my $VERSION = '1.2.0';
my $VERSION = '1.3.0';
use Getopt::Long;
use YAML::Syck;