source: trunk/LATMOS-Accounts/bin/la-sql-attrvalues @ 2363

Last change on this file since 2363 was 2094, checked in by nanardon, 7 years ago

Allow to set allowed_values insde database instead config, this work only for SQL base

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8use Term::ReadKey;
9
10=head1 NAME
11
12    la-sql-attrvalue - Set limited choice to attributes
13
14=head1 SYNOPSIS
15
16    la-rename [options] attribute [value]
17
18=head1 OPTIONS
19
20=over 4
21
22=item -c|--config configdir
23
24Use this configuration directory instead of the default one.
25
26=item -b|--base basename
27
28Query this specific base instead of the default one.
29
30=item -o|--otype otype
31
32Modify object having type 'otype', default is user
33
34=item -r|--remove
35
36Remove the given value (or all if no value are given)
37
38=back
39
40=cut
41
42GetOptions(
43    'c|config=s' => \my $config,
44    'b|base=s'   => \my $base,
45    't|test'     => \my $test,
46    'o|otype=s'  => \my $otype,
47    'r|remove'   => \my $remove,
48    'help'       => sub { pod2usage(0) },
49) or pod2usage();
50
51my ($attribute, @values) = @ARGV;
52
53if (!$attribute) { pod2usage(); }
54
55$otype ||= 'user';
56
57my $LA = LATMOS::Accounts->new($config, noacl => 1);
58my $labase = $LA->base($base);
59$labase && $labase->load or die "Cannot load base\n";
60
61if ($remove) {
62    $labase->DelAttrValue($otype, $attribute, @values) or die "Cannot remove this value";
63} else {
64    if (@values) {
65        $labase->AddAttrValue($otype, $attribute, @values) or die "Cannot add this value";
66    }
67
68    print "Otype: $otype, Attribute: $attribute\n";
69    foreach ($labase->ListAttrValue($otype, $attribute)) {
70        print "\t$_\n";
71    }
72}
73
74
75$labase->commit;
Note: See TracBrowser for help on using the repository browser.