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-config - Tools to query configuration of LATMOS::Accounts system. |
---|
12 | |
---|
13 | =head1 SYNOPSIS |
---|
14 | |
---|
15 | Show configured bases: |
---|
16 | |
---|
17 | la-config |
---|
18 | |
---|
19 | List supported attribute: |
---|
20 | |
---|
21 | la-config [option] att |
---|
22 | la-config [option] att objects_type |
---|
23 | |
---|
24 | =cut |
---|
25 | |
---|
26 | GetOptions( |
---|
27 | 'c|config=s' => \my $config, |
---|
28 | 'b|base=s' => \my $base, |
---|
29 | 'help' => sub { pod2usage(0) }, |
---|
30 | ) or pod2usage(); |
---|
31 | |
---|
32 | =head1 OPTIONS |
---|
33 | |
---|
34 | =item -c|--config configfile |
---|
35 | |
---|
36 | Use this configuration file instead default |
---|
37 | |
---|
38 | =item -b|--base basename |
---|
39 | |
---|
40 | Perform query on this base |
---|
41 | |
---|
42 | =cut |
---|
43 | |
---|
44 | my $LA = LATMOS::Accounts->new($config); |
---|
45 | |
---|
46 | my $action = shift(@ARGV) || ''; |
---|
47 | for ($action) { |
---|
48 | m/^$/ and do { |
---|
49 | my $default = $LA->default_base_name || ''; |
---|
50 | print "Bases:\n"; |
---|
51 | foreach ($LA->list_bases) { |
---|
52 | printf(" %s %s (%s)\n", |
---|
53 | ($_ eq $default ? '*' : ' '), |
---|
54 | $_, |
---|
55 | $LA->val($_, 'type', 'Err: no type') |
---|
56 | ); |
---|
57 | } |
---|
58 | my $default_sync = $LA->default_synchro_name || ''; |
---|
59 | print "Syncro:\n"; |
---|
60 | foreach ($LA->list_synchro) { |
---|
61 | printf(" %s %s (%s => %s)\n", |
---|
62 | ($_ eq $default_sync ? '*' : ' '), |
---|
63 | $_, |
---|
64 | $LA->val("sync:$_", 'from', 'Err: No from'), |
---|
65 | join(', ', $LA->val("sync:$_", 'to', 'Err: No to')), |
---|
66 | ); |
---|
67 | } |
---|
68 | last; |
---|
69 | }; |
---|
70 | m/^att(ributes)?$/ and do { |
---|
71 | my $labase = $base ? $LA->base($base) : $LA->default_base; |
---|
72 | if (my $otype = shift(@ARGV)) { |
---|
73 | printf "Supported field for object type %s (base %s)\n", |
---|
74 | $otype, |
---|
75 | $base ? $base : $LA->default_base_name; |
---|
76 | printf( |
---|
77 | " %s (%s%s)\n", $_, |
---|
78 | ($labase->get_field_name($otype, $_, 'r') ? 'r' : ' '), |
---|
79 | ($labase->get_field_name($otype, $_, 'w') ? 'w' : ' '), |
---|
80 | ) foreach($labase->list_canonicals_fields($otype, 'a')); |
---|
81 | } else { |
---|
82 | printf "Supported object type by base %s\n", |
---|
83 | $base ? $base : $LA->default_base_name; |
---|
84 | print " $_\n" foreach($labase->list_supported_objects); |
---|
85 | } |
---|
86 | }; |
---|
87 | } |
---|