From 8b782b88bd535d739166d21a4cbb95931fff2ce0 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 16 Mar 2009 09:56:35 -0700 Subject: Don't use closure in GetOptions Although it looks cleaner, the error handling for closures is different. Exit in closure from GetOptions, only fails the option not the program. --- scripts/vyatta_quagga_utils.pl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/vyatta_quagga_utils.pl b/scripts/vyatta_quagga_utils.pl index c59bc87e..55254cbb 100755 --- a/scripts/vyatta_quagga_utils.pl +++ b/scripts/vyatta_quagga_utils.pl @@ -6,12 +6,19 @@ use Vyatta::Misc; use NetAddr::IP; use Getopt::Long; -GetOptions("check-prefix-boundry=s" => sub { check_prefix_boundry( $_[1] ); }, - "not-exists=s" => sub { check_not_exists($_[1]); }, - "exists=s" => sub { check_exists($_[1]); }, - "check-ospf-area=s" => sub { check_ospf_area($_[1]); }, +my ($prefix, $exists, $not_exists, $area); + +GetOptions("check-prefix-boundry=s" => \$prefix, + "not-exists=s" => \$not_exists, + "exists=s" => \$exists, + "check-ospf-area=s" => \$area, ); +check_prefix_boundry($prefix) if ($prefix); +check_not_exists($not_exists) if ($not_exists); +check_exists($exists) if ($exists); +check_ospf_area($area) if ($area); + exit 0; sub check_prefix_boundry { @@ -62,6 +69,7 @@ sub check_ospf_area { } exit 0 } - exit 1; + + die "Invalid OSPF area: $area\n"; } -- cgit v1.2.3