#!/usr/bin/perl
#
# Copyright 2014-2016 - Giovanni Simoni
#
# This file is part of PFT.
#
# PFT is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# PFT is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with PFT.  If not, see <http://www.gnu.org/licenses/>.

=encoding utf8

=head1 NAME

pft clean - Clean the build directory

=head1 SYNOPSIS

B<pft> B<clean> [B<-v>]

=head1 DESCRIPTION

Syntactic sugar for a plain removal of the C<ROOT/build> directory

=head1 OPTIONS

=over

=item --verbose | -v

Be verbose.

=item --help | -h

Show this help text.

=back

=cut

use v5.16;
use strict;
use warnings;
use utf8;

use Encode;
use Encode::Locale;
use File::Path;

use Getopt::Long;
Getopt::Long::Configure ("bundling");

use App::PFT;
use PFT::Tree;

my $verbose = 0;
GetOptions(
    'verbose|v' => \$verbose,
    'help|h' => sub {
        pod2usage
            -exitval => 1,
            -verbose => 2,
            -input => App::PFT::help_of 'clean',
    }
) or exit 1;

my $tree = eval{ PFT::Tree->new } || do {
    say STDERR $@ =~ s/ at.*$//rs;
    exit 1
};

File::Path::rmtree
    encode(locale_fs => $tree->dir_build),
    { verbose => $verbose }
;
