From: Joey Hess Date: Sat, 24 Jul 2010 04:21:30 +0000 (-0400) Subject: simplify X-Git-Tag: 1.11~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=10798d26b77ccd680ae35faad241b741768b51c7;p=tools%2Fpristine-tar.git simplify --- 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); }