From 10798d26b77ccd680ae35faad241b741768b51c7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 24 Jul 2010 00:21:30 -0400 Subject: [PATCH] simplify --- Pristine/Tar.pm | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/Pristine/Tar.pm b/Pristine/Tar.pm index fc9a2a6..abe0255 100644 --- a/Pristine/Tar.pm +++ b/Pristine/Tar.pm @@ -66,34 +66,31 @@ sub dispatch { my %commands=%{$params{commands}}; my %options=%{$params{options}} if exists $params{options}; - my $run=sub { - my $command=shift; - my $i=$commands{$command}; - if (! defined $i) { - error "Unknown subcommand \"$command\""; - } - - # Check that the right number of args were passed by user. - if (defined $i->[1] && @_ != $i->[1]) { - $command="usage"; - $i=$commands{$command}; - } - - $i->[0]->(@_); - - exit 1 if $command eq "usage"; - }; - + my $command; Getopt::Long::Configure("bundling"); if (! GetOptions(%options, "v|verbose!" => \$verbose, "d|debug!" => \$debug, "k|keep!" => \$keep) || ! @ARGV) { - $run->("usage"); + $command="usage"; + } + else { + $command=shift @ARGV; + } + + my $i=$commands{$command}; + if (! defined $i) { + error "Unknown subcommand \"$command\""; + } + + # Check that the right number of args were passed by user. + if (defined $i->[1] && @ARGV != $i->[1]) { + $command="usage"; + $i=$commands{$command}; } - $run->(@ARGV); + $i->[0]->(@ARGV); } -- 2.34.1