Minor style cleanups, version bump.
FossilOrigin-Name: 57f9fdc9c093cdb13c45a219d0a56902b9d6b23b6f82adf5ed5c08855753dc6a
This commit is contained in:
parent
7cc910744f
commit
fb34a4b020
1 changed files with 79 additions and 71 deletions
150
shelldap
150
shelldap
|
|
@ -476,8 +476,8 @@ sub init
|
||||||
$self->{'API'}->{'match_uniq'} = 0;
|
$self->{'API'}->{'match_uniq'} = 0;
|
||||||
|
|
||||||
$self->{'editor'} = $conf->{'editor'} || $ENV{'EDITOR'} || 'vi';
|
$self->{'editor'} = $conf->{'editor'} || $ENV{'EDITOR'} || 'vi';
|
||||||
$self->{'pager'} = $conf->{'pager'} || $ENV{'PAGER'} || 'less';
|
$self->{'pager'} = $conf->{'pager'} || $ENV{'PAGER'} || 'less';
|
||||||
$self->{'env'} = [ qw/ debug cacheage timeout / ];
|
$self->{'env'} = [ qw/ debug cacheage timeout / ];
|
||||||
|
|
||||||
# let autocomplete work with the '=' character
|
# let autocomplete work with the '=' character
|
||||||
my $term = $self->term();
|
my $term = $self->term();
|
||||||
|
|
@ -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
|
||||||
|
|
@ -1129,8 +1198,8 @@ sub comp_inspect
|
||||||
my $sub = "comp_$_";
|
my $sub = "comp_$_";
|
||||||
*$sub = \&autocomplete_cwd;
|
*$sub = \&autocomplete_cwd;
|
||||||
}
|
}
|
||||||
*comp_touch = \&comp_create;
|
*comp_touch = \&comp_create;
|
||||||
*comp_export = \&comp_setenv;
|
*comp_export = \&comp_setenv;
|
||||||
|
|
||||||
# setup alias subs
|
# setup alias subs
|
||||||
#
|
#
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue