From c4faefbb0946a80bc5bec94a2e0d037d2b8a06ba Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 29 Dec 2021 17:52:36 +0100 Subject: [PATCH] =?UTF-8?q?TT#156156=20Switch=20to=20=C2=AB-=C2=BB=20as=20?= =?UTF-8?q?the=20word=20separator=20in=20CLI=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The prevalent convention in the project is to use «-» instead of «_» to split words in options. Switch the options to that, and keep backwards compatibility option alias that emits a deprecation warning while people transition to the new names. The alias will be removed on the next LTS. Change-Id: I003e79a5358aec905bd652c5310217be24fd98c6 --- share/tools/generate_invoices.pl | 92 +++++++++++++++++++++------- tools_bin/ngcp-provisioning-template | 49 +++++++++++---- 2 files changed, 107 insertions(+), 34 deletions(-) diff --git a/share/tools/generate_invoices.pl b/share/tools/generate_invoices.pl index 9a30725f95..038275db02 100755 --- a/share/tools/generate_invoices.pl +++ b/share/tools/generate_invoices.pl @@ -20,10 +20,43 @@ use feature 'state'; my $opt = {}; my $opt_cfg = {}; my $cfg_raw = {}; + +# XXX: Remove after mr10.5. +sub old_scalar_option { + my ($name, $value) = @_; + my $newname = $name =~ tr/_/-/r; + $opt->{$name} = $value; + warn "$0: option --$name is deprecated; use --$newname instead\n"; +} + +# XXX: Remove after mr10.5. +sub old_array_option { + my ($name, $value) = @_; + my $newname = $name =~ tr/_/-/r; + push @{$opt->{$name}}, $value; + warn "$0: option --$name is deprecated; use --$newname instead\n"; +} + + +sub parse_scalar_option { + my ($name, $value) = @_; + $name =~ tr/-/_/; + $opt->{$name} = $value; +} + +sub parse_array_option { + my ($name, $value) = @_; + $name =~ tr/-/_/; + push @{$opt->{$name}}, $value; +} + my @opt_spec = ( - 'reseller_id=i@', - 'client_contact_id=i@', - 'client_contract_id=i@', + 'reseller_id=i@' => \&old_array_option, + 'reseller-id=i@' => \&parse_array_option, + 'client_contact_id=i@' => \&old_array_option, + 'client-contact-id=i@' => \&parse_array_option, + 'client_contract_id=i@' => \&old_array_option, + 'client-contract-id=i@' => \&parse_array_option, 'stime=s', 'etime=s', 'prevmonth', @@ -31,12 +64,18 @@ my @opt_spec = ( 'send', 'resend', 'regenerate', - 'allow_terminated', - 'backward_is_active', - 'update_contract_balance', - 'update_contract_balance_nonzero', - 'force_unrated', - 'no_empty', + 'allow_terminated' => \&old_scalar_option, + 'allow-terminated' => \&parse_scalar_option, + 'backward_is_active' => \&old_scalar_option, + 'backward-is-active' => \&parse_scalar_option, + 'update_contract_balance' => \&old_scalar_option, + 'update-contract-balance' => \&parse_scalar_option, + 'update_contract_balance_nonzero' => \&old_scalar_option, + 'update-contract-balance-nonzero' => \&parse_scalar_option, + 'force_unrated' => \&old_scalar_option, + 'force-unrated' => \&parse_scalar_option, + 'no_empty' => \&old_scalar_option, + 'no-empty' => \&parse_scalar_option, 'enable', 'help|?', 'man' @@ -47,7 +86,15 @@ my @opt_spec = ( if(-e $config_file){ my $cfg2opt = sub{ my($key, $val) = @_; - state $opt_spec = { map{my $k = $_; $k=~s/[^[:alnum:]_].*?$//; $k => $_;} @opt_spec }; + state $opt_spec = { + map { + my $k = $_; + $k =~ s/[^[:alnum:]-].*?$//; + $k => $_; + } grep { + ref eq '' + } @opt_spec + }; if(!$opt_spec->{$key}){ return ''; } @@ -93,6 +140,7 @@ my @opt_spec = ( my ($var, $value) = split(/\s*=\s*/, $_, 2); #$opt->{lc $var} = $value; my $opt_key = lc $var; + $opt_key =~ s/_/-/g; $cfg_raw->{$opt_key} = $value; $opt_str .= $cfg2opt->($opt_key,$value); #$opt->{lc $var} = $value; @@ -355,7 +403,7 @@ sub check_unrated_calls{ $stime->epoch,$etime->epoch ); if(@$unrated_calls_info){ - my $msg = "\n\n\n\n".'There are '.@$unrated_calls_info.' customers which have unrated calls in the '.$stime->ymd.' - '.$etime->ymd.' period. Run '.__FILE__.' script with option --force_unrated to generate invoices anyway.'."\n\n\n\n"; + my $msg = "\n\n\n\n".'There are '.@$unrated_calls_info.' customers which have unrated calls in the '.$stime->ymd.' - '.$etime->ymd.' period. Run '.__FILE__.' script with option --force-unrated to generate invoices anyway.'."\n\n\n\n"; my $info = join("\n",map {"Customer: ".sprintf("%5d",$_->{source_account_id})."; Unrated calls: ".sprintf("%5d",$_->{calls_number})."; Period: $_->{start_time_min} - $_->{start_time_max};"} @$unrated_calls_info); $logger->debug($msg); print $msg; @@ -697,15 +745,15 @@ All options like resellers, customers, period specification are considered toget =over 4 -=item B<--reseller_id=ID1[,IDn]> +=item B<--reseller-id=ID1[,IDn]> Generate invoices only for specified resellers customers -=item B<--client_contact_id=ID1[,IDn]> +=item B<--client-contact-id=ID1[,IDn]> Generate invoices only for customers, defined by their contact IDs -=item B<--client_contract_id=ID1[,IDn]> +=item B<--client-contract-id=ID1[,IDn]> Generate invoices only for customers, defined by their contract IDs @@ -737,27 +785,29 @@ Makes to send invoices, which haven't been sent yet, to customers. Other options Makes to send invoices, which have been sent already, to customers. Other options: resellers, customers, period specification will be considered. Default is false. -=item B<--allow_terminated> +=item B<--allow-terminated> Generates invoices for terminated contracts too. -=item B<--force_unrated> +=item B<--force-unrated> Generate invoices despite unrated calls existence in the period. -=item B<--backward_is_active> +=item B<--backward-is-active> Use old is_active logic of invoice_template selection. For internal use. -=item B<--update_contract_balance> +=item B<--update-contract-balance> For internal use. Update contract_balances *_balance_interval fields with values according to invoice lists. -=item B<--update_contract_balance_nonzero> +=item B<--update-contract-balance-nonzero> -For internal use. Configuration for option --update_contract_balance. Allows update contract_balances.[cash|free_time]_balance_interval fields even if old values aren't empty. +For internal use. Configuration for option --update-contract-balance. +Allows update contract_balances.[cash|free_time]_balance_interval fields even +if old values aren't empty. -=item B<--no_empty> +=item B<--no-empty> Deny generate invoices for invoices without calls and null permanent fee. diff --git a/tools_bin/ngcp-provisioning-template b/tools_bin/ngcp-provisioning-template index db5803c431..ab2cb6c3b9 100755 --- a/tools_bin/ngcp-provisioning-template +++ b/tools_bin/ngcp-provisioning-template @@ -46,11 +46,30 @@ pod2usage(2) unless $template_name; pod2usage(1) if $template_name =~ /help|\?/; my $help; my $log_level; + +# XXX: Remove after mr10.5. +sub parse_old_db_option { + my ($name, $value) = @_; + my $newname = $name =~ tr/_/-/r; + $db{$name} = $value; + warn "$0: option --$name is deprecated; use --$newname instead\n"; +} + +# XXX: Remove after mr10.5. +sub parse_old_log_level_option { + my ($name, $value) = @_; + my $newname = $name =~ tr/_/-/r; + $log_level = $value; + warn "$0: option --$name is deprecated; use --$newname instead\n"; +} + Getopt::Long::Configure("pass_through"); Getopt::Long::Configure("permute"); GetOptions( - ( map { ('db_' . $_ . ':s') => \$db{$_}; } keys %db ), - 'log_level:s' => \$log_level, + ( map { ('db_' . $_ . ':s') => \&parse_old_db_option } keys %db ), + ( map { ('db-' . $_ . ':s') => \$db{$_}; } keys %db ), + 'log_level:s' => \&parse_old_log_level_option, + 'log-level:s' => \$log_level, "help|?" => \$help, ) or pod2usage(2); pod2usage(1) if $help; @@ -345,35 +364,39 @@ by that template. The form fields can be passed as command line options. Print a brief help message and exits. -=item B<--db_host=>I +=item B<--db-host=>I The host of the ngcp database to connect to. If omitted, the database connection settings of ngcp-panel will be used. -=item B<--db_port=>I +=item B<--db-port=>I -The port of the ngcp database to connect to. Only relevant if --db_host is specified. +The port of the ngcp database to connect to. +Only relevant if B<--db-host> is specified. -=item B<--db_user=>I +=item B<--db-user=>I -The database user for the ngcp database to connect to. Only relevant if --db_host is specified. +The database user for the ngcp database to connect to. +Only relevant if B<--db-host> is specified. -=item B<--db_password=>I +=item B<--db-password=>I -The database user password (if any) for the ngcp database to connect to. Only relevant if --db_host is specified. +The database user password (if any) for the ngcp database to connect to. +Only relevant if B<--db-host> is specified. =item B<--file=>I<.csv-filename> Specify a .csv file to process. Each row represents form values for one subscriber to create. -=item B<--first_name=>I +=item B<--first-name=>I -Provide the value for a form field "first_name" (if you have such in your provisioning template). Only relevant if no --file is specified. +Provide the value for a form field "first_name" (if you have such in your +provisioning template). Only relevant if no --file is specified. =item B<--purge> Terminate an existing subscriber with duplicate number/aliases first. -=item B<--log_level> +=item B<--log-level> Verbosity of printed messages while processing (debug, info, warn, error). @@ -381,7 +404,7 @@ Verbosity of printed messages while processing (debug, info, warn, error). =head1 EXAMPLES -ngcp-provisioning-template "My First Provisioning Template" --first_name="John" --last_name="Doe" --cc="43" --ac="316" --sn="123456" --purge +ngcp-provisioning-template "My First Provisioning Template" --first-name="John" --last-name="Doe" --cc="43" --ac="316" --sn="123456" --purge ... runs "My First Provisioning Template" from config.yml using first_name "John", last_name "Doe" etc.