source: LATMOS-Accounts/bin/la-config @ 656

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

Typos dans l'aide en ligne de commande

  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
File size: 2.3 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-config - Tools to query configuration of LATMOS::Accounts system.
12
13=head1 SYNOPSIS
14
15List supported base, synchronisation, objects and attributes
16
17    la-config [option] [object]
18
19=cut
20
21GetOptions(
22    'c|config=s' => \my $config,
23    'lb'         => \my $listbases,
24    'ls'         => \my $listsynchros,
25    'base=s'     => \my $base,
26    'help'       => sub { pod2usage(0) },
27) or pod2usage();
28
29=head1 OPTIONS
30
31=item -c|--config configfile
32
33Use this configuration file instead of the default one.
34
35=item -b|--base basename
36
37Perform query on this base
38
39=item --lb
40
41List base setup in config
42
43=item --ls
44
45List synchronisation setup in config
46
47=cut
48
49my $LA = LATMOS::Accounts->new($config, noacl => 1);
50
51if ($listbases) {
52    my $default = $LA->default_base_name || '';
53    print "Bases:\n";
54    foreach ($LA->list_bases) {
55        printf("  %s %s (%s)\n",
56            ($_ eq $default ? '*' : ' '),
57            $_,
58            $LA->val($_, 'type', 'Err: no type')
59        );
60    }
61}
62if ($listsynchros) {
63    my $default_sync = $LA->default_synchro_name || '';
64    print "Syncro:\n";
65    foreach ($LA->list_synchro) {
66        printf("  %s %s (%s => %s)\n",
67            ($_ eq $default_sync ? '*' : ' '),
68            $_,
69            $LA->val("sync:$_", 'from', 'Err: No from'),
70            join(', ', $LA->val("sync:$_", 'to', 'Err: No to')),
71        );
72    }
73}
74if (!($listsynchros || $listbases)) {
75    if (my $otype = $ARGV[0]) {
76        my $labase = $base ? $LA->base($base) : $LA->default_base;
77        printf "Supported field for object type %s (base %s)\n",
78        $otype,
79        $base ? $base : $LA->default_base_name;
80        printf(
81            "  %s (%s%s)\n", $_,
82            ($labase->get_field_name($otype, $_, 'r') ? 'r' : ' '),
83            ($labase->get_field_name($otype, $_, 'w') ? 'w' : ' '),
84        ) foreach($labase->list_canonical_fields($otype, 'a'));
85    } else {
86        my $labase = $base ? $LA->base($base) : $LA->default_base
87            or die "Cannot instanciate " .
88            $base ? $base : $LA->default_base_name . "\n";
89        printf "Supported object type by base %s\n",
90            $base ? $base : $LA->default_base_name;
91        print "  $_\n" foreach($labase->list_supported_objects);
92    }
93}
Note: See TracBrowser for help on using the repository browser.