applied patch #753 for Getopt::Long support (with a fix for --verbose)

This commit is contained in:
Gaël Roualland 2002-12-02 00:16:03 +00:00
parent 2a848d22af
commit 118422d5ec

110
stow.in
View file

@ -42,101 +42,23 @@ $Restow = 0;
$Force = 0; $Force = 0;
@Subdirs = (); @Subdirs = ();
use Getopt::Long;
Getopt::Long::Configure ("gnu_getopt");
# FIXME: use Getopt::Long GetOptions(
while (@ARGV && ($_ = $ARGV[0]) && /^-/) { 'n|no' => \$NotReally,
$opt = $'; 'c|conflicts' => sub { $Conflicts = 1; $NotReally = 1; },
shift; 'i|ignore' => \$Conflicts,
last if /^--$/; 'f|force' => sub { $Force = 1; $Conflicts = 1; },
'd|dir=s' => \$Stow,
if ($opt =~ /^-/) { 't|target=s' => \$Target,
$opt = $'; 's|subdirs=s' => sub { my($arg, $val) = @_; @Subdirs = split( /:/, $val ); },
if ($opt =~ /^no?$/i) { 'v|verbose:i' => sub { my($arg, $val) = @_; $Verbose = $val ? $val : $Verbose + 1; },
$NotReally = 1; 'D|delete' => \$Delete,
} elsif ($opt =~ /^c(o(n(f(l(i(c(ts?)?)?)?)?)?)?)?$/i) { 'R|restow' => \$Restow,
$Conflicts = 1; 'V|version' => sub { my($arg, $val) = @_; &version() if ( $val ); },
$NotReally = 1; 'h|help' => sub { my($arg, $val) = @_; &usage(undef) if ($val); },
} elsif ($opt =~ /^i(g(n(o(r(e?)?)?)?)?)$/i) { ) or usage(undef);
$Conflicts = 1;
} elsif ($opt =~ /^f(o(r(c(e?)?)?)?)$/i) {
$Force = 1;
$Conflicts = 1;
} elsif ($opt =~ /^dir?/i) {
$remainder = $';
if ($remainder =~ /^=/) {
$Stow = $'; # the stuff after the =
} else {
$Stow = shift;
}
} elsif ($opt =~ /^t(a(r(g(et?)?)?)?)?/i) {
$remainder = $';
if ($remainder =~ /^=/) {
$Target = $'; # the stuff after the =
} else {
$Target = shift;
}
} elsif ($opt =~ /^s(u(b(d(i(rs?)?)?)?)?)?/i) {
$remainder = $';
if ($remainder =~ /^=/) {
$remainder = $'; # the stuff after the =
} else {
$remainder = shift; # the following argument
}
@Subdirs = split(/:/, $remainder);
warn "remainder='$remainder' Subdirs = (@Subdirs)\n" if ($Verbose > 1);
} elsif ($opt =~ /^verb(o(se?)?)?/i) {
$remainder = $';
if ($remainder =~ /^=(\d+)/) {
$Verbose = $1;
} else {
++$Verbose;
}
} elsif ($opt =~ /^de(l(e(te?)?)?)?$/i) {
$Delete = 1;
} elsif ($opt =~ /^r(e(s(t(o(w?)?)?)?)?)?$/i) {
$Restow = 1;
} elsif ($opt =~ /^vers(i(on?)?)?$/i) {
&version();
} else {
&usage(($opt =~ /^h(e(lp?)?)?$/) ? undef :
"unknown or ambiguous option: $opt");
}
} else {
@opts = split(//, $opt);
while ($_ = shift(@opts)) {
if ($_ eq 'n') {
$NotReally = 1;
} elsif ($_ eq 'c') {
$Conflicts = 1;
$NotReally = 1;
} elsif ($_ eq 'i') {
$Conflicts = 1;
} elsif ($_ eq 'f') {
$Force = 1;
$Conflicts = 1;
} elsif ($_ eq 'd') {
$Stow = (join('', @opts) || shift);
@opts = ();
} elsif ($_ eq 't') {
$Target = (join('', @opts) || shift);
@opts = ();
} elsif ($_ eq 'v') {
++$Verbose;
} elsif ($_ eq 'D') {
$Delete = 1;
} elsif ($_ eq 'R') {
$Restow = 1;
} elsif ($_ eq 's') {
@Subdirs = split(/:/, (join('', @opts) || shift));
@opts = ();
} elsif ($_ eq 'V') {
&version();
} else {
&usage(($_ eq 'h') ? undef : "unknown option: $_");
}
}
}
}
&usage("No packages named") unless @ARGV; &usage("No packages named") unless @ARGV;