[pve-devel] applied: [PATCH common v2 2/9] cli: factor out initialisation check

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Dec 29 12:32:45 CET 2017


applied

On Mon, Dec 18, 2017 at 10:21:36AM +0100, Thomas Lamprecht wrote:
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> Reviewed-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  src/PVE/CLIHandler.pm | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/src/PVE/CLIHandler.pm b/src/PVE/CLIHandler.pm
> index c6f11f6..f50611d 100644
> --- a/src/PVE/CLIHandler.pm
> +++ b/src/PVE/CLIHandler.pm
> @@ -14,6 +14,12 @@ my $cmddef;
>  my $exename;
>  my $cli_handler_class;
>  
> +my $assert_initialized = sub {
> +    my @caller = caller;
> +    die "$caller[0]:$caller[2] - not initialized\n"
> +	if !($cmddef && $exename && $cli_handler_class);
> +};
> +
>  my $expand_command_name = sub {
>      my ($def, $cmd) = @_;
>  
> @@ -73,7 +79,7 @@ __PACKAGE__->register_method ({
>      code => sub {
>  	my ($param) = @_;
>  
> -	die "not initialized" if !($cmddef && $exename && $cli_handler_class);
> +	$assert_initialized->();
>  
>  	my $cmd = $param->{cmd};
>  
> @@ -114,7 +120,7 @@ __PACKAGE__->register_method ({
>  sub print_simple_asciidoc_synopsis {
>      my ($class, $name, $arg_param, $uri_param) = @_;
>  
> -    die "not initialized" if !$cli_handler_class;
> +    $assert_initialized->();
>  
>      my $pwcallback = $cli_handler_class->can('read_password');
>      my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
> @@ -129,7 +135,7 @@ sub print_simple_asciidoc_synopsis {
>  
>  sub print_asciidoc_synopsis {
>  
> -    die "not initialized" if !($cmddef && $exename && $cli_handler_class);
> +    $assert_initialized->();
>  
>      my $pwcallback = $cli_handler_class->can('read_password');
>      my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
> @@ -157,7 +163,7 @@ sub print_asciidoc_synopsis {
>  
>  sub print_usage_verbose {
>  
> -    die "not initialized" if !($cmddef && $exename && $cli_handler_class);
> +    $assert_initialized->();
>  
>      my $pwcallback = $cli_handler_class->can('read_password');
>      my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
> @@ -179,7 +185,7 @@ sub sorted_commands {
>  sub print_usage_short {
>      my ($fd, $msg) = @_;
>  
> -    die "not initialized" if !($cmddef && $exename && $cli_handler_class);
> +    $assert_initialized->();
>  
>      my $pwcallback = $cli_handler_class->can('read_password');
>      my $stringfilemap = $cli_handler_class->can('string_param_file_mapping');
> -- 
> 2.11.0




More information about the pve-devel mailing list