]> git.proxmox.com Git - pve-client.git/blob - extractapi.pl
cleanup: use nested CLIHandler command definitions
[pve-client.git] / extractapi.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Storable;
6
7 use PVE::RESTHandler;
8 use PVE::API2;
9
10 sub remove_code_refs {
11 my ($tree) = @_;
12
13 my $class = ref($tree);
14 return if !$class;
15
16 if ($class eq 'ARRAY') {
17 foreach my $el (@$tree) {
18 remove_code_refs($el);
19 }
20 } elsif ($class eq 'HASH') {
21 foreach my $k (keys %$tree) {
22 if (my $itemclass = ref($tree->{$k})) {
23 if ($itemclass eq 'CODE') {
24 undef $tree->{$k};
25 } elsif ($itemclass eq 'Regexp') {
26 $tree->{$k} = "$tree"; # return string representation
27 } else {
28 remove_code_refs($tree->{$k});
29 }
30 }
31 }
32 }
33 }
34
35 my $tree = PVE::RESTHandler::api_dump('PVE::API2', undef, 1);
36
37 remove_code_refs($tree);
38 Storable::store_fd($tree, \*STDOUT);
39
40 exit(0);