pve-client/extractapi.pl
Dietmar Maurer ab79ce7802 use binary format to store API definition efficently
Note: The previous file does not contains indexed parameters like -net\d+ (those
were converted to to -net[n]). But we need all those parameters for the command
line completion. The binary format is much smaller the json, because it can handle
references.
2018-06-12 11:17:45 +02:00

41 lines
747 B
Perl
Executable File

#!/usr/bin/perl
use strict;
use warnings;
use Storable;
use PVE::RESTHandler;
use PVE::API2;
sub remove_code_refs {
my ($tree) = @_;
my $class = ref($tree);
return if !$class;
if ($class eq 'ARRAY') {
foreach my $el (@$tree) {
remove_code_refs($el);
}
} elsif ($class eq 'HASH') {
foreach my $k (keys %$tree) {
if (my $itemclass = ref($tree->{$k})) {
if ($itemclass eq 'CODE') {
undef $tree->{$k};
} elsif ($itemclass eq 'Regexp') {
$tree->{$k} = "$tree"; # return string representation
} else {
remove_code_refs($tree->{$k});
}
}
}
}
}
my $tree = PVE::RESTHandler::api_dump('PVE::API2', undef, 1);
remove_code_refs($tree);
Storable::store_fd($tree, \*STDOUT);
exit(0);