Thread: [LDAPsh-cvs] ldapsh ldapsh,1.20,1.20.6.1
Status: Beta
Brought to you by:
rcorvalan
From: <j-d...@us...> - 2003-07-27 07:42:14
|
Update of /cvsroot/ldapsh/ldapsh In directory sc8-pr-cvs1:/tmp/cvs-serv4036 Modified Files: Tag: PATCH-778368 ldapsh Log Message: 1) Added "add", "replace", "delete" for editing attributes. 2) Added tab completion for attribute names and values. Index: ldapsh =================================================================== RCS file: /cvsroot/ldapsh/ldapsh/ldapsh,v retrieving revision 1.20 retrieving revision 1.20.6.1 diff -C2 -d -r1.20 -r1.20.6.1 *** ldapsh 27 Jul 2003 07:03:01 -0000 1.20 --- ldapsh 27 Jul 2003 07:42:11 -0000 1.20.6.1 *************** *** 184,188 **** use Data::Dumper qw(Dumper); use Unicode::MapUTF8 qw(to_utf8 from_utf8); ! use subs qw(connect bind dump exit reset); BEGIN { --- 184,188 ---- use Data::Dumper qw(Dumper); use Unicode::MapUTF8 qw(to_utf8 from_utf8); ! use subs qw(connect bind delete dump exit reset); BEGIN { *************** *** 600,603 **** --- 600,606 ---- if ($cmd =~ /^(cd|acd|setdn|pushd|cat|vi|ls|list|dump|ldif|search|cp)$/) { return _cdCommandCompletion(@_); + } elsif ($cmd =~ /^(add|replace|delete)$/) { + # Attribute Completion + return _attributeEditCompletion(@_); } else { return(); *************** *** 631,640 **** return _entryDNCompletion($prefix, $attr, $partToComplete, $BaseDN); } else { ! return _attributeNamesCompletion($prefix, $partToComplete, $BaseDN); } } ! sub _attributeNamesCompletion($$$) { my ($prefix, $partToComplete, $BaseDN) = @_; $TermAttribs->{completion_append_character} = "\0"; --- 634,681 ---- return _entryDNCompletion($prefix, $attr, $partToComplete, $BaseDN); } else { ! return _attributeNamesDNCompletion($prefix, $partToComplete, $BaseDN); } } + sub _attributeEditCompletion{ + my ($text, $line, $start, $end) = @_; + + # Put argument delimiter after current comma + if ($text =~ /,$/) { + $TermAttribs->{completion_append_character} = ' '; + return $text; + } + + my $entries = $Globals->{ENTRIES}{VALUE}; + + unless (defined($entries) && scalar(@{$entries}) > 0) { + return undef; + } + + $TermAttribs->{completion_append_character} = "\0"; + + if (substr($line, 0, $start) =~ /,/) { + my ($name) = ($line =~ /^\S+\s+([^,]*)/); + return undef unless defined($name); + if ($name =~ /^['"]/) { + $name = substr($name, 1, length($name)-2); + } + my @possible_entries = @{$entries}[0]->get_value($name); + @possible_entries = grep {/^$text/i} @possible_entries; + return undef unless scalar(@possible_entries); + # TODO find longest common prefix + return $text, @possible_entries; + } else { + my @possible_entries = @{$entries}[0]->attributes(); + @possible_entries = grep {/^$text/i} @possible_entries; + return undef unless scalar(@possible_entries); + # TODO find longest common prefix + # TODO use a cache + return $text, @possible_entries; + } + return undef; + } ! sub _attributeNamesDNCompletion($$$) { my ($prefix, $partToComplete, $BaseDN) = @_; $TermAttribs->{completion_append_character} = "\0"; *************** *** 1639,1642 **** --- 1680,1777 ---- map { &$code; } @$entries; + return 1; + } + + + =head3 add + + B<Synopsis>: C<add 'E<lt>attributeE<gt>', 'E<lt>valueE<gt>' ...> + + Add one or more new attributes to the entries in the L<$ENTRIES|"$ENTRIES"> global variable. + + The values will be added to the values that already exist for the given attribute. + + The entries are locally modified! You must L<commit|commit>! You can see the changes + done using the L<changes|changes> command. + + Example: C<add 'givenName', 'Bob', 'Robert'> + + =cut + + sub add { + my $entries = $Globals->{ENTRIES}{VALUE}; + + _haveentries() or return 0; + + if (scalar @_ < 2) { + print STDERR "You must supply both an attribute and some values.\n"; + return 0; + } + + my $attr = shift; + + map { $_->add($attr, [@_]) } @$entries; + return 1; + } + + + =head3 replace + + B<Synopsis>: C<replace 'E<lt>attributeE<gt>', 'E<lt>valueE<gt>' ...> + + Similar to L<add|add>, except that the given values will replace any values that + already exist for the given attribute. + + The entries are merely locally modified! You must L<commit|commit>! You can see the changes + using the L<changes|changes> command. + + Example: C<replace 'givenName', 'Bill', 'William'> + + =cut + + sub replace { + my $entries = $Globals->{ENTRIES}{VALUE}; + + _haveentries() or return 0; + + if (scalar @_ < 2) { + print STDERR "You must supply both an attribute and some values.\n"; + return 0; + } + + my $attr = shift; + + map { $_->replace($attr, [@_]) } @$entries; + return 1; + } + + + =head3 delete + + B<Synopsis>: C<delete 'E<lt>attributeE<gt>'[, 'E<lt>valueE<gt>' ...]> + + Delete the values of given attribute from the the L<$ENTRIES|"$ENTRIES"> global variable. + If no values are given, the entire attribute will be deleted. + + The entries are locally modified! You must L<commit|commit>! You can see the changes + done using the L<changes|changes> command. + + Example: C<delete 'givenName'> + + =cut + + sub delete { + my $entries = $Globals->{ENTRIES}{VALUE}; + + _haveentries() or return 0; + + if (scalar @_ < 1) { + print STDERR "You must at least supply an attribute name.\n"; + return 0; + } + + my $attr = shift; + + map { $_->delete($attr, [@_]) } @$entries; return 1; } |