mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-26 05:03:28 +00:00
Replace 'string' with 'filepath' for mapped params
For the CLI man pages and documentation, mapped parameters ('content' strings in API2 which are loaded from file paths in CLI) get special treatment and are displayed with the type 'filepath'.
This commit is contained in:
parent
408976c6f7
commit
4845032a46
@ -98,9 +98,11 @@ __PACKAGE__->register_method ({
|
|||||||
raise_param_exc({ cmd => "no such command '$cmd'"}) if !$class;
|
raise_param_exc({ cmd => "no such command '$cmd'"}) if !$class;
|
||||||
|
|
||||||
my $pwcallback = $cli_handler_class->can('read_password');
|
my $pwcallback = $cli_handler_class->can('read_password');
|
||||||
|
my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
|
||||||
|
|
||||||
my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param,
|
my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param,
|
||||||
$verbose ? 'full' : 'short', $pwcallback);
|
$verbose ? 'full' : 'short', $pwcallback,
|
||||||
|
$stringfilemap);
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
print "$str\n";
|
print "$str\n";
|
||||||
} else {
|
} else {
|
||||||
@ -117,10 +119,12 @@ sub print_simple_asciidoc_synopsys {
|
|||||||
die "not initialized" if !$cli_handler_class;
|
die "not initialized" if !$cli_handler_class;
|
||||||
|
|
||||||
my $pwcallback = $cli_handler_class->can('read_password');
|
my $pwcallback = $cli_handler_class->can('read_password');
|
||||||
|
my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
|
||||||
|
|
||||||
my $synopsis = "*${name}* `help`\n\n";
|
my $synopsis = "*${name}* `help`\n\n";
|
||||||
|
|
||||||
$synopsis .= $class->usage_str($name, $name, $arg_param, $uri_param, 'asciidoc', $pwcallback);
|
$synopsis .= $class->usage_str($name, $name, $arg_param, $uri_param,
|
||||||
|
'asciidoc', $pwcallback, $stringfilemap);
|
||||||
|
|
||||||
return $synopsis;
|
return $synopsis;
|
||||||
}
|
}
|
||||||
@ -130,6 +134,7 @@ sub print_asciidoc_synopsys {
|
|||||||
die "not initialized" if !($cmddef && $exename && $cli_handler_class);
|
die "not initialized" if !($cmddef && $exename && $cli_handler_class);
|
||||||
|
|
||||||
my $pwcallback = $cli_handler_class->can('read_password');
|
my $pwcallback = $cli_handler_class->can('read_password');
|
||||||
|
my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
|
||||||
|
|
||||||
my $synopsis = "";
|
my $synopsis = "";
|
||||||
|
|
||||||
@ -139,7 +144,8 @@ sub print_asciidoc_synopsys {
|
|||||||
foreach my $cmd (sort keys %$cmddef) {
|
foreach my $cmd (sort keys %$cmddef) {
|
||||||
my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
|
my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
|
||||||
my $str = $class->usage_str($name, "$exename $cmd", $arg_param,
|
my $str = $class->usage_str($name, "$exename $cmd", $arg_param,
|
||||||
$uri_param, 'asciidoc', $pwcallback);
|
$uri_param, 'asciidoc', $pwcallback,
|
||||||
|
$stringfilemap);
|
||||||
$synopsis .= "\n" if $oldclass && $oldclass ne $class;
|
$synopsis .= "\n" if $oldclass && $oldclass ne $class;
|
||||||
|
|
||||||
$synopsis .= "$str\n\n";
|
$synopsis .= "$str\n\n";
|
||||||
@ -157,9 +163,10 @@ sub print_simple_pod_manpage {
|
|||||||
die "not initialized" if !$cli_handler_class;
|
die "not initialized" if !$cli_handler_class;
|
||||||
|
|
||||||
my $pwcallback = $cli_handler_class->can('read_password');
|
my $pwcallback = $cli_handler_class->can('read_password');
|
||||||
|
my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
|
||||||
|
|
||||||
my $synopsis = " $name help\n\n";
|
my $synopsis = " $name help\n\n";
|
||||||
my $str = $class->usage_str($name, $name, $arg_param, $uri_param, 'long', $pwcallback);
|
my $str = $class->usage_str($name, $name, $arg_param, $uri_param, 'long', $pwcallback, $stringfilemap);
|
||||||
$str =~ s/^USAGE://;
|
$str =~ s/^USAGE://;
|
||||||
$str =~ s/\n/\n /g;
|
$str =~ s/\n/\n /g;
|
||||||
$synopsis .= $str;
|
$synopsis .= $str;
|
||||||
@ -176,6 +183,7 @@ sub print_pod_manpage {
|
|||||||
die "no pod file specified" if !$podfn;
|
die "no pod file specified" if !$podfn;
|
||||||
|
|
||||||
my $pwcallback = $cli_handler_class->can('read_password');
|
my $pwcallback = $cli_handler_class->can('read_password');
|
||||||
|
my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
|
||||||
|
|
||||||
my $synopsis = "";
|
my $synopsis = "";
|
||||||
|
|
||||||
@ -186,7 +194,8 @@ sub print_pod_manpage {
|
|||||||
foreach my $cmd (sorted_commands()) {
|
foreach my $cmd (sorted_commands()) {
|
||||||
my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
|
my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
|
||||||
my $str = $class->usage_str($name, "$exename $cmd", $arg_param,
|
my $str = $class->usage_str($name, "$exename $cmd", $arg_param,
|
||||||
$uri_param, $style, $pwcallback);
|
$uri_param, $style, $pwcallback,
|
||||||
|
$stringfilemap);
|
||||||
$str =~ s/^USAGE: //;
|
$str =~ s/^USAGE: //;
|
||||||
|
|
||||||
$synopsis .= "\n" if $oldclass && $oldclass ne $class;
|
$synopsis .= "\n" if $oldclass && $oldclass ne $class;
|
||||||
@ -207,13 +216,14 @@ sub print_usage_verbose {
|
|||||||
die "not initialized" if !($cmddef && $exename && $cli_handler_class);
|
die "not initialized" if !($cmddef && $exename && $cli_handler_class);
|
||||||
|
|
||||||
my $pwcallback = $cli_handler_class->can('read_password');
|
my $pwcallback = $cli_handler_class->can('read_password');
|
||||||
|
my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
|
||||||
|
|
||||||
print "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n\n";
|
print "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n\n";
|
||||||
|
|
||||||
foreach my $cmd (sort keys %$cmddef) {
|
foreach my $cmd (sort keys %$cmddef) {
|
||||||
my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
|
my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
|
||||||
my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param,
|
my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param,
|
||||||
'full', $pwcallback);
|
'full', $pwcallback, $stringfilemap);
|
||||||
print "$str\n\n";
|
print "$str\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,6 +238,7 @@ sub print_usage_short {
|
|||||||
die "not initialized" if !($cmddef && $exename && $cli_handler_class);
|
die "not initialized" if !($cmddef && $exename && $cli_handler_class);
|
||||||
|
|
||||||
my $pwcallback = $cli_handler_class->can('read_password');
|
my $pwcallback = $cli_handler_class->can('read_password');
|
||||||
|
my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
|
||||||
|
|
||||||
print $fd "ERROR: $msg\n" if $msg;
|
print $fd "ERROR: $msg\n" if $msg;
|
||||||
print $fd "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n";
|
print $fd "USAGE: $exename <COMMAND> [ARGS] [OPTIONS]\n";
|
||||||
@ -235,7 +246,7 @@ sub print_usage_short {
|
|||||||
my $oldclass;
|
my $oldclass;
|
||||||
foreach my $cmd (sorted_commands()) {
|
foreach my $cmd (sorted_commands()) {
|
||||||
my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
|
my ($class, $name, $arg_param, $uri_param) = @{$cmddef->{$cmd}};
|
||||||
my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'short', $pwcallback);
|
my $str = $class->usage_str($name, "$exename $cmd", $arg_param, $uri_param, 'short', $pwcallback, $stringfilemap);
|
||||||
print $fd "\n" if $oldclass && $oldclass ne $class;
|
print $fd "\n" if $oldclass && $oldclass ne $class;
|
||||||
print $fd " $str";
|
print $fd " $str";
|
||||||
$oldclass = $class;
|
$oldclass = $class;
|
||||||
@ -500,7 +511,7 @@ my $handle_simple_cmd = sub {
|
|||||||
if (scalar(@$args) >= 1) {
|
if (scalar(@$args) >= 1) {
|
||||||
if ($args->[0] eq 'help') {
|
if ($args->[0] eq 'help') {
|
||||||
my $str = "USAGE: $name help\n";
|
my $str = "USAGE: $name help\n";
|
||||||
$str .= $class->usage_str($name, $name, $arg_param, $uri_param, 'long', $pwcallback);
|
$str .= $class->usage_str($name, $name, $arg_param, $uri_param, 'long', $pwcallback, $stringfilemap);
|
||||||
print STDERR "$str\n\n";
|
print STDERR "$str\n\n";
|
||||||
return;
|
return;
|
||||||
} elsif ($args->[0] eq 'bashcomplete') {
|
} elsif ($args->[0] eq 'bashcomplete') {
|
||||||
|
@ -410,7 +410,7 @@ sub handle {
|
|||||||
# $format: 'asciidoc', 'pod' or 'text'
|
# $format: 'asciidoc', 'pod' or 'text'
|
||||||
# $style: 'config', 'arg' or 'fixed'
|
# $style: 'config', 'arg' or 'fixed'
|
||||||
my $get_property_description = sub {
|
my $get_property_description = sub {
|
||||||
my ($name, $style, $phash, $format, $hidepw) = @_;
|
my ($name, $style, $phash, $format, $hidepw, $fileparams) = @_;
|
||||||
|
|
||||||
my $res = '';
|
my $res = '';
|
||||||
|
|
||||||
@ -426,6 +426,15 @@ my $get_property_description = sub {
|
|||||||
$type = '';
|
$type = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($fileparams && $type eq 'string') {
|
||||||
|
foreach my $elem (@$fileparams) {
|
||||||
|
if ($name eq $elem) {
|
||||||
|
$type = 'filepath';
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($format eq 'asciidoc') {
|
if ($format eq 'asciidoc') {
|
||||||
|
|
||||||
if ($style eq 'config') {
|
if ($style eq 'config') {
|
||||||
@ -508,8 +517,9 @@ my $get_property_description = sub {
|
|||||||
# 'full' ... also include description
|
# 'full' ... also 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
|
||||||
sub usage_str {
|
sub usage_str {
|
||||||
my ($self, $name, $prefix, $arg_param, $fixed_param, $format, $hidepw) = @_;
|
my ($self, $name, $prefix, $arg_param, $fixed_param, $format, $hidepw, $stringfilemap) = @_;
|
||||||
|
|
||||||
$format = 'long' if !$format;
|
$format = 'long' if !$format;
|
||||||
|
|
||||||
@ -564,7 +574,8 @@ sub usage_str {
|
|||||||
$base = "${name}[n]";
|
$base = "${name}[n]";
|
||||||
}
|
}
|
||||||
|
|
||||||
$opts .= &$get_property_description($base, 'arg', $prop->{$k}, 'text', $hidepw);
|
$opts .= &$get_property_description($base, 'arg', $prop->{$k}, 'text',
|
||||||
|
$hidepw, &$stringfilemap($name));
|
||||||
|
|
||||||
if (!$prop->{$k}->{optional}) {
|
if (!$prop->{$k}->{optional}) {
|
||||||
$args .= " " if $args;
|
$args .= " " if $args;
|
||||||
@ -661,7 +672,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);
|
$err->{usage} = $self->usage_str($name, $prefix, $arg_param, $fixed_param, 'short', $pwcallback, $stringfilemap);
|
||||||
|
|
||||||
die $err;
|
die $err;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user