]> git.proxmox.com Git - pve-common.git/blame_incremental - data/PVE/PodParser.pm
fix date in copyright message
[pve-common.git] / data / PVE / PodParser.pm
... / ...
CommitLineData
1package PVE::PodParser;
2
3use strict;
4use Pod::Parser;
5use base qw(Pod::Parser);
6
7my $currentYear = (localtime(time))[5] + 1900;
8
9my $stdinclude = {
10 pve_copyright => <<EODATA,
11\=head1 COPYRIGHT AND DISCLAIMER
12
13Copyright (C) 2007-$currentYear Proxmox Server Solutions GmbH
14
15This program is free software: you can redistribute it and\/or modify
16it under the terms of the GNU Affero General Public License as
17published by the Free Software Foundation, either version 3 of the
18License, or (at your option) any later version.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23GNU Affero General Public License for more details.
24
25You should have received a copy of the GNU Affero General Public License
26along with this program. If not, see L<http://www.gnu.org/licenses/>.
27EODATA
28};
29
30sub command {
31 my ($self, $cmd, $text, $line_num, $pod_para) = @_;
32
33 if (($cmd eq 'include' && $text =~ m/^\s*(\S+)\s/)) {
34 my $incl = $1;
35 my $data = $stdinclude->{$incl} ? $stdinclude->{$incl} :
36 $self->{include}->{$incl};
37 chomp $data;
38 $self->textblock("$data\n\n", $line_num, $pod_para);
39 } else {
40 $self->textblock($pod_para->raw_text(), $line_num, $pod_para);
41 }
42}
43
44# helpers used to generate our manual pages
45
46sub schema_get_type_text {
47 my ($phash) = @_;
48
49 if ($phash->{typetext}) {
50 return $phash->{typetext};
51 } elsif ($phash->{enum}) {
52 return "(" . join(' | ', sort @{$phash->{enum}}) . ")";
53 } elsif ($phash->{pattern}) {
54 return $phash->{pattern};
55 } elsif ($phash->{type} eq 'integer' || $phash->{type} eq 'number') {
56 if (defined($phash->{minimum}) && defined($phash->{maximum})) {
57 return "$phash->{type} ($phash->{minimum} - $phash->{maximum})";
58 } elsif (defined($phash->{minimum})) {
59 return "$phash->{type} ($phash->{minimum} - N)";
60 } elsif (defined($phash->{maximum})) {
61 return "$phash->{type} (-N - $phash->{maximum})";
62 }
63 }
64
65 my $type = $phash->{type} || 'string';
66
67 return $type;
68}
69
70# generta epop from JSON schema properties
71sub dump_properties {
72 my ($properties) = @_;
73
74 my $data = "=over 1\n\n";
75
76 my $idx_param = {}; # -vlan\d+ -scsi\d+
77
78 foreach my $key (sort keys %$properties) {
79 my $d = $properties->{$key};
80 my $base = $key;
81 if ($key =~ m/^([a-z]+)(\d+)$/) {
82 my $name = $1;
83 next if $idx_param->{$name};
84 $idx_param->{$name} = 1;
85 $base = "${name}[n]";
86 }
87
88 my $descr = $d->{description} || 'No description avalable.';
89 chomp $descr;
90
91 if (defined(my $dv = $d->{default})) {
92 my $multi = $descr =~ m/\n\n/; # multi paragraph ?
93 $descr .= $multi ? "\n\n" : " ";
94 $descr .= "Default value is '$dv'.";
95 }
96
97 my $typetext = schema_get_type_text($d);
98 $data .= "=item $base: $typetext\n\n";
99 $data .= "$descr\n\n";
100 }
101
102 $data .= "=back";
103
104 return $data;
105}
106
1071;