#!/usr/bin/perl
use strict;
use LEOCHARRE::CLI2; 
use File::EmptyDirs 'remove_empty_dirs';
use Cwd;

my @DIRS =
   grep {
      -d $_ or die("Argument '$_' is not a directory on disk.\n")
   } @ARGV;

#@DIRS ||= (cwd());


#(scalar @DIRS) or (push @DIRS, cwd());  
@DIRS or ( push @DIRS, cwd() );


#$opt_d and ( (warn "# dir arg: $_\n") for @DIRS );
debug("dirs: @DIRS");

for my $d (@DIRS) {
   -d $d or die("$d not a dir");
   my @removed = remove_empty_dirs($d);
   if ($opt_d){
      warn "# removed:\n";
      (warn "# $_\n") for @removed;
   }
}





sub usage { qq{ermdir [OPTION].. PATH..
Remove empty directories recursively.

   -d          debug
   -h          help
   -v          version

Where PATH is one or more directories on disk.

Try 'man ermdir' for more info.
}}


exit;

__END__

=pod

=head1 NAME

ermdir - Remove empty directories recursively.

=head1 USAGE

ermdir [OPTION].. PATH..

   -d          debug
   -h          help
   -v          version

Where PATH is one or more directories on disk.

=head1 SEE ALSO

L<File::EmptyDirs> - parent package.

=head1 AUTHOR

Leo Charre leocharre at cpan dot org

=head1 COPYRIGHT

Copyright (c) 2009 Leo Charre. All rights reserved.

=head1 LICENSE

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".

=head1 DISCLAIMER

This package 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.
   
=cut

