]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl -w | |
2 | ||
3 | use strict; | |
4 | use PVE::RESTHandler; | |
5 | use PVE::API2; | |
6 | use JSON; | |
7 | ||
8 | sub cleanup_tree { | |
9 | my ($h) = @_; | |
10 | ||
11 | my $class = ref($h); | |
12 | return $h if !$class; | |
13 | ||
14 | if ($class eq 'ARRAY') { | |
15 | my $res = []; | |
16 | foreach my $el (@$h) { | |
17 | push @$res, cleanup_tree($el); | |
18 | } | |
19 | return $res; | |
20 | } elsif ($class eq 'HASH') { | |
21 | my $res = {}; | |
22 | foreach my $k (keys %$h) { | |
23 | if (my $class = ref($h->{$k})) { | |
24 | if ($class eq 'CODE') { | |
25 | next if $k eq 'completion'; | |
26 | } | |
27 | $res->{$k} = cleanup_tree($h->{$k}); | |
28 | } else { | |
29 | $res->{$k} = $h->{$k}; | |
30 | } | |
31 | } | |
32 | return $res; | |
33 | } elsif ($class eq 'Regexp') { | |
34 | return "$h"; # return string representation | |
35 | } else { | |
36 | die "unknown class '$class'\n"; | |
37 | } | |
38 | } | |
39 | ||
40 | my $tree = cleanup_tree(PVE::RESTHandler::api_dump('PVE::API2')); | |
41 | ||
42 | print "var pveapi = " . to_json($tree, {pretty => 1, canonical => 1}) . ";\n\n"; | |
43 | ||
44 | exit(0); |