[pve-devel] [pve-common v2] PVE::CLIFormatter - new 'yaml' renderer
Dietmar Maurer
dietmar at proxmox.com
Thu Jul 26 12:04:56 CEST 2018
Generates nice and readable output for list of string and simple objects.
Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
changes in v2: use CPAN::Meta::YAML
src/PVE/CLIFormatter.pm | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm
index 8bb42ca..f9eb03f 100644
--- a/src/PVE/CLIFormatter.pm
+++ b/src/PVE/CLIFormatter.pm
@@ -4,6 +4,7 @@ use strict;
use warnings;
use I18N::Langinfo;
use POSIX qw(strftime);
+use CPAN::Meta::YAML; # comes with perl-modules
use PVE::JSONSchema;
use PVE::PTY;
@@ -81,6 +82,17 @@ sub 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) = @_;
--
2.11.0
More information about the pve-devel
mailing list