Package: whohas Version: 0.22-2 Severity: wishlist Tags: patch Hi Philipp and Jonathan,
Currently whohas is parsing its own command-line options. There's a pair of standard Perl libraries (Getopt::Std and Getopt::Long) which do it for you. The main reason I'd like you to use it is because new options can then be added with just two extra lines around the GetOptions() call. As the attached patch stands, it also does this: -n is equivalent to --no-threads "-d Dist1 -d Dist2" is equivalent to "-d Dist1,Dist2" There are options for Getopt if "-n" should be reserved for future use. The patch goes on top of all the Debian 0.22-2 patches. It should also apply cleanly to (0.22 + abort if given an unsupported distribution). Cheers, Steve
commit c37e106c5c302dc803ee464eb39bf23f83e86201 Author: Steve Cotton <st...@s.cotton.clara.co.uk> Date: Thu Jan 29 12:26:09 2009 +0000 Parse arguments with Getopt::Long diff --git a/program/whohas b/program/whohas index 5e02398..7eb8da7 100755 --- a/program/whohas +++ b/program/whohas @@ -61,48 +61,56 @@ my $fedora_bool = 1; my @thrs; my $here = 0; +use Getopt::Long; +my @option_distro; +my $option_nothreads; +GetOptions( + "d=s" => \...@option_distro, + "no-threads" => \$option_nothreads, +); + if (@ARGV > 1) { - for (my $i = 0; $i < @ARGV; $i++) { - if ($ARGV[$i] eq "-d") { - $arch_bool = 0; - $debian_bool = 0; - $fink_bool = 0; - $freebsd_bool = 0; - $macports_bool = 0; - $netbsd_bool = 0; - $openbsd_bool = 0; - $opensuse_bool = 0; - $slack_bool = 0; - $sourcemage_bool = 0; - $ubuntu_bool = 0; - $gentoo_bool = 0; - $fedora_bool = 0; - my @parts = split /,/, $ARGV[$i+1]; - for (my $a = 0; $a < @parts; $a++) { - if ( $parts[$a] =~ /archlinux/i) { $arch_bool = 1; - } elsif ( $parts[$a] =~ /debian/i) { $debian_bool = 1; - } elsif ( $parts[$a] =~ /fink/i) { $fink_bool = 1; - } elsif ( $parts[$a] =~ /freebsd/i) { $freebsd_bool = 1; - } elsif ( $parts[$a] =~ /macports/i) { $macports_bool = 1; - } elsif ( $parts[$a] =~ /netbsd/i) { $netbsd_bool = 1; - } elsif ( $parts[$a] =~ /openbsd/i) { $openbsd_bool = 1; - } elsif ( $parts[$a] =~ /opensuse/i) { $opensuse_bool = 1; - } elsif ( $parts[$a] =~ /slackware/i) { $slack_bool = 1; - } elsif ( $parts[$a] =~ /sourcemage/i) { $sourcemage_bool = 1; - } elsif ( $parts[$a] =~ /ubuntu/i) { $ubuntu_bool = 1; - } elsif ( $parts[$a] =~ /gentoo/i) { $gentoo_bool = 1; - } elsif ( $parts[$a] =~ /fedora/i) { $fedora_bool = 1; - } else { - die "Unsupported distribution '$parts[$a]'\n"; - } - } - splice @ARGV, $i, 2; - last; + die "Error:\tToo many parameters. Usage: $0 [--no-threads] [-d Dist1[,Dist2[,Dist3...]]] pkgname\n"; +} elsif (@ARGV < 1) { + die "Error:\tPlease specify a search term.\n"; +} + +if (@option_distro) { + $arch_bool = 0; + $debian_bool = 0; + $fink_bool = 0; + $freebsd_bool = 0; + $macports_bool = 0; + $netbsd_bool = 0; + $openbsd_bool = 0; + $opensuse_bool = 0; + $slack_bool = 0; + $sourcemage_bool = 0; + $ubuntu_bool = 0; + $gentoo_bool = 0; + $fedora_bool = 0; + @option_distro = split(/,/,join(',',@option_distro)); + for my $distro (@option_distro) { + if ( $distro =~ /archlinux/i) { $arch_bool = 1; + } elsif ( $distro =~ /debian/i) { $debian_bool = 1; + } elsif ( $distro =~ /fink/i) { $fink_bool = 1; + } elsif ( $distro =~ /freebsd/i) { $freebsd_bool = 1; + } elsif ( $distro =~ /macports/i) { $macports_bool = 1; + } elsif ( $distro =~ /netbsd/i) { $netbsd_bool = 1; + } elsif ( $distro =~ /openbsd/i) { $openbsd_bool = 1; + } elsif ( $distro =~ /opensuse/i) { $opensuse_bool = 1; + } elsif ( $distro =~ /slackware/i) { $slack_bool = 1; + } elsif ( $distro =~ /sourcemage/i) { $sourcemage_bool = 1; + } elsif ( $distro =~ /ubuntu/i) { $ubuntu_bool = 1; + } elsif ( $distro =~ /gentoo/i) { $gentoo_bool = 1; + } elsif ( $distro =~ /fedora/i) { $fedora_bool = 1; + } else { + die "Unsupported distribution '$distro'\n"; } } } -if (@ARGV == 1) { +unless ($option_nothreads) { if ($ARGV[0] eq "whohasme") { my $motto = "Congratulations. You discovered an Easter egg. Maybe you can send a quick email to phi1i...@yahoo.com to say hello and tell the developer what you think of the software.\n"; exit; @@ -153,53 +161,49 @@ if (@ARGV == 1) { $_->join; } } -} elsif ($ARGV[0] eq "--no-threads") { +} else { if ($arch_bool == 1) { - &arch( $ARGV[1]); - &aur( $ARGV[1]); + &arch( $ARGV[0]); + &aur( $ARGV[0]); } if ($debian_bool == 1) { - &debian( $ARGV[1]); + &debian( $ARGV[0]); } if ($fedora_bool == 1) { - &fedora( $ARGV[1]); + &fedora( $ARGV[0]); } if ($fink_bool == 1) { - &fink( $ARGV[1]); + &fink( $ARGV[0]); } if ($freebsd_bool == 1) { - &freebsd( $ARGV[1]); + &freebsd( $ARGV[0]); } if ($gentoo_bool == 1) { - &gentoo( $ARGV[1]); + &gentoo( $ARGV[0]); } if ($macports_bool == 1) { - &macports( $ARGV[1]); + &macports( $ARGV[0]); } if ($netbsd_bool == 1) { -# &netbsd( $ARGV[1]); - &netbsd_pkgsrc( $ARGV[1]); +# &netbsd( $ARGV[0]); + &netbsd_pkgsrc( $ARGV[0]); } if ($openbsd_bool == 1) { - &openbsd( $ARGV[1]); + &openbsd( $ARGV[0]); } if ($opensuse_bool == 1) { - &opensuse( $ARGV[1]); + &opensuse( $ARGV[0]); } if ($slack_bool == 1) { - &slack( $ARGV[1]); - &lp_net( $ARGV[1]); + &slack( $ARGV[0]); + &lp_net( $ARGV[0]); } if ($sourcemage_bool == 1) { - &sourcemage($ARGV[1]); + &sourcemage($ARGV[0]); } if ($ubuntu_bool == 1) { - &ubuntu( $ARGV[1]); + &ubuntu( $ARGV[0]); } -} elsif (@ARGV != 0) { - die "Error:\tToo many parameters. Usage: $0 [--no-threads] pkgname\n"; -} else { - die "Error:\tPlease specify a search term.\n"; } sub fedora {