]> git.proxmox.com Git - pve-common.git/commitdiff
CLIHandler: add standard_mappings
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 15 Jun 2018 13:28:43 +0000 (15:28 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 19 Jun 2018 09:56:00 +0000 (11:56 +0200)
so we can reuse often used parameter mappings

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PVE/CLIHandler.pm

index 6871c1fc71f4a08431ec612001f590db825ff296..810467d46eb28db8ac2a997901a0a22cb1b787ea 100644 (file)
@@ -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