]> git.proxmox.com Git - pve-common.git/commitdiff
PVE::CLIFormatter - new 'yaml' renderer
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 26 Jul 2018 07:50:25 +0000 (09:50 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 26 Jul 2018 09:57:15 +0000 (11:57 +0200)
Generates nice and readable output for list of string and simple objects.

src/PVE/CLIFormatter.pm

index 8bb42ca15e044fa1e899a0398c15ea3fe74d1164..f9eb03fe4f3f3b7b94aa286df22c5d1b81cf9ae3 100644 (file)
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 use I18N::Langinfo;
 use POSIX qw(strftime);
 use warnings;
 use I18N::Langinfo;
 use POSIX qw(strftime);
+use CPAN::Meta::YAML; # comes with perl-modules
 
 use PVE::JSONSchema;
 use PVE::PTY;
 
 use PVE::JSONSchema;
 use PVE::PTY;
@@ -81,6 +82,17 @@ sub render_bytes {
 
 PVE::JSONSchema::register_renderer('bytes', \&render_bytes);
 
 
 PVE::JSONSchema::register_renderer('bytes', \&render_bytes);
 
+sub render_yaml {
+    my ($value) = @_;
+
+    my $data = CPAN::Meta::YAML::Dump($value);
+    $data =~ s/^---[\n\s]//; # remove yaml marker
+
+    return $data;
+}
+
+PVE::JSONSchema::register_renderer('yaml', \&render_yaml);
+
 sub query_terminal_options {
     my ($options) = @_;
 
 sub query_terminal_options {
     my ($options) = @_;