123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package Automake::Getopt;
- use 5.006;
- use strict;
- use warnings FATAL => 'all';
- use Exporter ();
- use Getopt::Long ();
- use Automake::ChannelDefs qw/fatal/;
- use Carp qw/croak confess/;
- use vars qw (@ISA @EXPORT);
- @ISA = qw (Exporter);
- @EXPORT= qw/getopt/;
- sub parse_options (%)
- {
- my %option = @_;
- Getopt::Long::Configure ("bundling", "pass_through");
-
-
- Getopt::Long::GetOptions (%option)
- or confess "error in options specification (likely)";
- if (@ARGV && $ARGV[0] =~ /^-./)
- {
- my %argopts;
- for my $k (keys %option)
- {
- if ($k =~ /(.*)=s$/)
- {
- map { $argopts{(length ($_) == 1)
- ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
- }
- }
- if ($ARGV[0] eq '--')
- {
- shift @ARGV;
- }
- elsif (exists $argopts{$ARGV[0]})
- {
- fatal ("option '$ARGV[0]' requires an argument\n"
- . "Try '$0 --help' for more information.");
- }
- else
- {
- fatal ("unrecognized option '$ARGV[0]'.\n"
- . "Try '$0 --help' for more information.");
- }
- }
- }
- 1;
|