perl: Fold if into previous else
[dpkg.git] / scripts / dpkg-buildapi.pl
blob2981eebb00608af7a0352d40858e239e9f608386
1 #!/usr/bin/perl
3 # dpkg-buildapi
5 # Copyright © 2022 Guillem Jover <guillem@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 use warnings;
21 use strict;
23 use Dpkg ();
24 use Dpkg::Gettext;
25 use Dpkg::ErrorHandling;
26 use Dpkg::BuildAPI qw(get_build_api);
27 use Dpkg::Control::Info;
29 textdomain('dpkg-dev');
31 sub version()
33 printf(g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION);
36 sub usage()
38 printf g_(
39 'Usage: %s [<option>...] [<command>]')
40 . "\n\n" . g_(
41 'Commands:
42 -?, --help show this help message.
43 --version show the version.')
44 . "\n\n" . g_(
45 'Options:
46 -c<control-file> get control info from this file.
47 '), $Dpkg::PROGNAME;
50 my $controlfile = 'debian/control';
52 while (@ARGV) {
53 $_ = shift(@ARGV);
54 if (m/^-\?|--help$/) {
55 usage();
56 exit 0;
57 } elsif (m/^--version$/) {
58 version();
59 exit 0;
60 } elsif (m/-c(.*)$/) {
61 $controlfile = $1;
62 } elsif (m/^--$/) {
63 last;
64 } elsif (m/^-/) {
65 usageerr(g_("unknown option '%s'"), $_);
66 } else {
67 usageerr(g_('no arguments accepted'));
71 my $ctrl = Dpkg::Control::Info->new($controlfile);
73 print get_build_api($ctrl) . "\n";