source: LATMOS-Accounts/bin/la-search @ 655

Last change on this file since 655 was 655, checked in by vivat, 14 years ago

Ajout d'un message d'erreur lorsqu'un parametre obligatoire n'est pas fourni

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8
9=head1 NAME
10
11    la-search - Perform object search in Latmos::Accounts base
12
13=head1 SYNOPSIS
14
15    la-search [options] filter [filter2 [...]]
16
17=head1 OPTIONS
18
19=over 4
20
21=item --config configfile
22
23Use this configuration file instead default
24
25=item --base basename
26
27Perform search in this specific base instead default
28
29=item --fmt format
30
31(Only if NO obj_id is given) Specify a format of output.
32
33The "format" string may query tags in form:
34
35    %{ATTRIBUTE:printflike}
36
37Where ATTRIBUTE is the name of an attribute and the optional
38C<:printflike> is a printf like string to print the attribute content
39(without the C<%>).
40
41Examples for users:
42
43    --fmt "Name %{sn}, First Name %{givenName}\n"
44
45    --fmt "Name %{sn:20s}, First Name %{givenName}\n"
46
47=item FILTER
48
49Filter are in form "[ATTRIBUTE][OPERATOR][VALUE]"
50
51where attribute is a supported attribute.
52
53OPERATOR can be:
54
55=over 4
56
57=item C<=>
58
59Search object having attribute strictely equal to VALUE. If VALUE is C<*> match
60any non empty value.
61
62=item C<~>
63
64Search object having attribute containing VALUE.
65
66=back
67
68=cut
69
70GetOptions(
71    'c|config=s' => \my $config,
72    'b|base=s'   => \my $base,
73    'o|object=s' => \my $otype,
74    'fmt=s'      => \my $fmt,
75    'help'       => sub { pod2usage(0) },
76) or pod2usage();
77
78if (!$ARGV[0]) {print "You must specify 'filter', aborting\n"; pod2usage(); }
79
80$otype ||= 'user';
81
82my $LA = LATMOS::Accounts->new($config);
83my $labase = $base ? $LA->base($base) : $LA->default_base;
84$labase && $labase->load or die "Cannot load base";
85
86my @result = $labase->search_objects($otype, @ARGV);
87foreach (@result) {
88    if ($fmt) {
89        my $o = $labase->queryformat($fmt);
90    } else {
91        print "$_\n";
92    }
93}
94
95warn "\n" . scalar(@result) . " results\n";
96exit(0);
Note: See TracBrowser for help on using the repository browser.