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