[pve-devel] [pve-common 03/11] PVE::JSONSchema::register_renderer - allow to register renderers by name

Dietmar Maurer dietmar at proxmox.com
Fri Jun 29 13:15:18 CEST 2018


We want to use those renderer to format CLI output nicely.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 src/PVE/JSONSchema.pm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 41a6652..f0ac441 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -121,6 +121,22 @@ sub get_format {
     return $format_list->{$format};
 }
 
+my $renderer_hash = {};
+
+sub register_renderer {
+    my ($name, $code) = @_;
+
+    die "renderer '$name' already registered\n"
+	if $renderer_hash->{$name};
+
+    $renderer_hash->{$name} = $code;
+}
+
+sub get_renderer {
+    my ($name) = @_;
+    return $renderer_hash->{$name};
+}
+
 # register some common type for pve
 
 register_format('string', sub {}); # allow format => 'string-list'
-- 
2.11.0




More information about the pve-devel mailing list