]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/PodParser.pm
half-revert: remove autostart property from bridge ports
[pve-common.git] / src / PVE / PodParser.pm
index 7e31e1957e71c42a542c9ae1eb7ab76eb91b7af1..f61317bca69666990f8a2248edb7d75d8df0d3e3 100644 (file)
@@ -44,6 +44,51 @@ sub command {
 
 # helpers used to generate our manual pages
 
+sub generate_typetext {
+    my ($schema) = @_;
+    my $typetext = '';
+    my (@optional, @required);
+    foreach my $key (sort keys %$schema) {
+       next if !$schema->{$key}->{format_description} &&
+               !$schema->{$key}->{typetext};
+       if ($schema->{$key}->{optional}) {
+           push @optional, $key;
+       } else {
+           push @required, $key;
+       }
+    }
+    my ($pre, $post) = ('', '');
+    my $add = sub {
+       my ($key) = @_;
+       $typetext .= $pre;
+       my $entry = $schema->{$key};
+       if (my $alias = $entry->{alias}) {
+           $key = $alias;
+           $entry = $schema->{$key};
+       }
+       if (my $desc = $entry->{format_description}) {
+           $typetext .= $entry->{default_key} ? "[$key=]" : "$key=";
+           $typetext .= "<$desc>";
+       } elsif (my $text = $entry->{typetext}) {
+           $typetext .= $text;
+       } else {
+           die "internal error: neither format_description nor typetext found";
+       }
+       $typetext .= $post;
+    };
+    foreach my $key (@required) {
+       &$add($key);
+       $pre = ', ';
+    }
+    $pre = $pre ? ' [,' : '[';
+    $post = ']';
+    foreach my $key (@optional) {
+       &$add($key);
+       $pre = ' [,';
+    }
+    return $typetext;
+}
+
 sub schema_get_type_text {
     my ($phash) = @_;
 
@@ -61,6 +106,13 @@ sub schema_get_type_text {
        } elsif (defined($phash->{maximum})) {
            return "$phash->{type} (-N - $phash->{maximum})";
        }
+    } elsif ($phash->{type} eq 'string') {
+       if (my $format = $phash->{format}) {
+           $format = PVE::JSONSchema::get_format($format) if ref($format) ne 'HASH';
+           if (ref($format) eq 'HASH') {
+               return generate_typetext($format);
+           }
+       }
     }
 
     my $type = $phash->{type} || 'string';