[pve-devel] [PATCH common 3/4] CLIHandler: add standard_mappings

Dominik Csapak d.csapak at proxmox.com
Fri Jun 15 15:28:43 CEST 2018


so we can reuse often used parameter mappings

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/CLIHandler.pm | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
index c0b9406..b677105 100644
--- a/src/PVE/CLIHandler.pm
+++ b/src/PVE/CLIHandler.pm
@@ -69,6 +69,24 @@ my $get_commands = sub {
 
 my $complete_command_names = sub { $get_commands->($cmddef) };
 
+my $standard_mappings = { };
+
+sub get_standard_mapping {
+    my ($name, $base) = @_;
+
+    my $std =  $standard_mappings->{$name};
+    die "no such standard mapping '$name'\n" if !$std;
+
+    my $res = $base || {};
+
+    foreach my $opt (keys %$std) {
+	next if defined($res->{$opt});
+	$res->{$opt} = $std->{$opt};
+    }
+
+    return $res;
+}
+
 # traverses the command definition using the $argv array, resolving one level
 # of aliases.
 # Returns the matching (sub) command and its definition, and argument array for
-- 
2.11.0





More information about the pve-devel mailing list