From bd13e5a4761fa1cc8e6594bc647a053dabceba07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Fri, 21 Jan 2022 13:26:24 +0000 Subject: [PATCH] enh: osh-encrypt-rsync: catch warnings emitted by GetOptions --- bin/cron/osh-encrypt-rsync.pl | 36 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/bin/cron/osh-encrypt-rsync.pl b/bin/cron/osh-encrypt-rsync.pl index e4d8e1c..356421e 100755 --- a/bin/cron/osh-encrypt-rsync.pl +++ b/bin/cron/osh-encrypt-rsync.pl @@ -549,23 +549,27 @@ EOF sub main { _log "Starting..."; - if ( - !GetOptions( - "dry-run" => \$dryRun, - "config-test" => \$configTest, - "no-delete" => \$noDelete, - "encrypt-only" => \$encryptOnly, - "rsync-only" => \$rsyncOnly, - "force-delete" => \$forceDelete, - "force-encrypt" => \$forceEncrypt, - "verbose+" => \$verbose, - "help" => \$help, - ) - ) { - _err "Error while parsing command-line options"; - print_usage(); - return 1; + my $optwarn = 'Unknown error'; + local $SIG{'__WARN__'} = sub { $optwarn = shift; }; + if ( + !GetOptions( + "dry-run" => \$dryRun, + "config-test" => \$configTest, + "no-delete" => \$noDelete, + "encrypt-only" => \$encryptOnly, + "rsync-only" => \$rsyncOnly, + "force-delete" => \$forceDelete, + "force-encrypt" => \$forceEncrypt, + "verbose+" => \$verbose, + "help" => \$help, + ) + ) + { + _err "Error while parsing command-line options: $optwarn"; + print_usage(); + return 1; + } } if ($help) {