perl: Fold if into previous else
[dpkg.git] / scripts / dpkg-buildtree.pl
blobf2505981339655d939597e65802cc6da6292a2e7
1 #!/usr/bin/perl
3 # dpkg-buildtree
5 # Copyright © 2023 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 strict;
21 use warnings;
23 use Dpkg ();
24 use Dpkg::Gettext;
25 use Dpkg::ErrorHandling;
26 use Dpkg::BuildTree;
28 textdomain('dpkg-dev');
30 sub version {
31 printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
33 printf g_('
34 This is free software; see the GNU General Public License version 2 or
35 later for copying conditions. There is NO warranty.
36 ');
39 sub usage {
40 printf g_(
41 'Usage: %s [<command>]')
42 . "\n\n" . g_(
43 'Commands:
44 clean clean dpkg generated artifacts from the build tree.
45 --help show this help message.
46 --version show the version.
47 '), $Dpkg::PROGNAME;
50 my $action;
52 while (@ARGV) {
53 my $arg = shift @ARGV;
54 if ($arg eq 'clean') {
55 usageerr(g_('two commands specified: %s and %s'), $1, $action)
56 if defined $action;
57 $action = $arg;
58 } elsif ($arg eq '-?' or $arg eq '--help') {
59 usage();
60 exit 0;
61 } elsif ($arg eq '--version') {
62 version();
63 exit 0;
64 } else {
65 usageerr(g_("unknown option '%s'"), $arg);
69 usageerr(g_('missing action')) unless $action;
71 my $bt = Dpkg::BuildTree->new();
73 if ($action eq 'clean') {
74 $bt->clean();