1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use LATMOS::Accounts; |
---|
6 | use Getopt::Long; |
---|
7 | use 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 | |
---|
23 | Use this configuration file instead default |
---|
24 | |
---|
25 | =item --base basename |
---|
26 | |
---|
27 | Perform 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 | |
---|
33 | The "format" string may query tags in form: |
---|
34 | |
---|
35 | %{ATTRIBUTE:printflike} |
---|
36 | |
---|
37 | Where ATTRIBUTE is the name of an attribute and the optional |
---|
38 | C<:printflike> is a printf like string to print the attribute content |
---|
39 | (without the C<%>). |
---|
40 | |
---|
41 | Examples 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 | |
---|
49 | Filter are in form "[ATTRIBUTE][OPERATOR][VALUE]" |
---|
50 | |
---|
51 | where attribute is a supported attribute. |
---|
52 | |
---|
53 | OPERATOR can be: |
---|
54 | |
---|
55 | =over 4 |
---|
56 | |
---|
57 | =item C<=> |
---|
58 | |
---|
59 | Search object having attribute strictely equal to VALUE. If VALUE is C<*> match |
---|
60 | any non empty value. |
---|
61 | |
---|
62 | =item C<~> |
---|
63 | |
---|
64 | Search object having attribute containing VALUE. |
---|
65 | |
---|
66 | =back |
---|
67 | |
---|
68 | =cut |
---|
69 | |
---|
70 | GetOptions( |
---|
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 | |
---|
78 | if (!$ARGV[0]) {print "You must specify 'filter', aborting\n"; pod2usage(); } |
---|
79 | |
---|
80 | $otype ||= 'user'; |
---|
81 | |
---|
82 | my $LA = LATMOS::Accounts->new($config); |
---|
83 | my $labase = $base ? $LA->base($base) : $LA->default_base; |
---|
84 | $labase && $labase->load or die "Cannot load base"; |
---|
85 | |
---|
86 | my @result = $labase->search_objects($otype, @ARGV); |
---|
87 | foreach (@result) { |
---|
88 | if ($fmt) { |
---|
89 | my $o = $labase->queryformat($fmt); |
---|
90 | } else { |
---|
91 | print "$_\n"; |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | warn "\n" . scalar(@result) . " results\n"; |
---|
96 | exit(0); |
---|