+my $standard_mappings = {
+ 'pve-password' => {
+ name => 'password',
+ desc => '<password>',
+ interactive => 1,
+ func => sub {
+ my ($value) = @_;
+ return $value if $value;
+ return PVE::PTY::get_confirmed_password();
+ },
+ },
+};
+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;
+}
+
+my $gen_param_mapping_func = sub {
+ my ($cli_handler_class) = @_;
+
+ my $param_mapping = $cli_handler_class->can('param_mapping');
+
+ if (!$param_mapping) {
+ my $read_password = $cli_handler_class->can('read_password');
+ my $string_param_mapping = $cli_handler_class->can('string_param_file_mapping');
+
+ return $string_param_mapping if !$read_password;
+
+ $param_mapping = sub {
+ my ($name) = @_;
+
+ my $password_map = get_standard_mapping('pve-password', {
+ func => $read_password
+ });
+ my $map = $string_param_mapping ? $string_param_mapping->($name) : [];
+ return [@$map, $password_map];
+ };
+ }
+
+ return $param_mapping;
+};
+