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-attributes - Show summary of supported objects and attributes of config bases |
---|
12 | |
---|
13 | =head1 SYNOPSIS |
---|
14 | |
---|
15 | List supported objects and attributes |
---|
16 | |
---|
17 | la-attributes [option] |
---|
18 | la-attributes [option] object |
---|
19 | |
---|
20 | =cut |
---|
21 | |
---|
22 | GetOptions( |
---|
23 | 'c|config=s' => \my $config, |
---|
24 | 'b|base=s' => \my @qbases, |
---|
25 | 'help' => sub { pod2usage(0) }, |
---|
26 | ) or pod2usage(); |
---|
27 | |
---|
28 | =head1 OPTIONS |
---|
29 | |
---|
30 | =over 4 |
---|
31 | |
---|
32 | =item -c|--config configdir |
---|
33 | |
---|
34 | Use this configuration directory instead of thr default one. |
---|
35 | |
---|
36 | =item -b|--base basename |
---|
37 | |
---|
38 | Perform query on this base(s) (can be set multiple times). |
---|
39 | |
---|
40 | =back |
---|
41 | |
---|
42 | =cut |
---|
43 | |
---|
44 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
45 | |
---|
46 | if (!@qbases) { @qbases = $LA->list_bases } |
---|
47 | |
---|
48 | if (my ($otype) = @ARGV) { |
---|
49 | my %supported; |
---|
50 | my @bases; |
---|
51 | my %unsupported; |
---|
52 | foreach my $basename (@qbases) { |
---|
53 | |
---|
54 | my $labase = $LA->base($basename) or next; |
---|
55 | push(@bases, $basename); |
---|
56 | $labase->is_supported_object($otype) or do { |
---|
57 | $unsupported{$basename} = 1; |
---|
58 | next; |
---|
59 | }; |
---|
60 | foreach($labase->list_canonical_fields($otype, 'a')) { |
---|
61 | my $attr = $labase->attribute($otype, $_); |
---|
62 | $supported{$_}{$basename} = sprintf('%s', |
---|
63 | $attr ? ($attr->ro ? 'r ' : 'rw') : ' ' |
---|
64 | ); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | if (! keys %supported) { |
---|
69 | die "No base support this object type $otype\n"; |
---|
70 | } |
---|
71 | |
---|
72 | my ($objlen) = sort { $b <=> $a } map { length($_) } keys %supported; |
---|
73 | $objlen+=1; |
---|
74 | my $header = '|' . (' ' x $objlen) . ' | ' . join(' | ', @bases) . ' |'; |
---|
75 | print '-' x length($header) . "\n"; |
---|
76 | print $header . "\n"; |
---|
77 | print '-' x length($header) . "\n"; |
---|
78 | foreach my $obj (sort keys %supported) { |
---|
79 | printf("|%${objlen}s |", $obj); |
---|
80 | foreach (@bases) { |
---|
81 | print(' '. |
---|
82 | ($unsupported{$_} |
---|
83 | ? 'NA' |
---|
84 | : $supported{$obj}{$_} || ' ') |
---|
85 | ); |
---|
86 | print ' ' x (length($_) - 2) . ' |'; |
---|
87 | } |
---|
88 | print "\n"; |
---|
89 | print '-' x length($header) . "\n"; |
---|
90 | } |
---|
91 | } else { |
---|
92 | my %supported; |
---|
93 | my @bases; |
---|
94 | foreach my $basename (@qbases) { |
---|
95 | |
---|
96 | my $labase = $LA->base($basename) or next; |
---|
97 | push(@bases, $basename); |
---|
98 | foreach($labase->list_supported_objects) { |
---|
99 | $supported{$_}{$basename} = 1; |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | my ($objlen) = sort { $b <=> $a } map { length($_) } keys %supported; |
---|
104 | $objlen+=1; |
---|
105 | my $header = '|' . (' ' x $objlen) . ' | ' . join(' | ', @bases) . ' |'; |
---|
106 | print '-' x length($header) . "\n"; |
---|
107 | print $header . "\n"; |
---|
108 | print '-' x length($header) . "\n"; |
---|
109 | foreach my $obj (sort keys %supported) { |
---|
110 | printf("|%${objlen}s |", $obj); |
---|
111 | foreach (@bases) { |
---|
112 | print($supported{$obj}{$_} ? ' x' : ' '); |
---|
113 | print ' ' x (length($_) - 1) . ' |'; |
---|
114 | } |
---|
115 | print "\n"; |
---|
116 | print '-' x length($header) . "\n"; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | __END__ |
---|