]>
Commit | Line | Data |
---|---|---|
e143e9d8 DM |
1 | package PVE::PodParser; |
2 | ||
3 | use strict; | |
4 | use Pod::Parser; | |
5 | use base qw(Pod::Parser); | |
6 | ||
d415354b DM |
7 | my $currentYear = (localtime(time))[5] + 1900; |
8 | ||
e143e9d8 DM |
9 | my $stdinclude = { |
10 | pve_copyright => <<EODATA, | |
11 | \=head1 COPYRIGHT AND DISCLAIMER | |
12 | ||
d415354b | 13 | Copyright (C) 2007-$currentYear Proxmox Server Solutions GmbH |
e143e9d8 DM |
14 | |
15 | This program is free software: you can redistribute it and\/or modify | |
16 | it under the terms of the GNU Affero General Public License as | |
17 | published by the Free Software Foundation, either version 3 of the | |
18 | License, or (at your option) any later version. | |
19 | ||
20 | This program is distributed in the hope that it will be useful, | |
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | GNU Affero General Public License for more details. | |
24 | ||
25 | You should have received a copy of the GNU Affero General Public License | |
26 | along with this program. If not, see L<http://www.gnu.org/licenses/>. | |
27 | EODATA | |
28 | }; | |
29 | ||
30 | sub 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 | ||
46 | sub 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 | |
71 | sub 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 | ||
107 | 1; |