+# format option, display type and description
+# $name: option name
+# $display_name: for example "-$name" of "<$name>", pass undef to use "$name:"
+# $phash: json schema property hash
+# $format: 'asciidoc', 'short', 'long' or 'full'
+# $style: 'config', 'config-sub', 'arg' or 'fixed'
+my $get_property_description = sub {
+ my ($name, $style, $phash, $format, $hidepw, $fileparams) = @_;
+
+ my $res = '';
+
+ $format = 'asciidoc' if !defined($format);
+
+ my $descr = $phash->{description} || "no description available";
+
+ if ($phash->{verbose_description} &&
+ ($style eq 'config' || $style eq 'config-sub')) {
+ $descr = $phash->{verbose_description};
+ }
+
+ chomp $descr;
+
+ my $type = PVE::JSONSchema::schema_get_type_text($phash, $style);
+
+ if ($hidepw && $name eq 'password') {
+ $type = '';
+ }
+
+ if ($fileparams && $type eq 'string') {
+ foreach my $elem (@$fileparams) {
+ if ($name eq $elem) {
+ $type = '<filepath>';
+ last;
+ }
+ }
+ }
+
+ if ($format eq 'asciidoc') {
+
+ if ($style eq 'config') {
+ $res .= "`$name`: ";
+ } elsif ($style eq 'config-sub') {
+ $res .= "`$name`=";
+ } elsif ($style eq 'arg') {
+ $res .= "`-$name` ";
+ } elsif ($style eq 'fixed') {
+ $res .= "`<$name>`: ";
+ } else {
+ die "unknown style '$style'";
+ }
+
+ $res .= "`$type` " if $type;
+
+ if (defined(my $dv = $phash->{default})) {
+ $res .= "('default =' `$dv`)";
+ }
+
+ if ($style eq 'config-sub') {
+ $res .= ";;\n\n";
+ } else {
+ $res .= "::\n\n";
+ }
+
+ my $wdescr = $descr;
+ chomp $wdescr;
+ $wdescr =~ s/^$/+/mg;
+
+ $res .= $wdescr . "\n";
+
+ if (my $req = $phash->{requires}) {
+ my $tmp .= ref($req) ? join(', ', @$req) : $req;
+ $res .= "+\nNOTE: Requires option(s): `$tmp`\n";
+ }
+ $res .= "\n";
+
+ } elsif ($format eq 'short' || $format eq 'long' || $format eq 'full') {
+
+ my $defaulttxt = '';
+ if (defined(my $dv = $phash->{default})) {
+ $defaulttxt = " (default=$dv)";
+ }
+
+ my $display_name;
+ if ($style eq 'config') {
+ $display_name = "$name:";
+ } elsif ($style eq 'arg') {
+ $display_name = "-$name";
+ } elsif ($style eq 'fixed') {
+ $display_name = "<$name>";
+ } else {
+ die "unknown style '$style'";
+ }
+
+ my $tmp = sprintf " %-10s %s$defaulttxt\n", $display_name, "$type";
+ my $indend = " ";
+
+ $res .= Text::Wrap::wrap('', $indend, ($tmp));
+ $res .= "\n",
+ $res .= Text::Wrap::wrap($indend, $indend, ($descr)) . "\n\n";
+
+ if (my $req = $phash->{requires}) {
+ my $tmp = "Requires option(s): ";
+ $tmp .= ref($req) ? join(', ', @$req) : $req;
+ $res .= Text::Wrap::wrap($indend, $indend, ($tmp)). "\n\n";
+ }
+
+ } else {
+ die "unknown format '$format'";
+ }
+
+ return $res;
+};
+