mode sql-string - option --printf-value can use new format variable name (#4631)

Co-authored-by: Lucie Dubrunfaut <123162035+lucie-dubrunfaut@users.noreply.github.com>
This commit is contained in:
qgarnier 2023-09-05 15:09:50 +02:00 committed by GitHub
parent 6f48d96cd3
commit 7402f466cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -53,7 +53,7 @@ sub custom_string_output {
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
$msg = sprintf("$self->{instance_mode}->{option_results}->{printf_format}", eval $self->{instance_mode}->{option_results}->{printf_value});
$msg = sprintf("$self->{instance_mode}->{option_results}->{printf_format}", $self->{result_values}->{ $self->{instance_mode}->{printf_value} });
};
} else {
$msg = sprintf("'%s'", $self->{result_values}->{value_field});
@ -62,6 +62,7 @@ sub custom_string_output {
if (defined($message)) {
$self->{output}->output_add(long_msg => 'output value issue: ' . $message);
}
return $msg;
}
@ -91,6 +92,16 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Need to specify '--sql-statement' option.");
$self->{output}->option_exit();
}
$self->{printf_value} = 'value_field';
if (defined($self->{option_results}->{printf_value}) && $self->{option_results}->{printf_value} ne '') {
$self->{printf_value} = $1
if ($self->{option_results}->{printf_value} =~ /\$self->{result_values}->{(value_field|key_field)}/);
$self->{printf_value} = $1
if ($self->{option_results}->{printf_value} =~ /\%{(value_field|key_field)}/);
$self->{printf_value} = $1
if ($self->{option_results}->{printf_value} =~ /\%\((value_field|key_field)\)/);
}
}
sub manage_selection {
@ -155,12 +166,12 @@ Value column (must be one of the selected field). MANDATORY
=item B<--printf-format>
Specify a custom output message relying on printf formatting
Specify a custom output message relying on printf formatting. If this option is set --printf-value is mandatory.
=item B<--printf-value>
Specify scalar used to replace in printf
(Can be: $self->{result_values}->{key_field}, $self->{result_values}->{value_field})
Specify scalar used to replace in printf. If this option is set --printf-format is mandatory.
(Can be: %{key_field}, %{value_field})
=item B<--warning-string>