App-Critique
view release on metacpan or search on metacpan
lib/App/Critique/Command/remove.pm view on Meta::CPAN
package App::Critique::Command::remove;
use strict;
use warnings;
our $VERSION = '0.05';
our $AUTHORITY = 'cpan:STEVAN';
use App::Critique::Session;
use App::Critique -command;
sub opt_spec {
my ($class) = @_;
return (
[ 'dry-run', 'display list of files to be removed, but do not remove them' ],
[],
$class->SUPER::opt_spec,
);
}
sub execute {
my ($self, $opt, $args) = @_;
my $session_file = App::Critique::Session->locate_session_file( $opt->git_work_tree );
if (not -e $session_file) {
if ( $opt->verbose ) {
warning(
'Unable to locate session file, looking for (%s)',
$session_file // 'undef'
);
}
error('No session file found, nothing removed.');
}
info('Attempting to remove session file ...');
if ( $opt->dry_run ) {
info('[dry-run] Found session file (%s), not removing.', $session_file);
}
else {
if ( $session_file->remove ) {
info('Successfully removed session file (%s).', $session_file);
}
else {
if ( $opt->verbose ) {
warning(
'Could not remove session file (%s) because: %s',
$session_file,
$!
);
}
error('Unable to remove session file.');
}
info('Attempting to clean up session directory ...');
my $branch = $session_file->parent;
if ( my @children = $branch->children ) {
info('Branch directory (%s) is not empty, it will not be removed', $branch);
if ( $opt->verbose ) {
info('Branch directory (%s) contains:', $branch);
info(' %s', $_) foreach @children;
}
}
else {
info('Attempting to remove empty branch directory ...');
if ( $branch->remove_tree ) {
info('Successfully removed empty branch directory (%s).', $branch);
}
else {
if ( $opt->verbose ) {
warning(
'Could not remove empty branch directory (%s) because: %s',
$branch,
$!
);
( run in 3.520 seconds using v1.01-cache-2.11-cpan-63c85eba8c4 )