From: Dominik Csapak Date: Fri, 15 Jun 2018 13:28:43 +0000 (+0200) Subject: CLIHandler: add standard_mappings X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=57d5edee2fe1d27c6ae9fa5ddef6f6a17dd87861;hp=a1c7eddaf198b1fb23255f0199c0624476a35606;ds=sidebyside CLIHandler: add standard_mappings so we can reuse often used parameter mappings Signed-off-by: Dominik Csapak --- diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm index 6871c1f..810467d 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