From d5d10f858042bc4ddd86fc998c048d541ba3088d Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 21 Sep 2015 12:11:05 +0200 Subject: [PATCH] JSONSchema: format_description + generate_typetext Helper to generate schema-based typetext properties for comma separated list configuration strings (like -net0 and -ip) using a 'format_description' schema property. --- src/PVE/JSONSchema.pm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index dbe2e35..8725949 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -797,6 +797,11 @@ my $default_schema_noref = { optional => 1, description => "This provides a description of the purpose the instance property. The value can be a string or it can be an object with properties corresponding to various different instance languages (with an optional default property indicating the default description).", }, + format_description => { + type => "string", + optional => 1, + description => "This provides a shorter (usually just one word) description for a property used to generate descriptions for comma separated list property strings.", + }, title => { type => "string", optional => 1, @@ -1227,4 +1232,32 @@ sub dump_config { return $data; } +sub generate_typetext { + my ($schema) = @_; + my $typetext = ''; + my (@optional, @required); + foreach my $key (sort keys %$schema) { + next if !$schema->{$key}->{format_description}; + if ($schema->{$key}->{optional}) { + push @optional, $key; + } else { + push @required, $key; + } + } + my ($pre, $post) = ('', ''); + foreach my $key (@required) { + my $desc = $schema->{$key}->{format_description}; + $typetext .= "$pre$key=<$desc>$post"; + $pre = ', '; + } + $pre = ' [,' if $pre; + foreach my $key (@optional) { + my $desc = $schema->{$key}->{format_description}; + $typetext .= "$pre$key=<$desc>$post"; + $pre = ' [,'; + $post = ']'; + } + return $typetext; +} + 1; -- 2.39.2