mirror of
git://git.proxmox.com/git/pve-common.git
synced 2024-12-24 01:33:48 +03:00
rename $stringfilemap to $param_mapping_func
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
dfc6cff8e3
commit
b01af86160
@ -457,7 +457,7 @@ sub setup_environment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $handle_cmd = sub {
|
my $handle_cmd = sub {
|
||||||
my ($args, $pwcallback, $preparefunc, $stringfilemap) = @_;
|
my ($args, $pwcallback, $preparefunc, $param_mapping_func) = @_;
|
||||||
|
|
||||||
$cmddef->{help} = [ __PACKAGE__, 'help', ['extra-args'] ];
|
$cmddef->{help} = [ __PACKAGE__, 'help', ['extra-args'] ];
|
||||||
|
|
||||||
@ -489,13 +489,13 @@ my $handle_cmd = sub {
|
|||||||
$abort->("unknown command '$cmd_str'") if !$class;
|
$abort->("unknown command '$cmd_str'") if !$class;
|
||||||
|
|
||||||
my $prefix = "$exename $cmd_str";
|
my $prefix = "$exename $cmd_str";
|
||||||
my $res = $class->cli_handler($prefix, $name, $cmd_args, $arg_param, $uri_param, $pwcallback, $stringfilemap);
|
my $res = $class->cli_handler($prefix, $name, $cmd_args, $arg_param, $uri_param, $pwcallback, $param_mapping_func);
|
||||||
|
|
||||||
&$outsub($res) if $outsub;
|
&$outsub($res) if $outsub;
|
||||||
};
|
};
|
||||||
|
|
||||||
my $handle_simple_cmd = sub {
|
my $handle_simple_cmd = sub {
|
||||||
my ($args, $pwcallback, $preparefunc, $stringfilemap) = @_;
|
my ($args, $pwcallback, $preparefunc, $param_mapping_func) = @_;
|
||||||
|
|
||||||
my ($class, $name, $arg_param, $uri_param, $outsub) = @{$cmddef};
|
my ($class, $name, $arg_param, $uri_param, $outsub) = @{$cmddef};
|
||||||
die "no class specified" if !$class;
|
die "no class specified" if !$class;
|
||||||
@ -524,7 +524,7 @@ my $handle_simple_cmd = sub {
|
|||||||
|
|
||||||
&$preparefunc() if $preparefunc;
|
&$preparefunc() if $preparefunc;
|
||||||
|
|
||||||
my $res = $class->cli_handler($name, $name, \@ARGV, $arg_param, $uri_param, $pwcallback, $stringfilemap);
|
my $res = $class->cli_handler($name, $name, \@ARGV, $arg_param, $uri_param, $pwcallback, $param_mapping_func);
|
||||||
|
|
||||||
&$outsub($res) if $outsub;
|
&$outsub($res) if $outsub;
|
||||||
};
|
};
|
||||||
@ -546,7 +546,7 @@ sub run_cli_handler {
|
|||||||
my $preparefunc = $params{prepare};
|
my $preparefunc = $params{prepare};
|
||||||
|
|
||||||
my $pwcallback = $class->can('read_password');
|
my $pwcallback = $class->can('read_password');
|
||||||
my $stringfilemap = $class->can('string_param_file_mapping');
|
my $param_mapping_func = $class->can('string_param_file_mapping');
|
||||||
|
|
||||||
$exename = &$get_exe_name($class);
|
$exename = &$get_exe_name($class);
|
||||||
|
|
||||||
@ -556,9 +556,9 @@ sub run_cli_handler {
|
|||||||
$cmddef = ${"${class}::cmddef"};
|
$cmddef = ${"${class}::cmddef"};
|
||||||
|
|
||||||
if (ref($cmddef) eq 'ARRAY') {
|
if (ref($cmddef) eq 'ARRAY') {
|
||||||
&$handle_simple_cmd(\@ARGV, $pwcallback, $preparefunc, $stringfilemap);
|
&$handle_simple_cmd(\@ARGV, $pwcallback, $preparefunc, $param_mapping_func);
|
||||||
} else {
|
} else {
|
||||||
&$handle_cmd(\@ARGV, $pwcallback, $preparefunc, $stringfilemap);
|
&$handle_cmd(\@ARGV, $pwcallback, $preparefunc, $param_mapping_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
|
@ -541,9 +541,9 @@ my $compute_param_mapping_hash = sub {
|
|||||||
# 'full' ... text, include description
|
# 'full' ... text, include description
|
||||||
# 'asciidoc' ... generate asciidoc for man pages (like 'full')
|
# 'asciidoc' ... generate asciidoc for man pages (like 'full')
|
||||||
# $hidepw ... hide password option (use this if you provide a read passwork callback)
|
# $hidepw ... hide password option (use this if you provide a read passwork callback)
|
||||||
# $stringfilemap ... mapping for string parameters to file path parameters
|
# $param_mapping_func ... mapping for string parameters to file path parameters
|
||||||
sub usage_str {
|
sub usage_str {
|
||||||
my ($self, $name, $prefix, $arg_param, $fixed_param, $format, $hidepw, $stringfilemap) = @_;
|
my ($self, $name, $prefix, $arg_param, $fixed_param, $format, $hidepw, $param_mapping_func) = @_;
|
||||||
|
|
||||||
$format = 'long' if !$format;
|
$format = 'long' if !$format;
|
||||||
|
|
||||||
@ -600,8 +600,8 @@ sub usage_str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $param_mapping_hash = $compute_param_mapping_hash->(&$stringfilemap($name))
|
my $param_mapping_hash = $compute_param_mapping_hash->(&$param_mapping_func($name))
|
||||||
if $stringfilemap;
|
if $param_mapping_func;
|
||||||
|
|
||||||
$opts .= &$get_property_description($base, 'arg', $prop->{$k}, $format,
|
$opts .= &$get_property_description($base, 'arg', $prop->{$k}, $format,
|
||||||
$hidepw, $param_mapping_hash->{$k});
|
$hidepw, $param_mapping_hash->{$k});
|
||||||
@ -699,7 +699,7 @@ my $replace_file_names_with_contents = sub {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sub cli_handler {
|
sub cli_handler {
|
||||||
my ($self, $prefix, $name, $args, $arg_param, $fixed_param, $pwcallback, $stringfilemap) = @_;
|
my ($self, $prefix, $name, $args, $arg_param, $fixed_param, $pwcallback, $param_mapping_func) = @_;
|
||||||
|
|
||||||
my $info = $self->map_method_by_name($name);
|
my $info = $self->map_method_by_name($name);
|
||||||
|
|
||||||
@ -707,8 +707,8 @@ sub cli_handler {
|
|||||||
eval {
|
eval {
|
||||||
my $param = PVE::JSONSchema::get_options($info->{parameters}, $args, $arg_param, $fixed_param, $pwcallback);
|
my $param = PVE::JSONSchema::get_options($info->{parameters}, $args, $arg_param, $fixed_param, $pwcallback);
|
||||||
|
|
||||||
if (defined($stringfilemap)) {
|
if (defined($param_mapping_func)) {
|
||||||
my $param_mapping_hash = $compute_param_mapping_hash->(&$stringfilemap($name));
|
my $param_mapping_hash = $compute_param_mapping_hash->(&$param_mapping_func($name));
|
||||||
&$replace_file_names_with_contents($param, $param_mapping_hash);
|
&$replace_file_names_with_contents($param, $param_mapping_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -719,7 +719,7 @@ sub cli_handler {
|
|||||||
|
|
||||||
die $err if !$ec || $ec ne "PVE::Exception" || !$err->is_param_exc();
|
die $err if !$ec || $ec ne "PVE::Exception" || !$err->is_param_exc();
|
||||||
|
|
||||||
$err->{usage} = $self->usage_str($name, $prefix, $arg_param, $fixed_param, 'short', $pwcallback, $stringfilemap);
|
$err->{usage} = $self->usage_str($name, $prefix, $arg_param, $fixed_param, 'short', $pwcallback, $param_mapping_func);
|
||||||
|
|
||||||
die $err;
|
die $err;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user