# HG changeset patch # User Heiko Schlittermann # Date 1295822131 -3600 # Node ID 26c6306bd9cc22988c0d21aaf9c2f64ee84be426 # Parent cb92affcf59f888cb9fae6abdec25d55ac5a6839 zone-rm now works diff -r cb92affcf59f -r 26c6306bd9cc bin/zone-rm --- a/bin/zone-rm Sun Jan 23 22:34:12 2011 +0100 +++ b/bin/zone-rm Sun Jan 23 23:35:31 2011 +0100 @@ -1,32 +1,82 @@ #!/usr/bin/perl +use v5.10; use warnings; use strict; -use File::Path; +use File::Path qw(remove_tree); use DNStools::Config qw(get_config); - -# liest die Konfiguration ein -my %config = get_config(); +use Net::LibIDN qw(:all); +use Pod::Usage; +use Getopt::Long; -my $master_dir = $config{"master_dir"}; -my $conf_dir = $config{"zone_conf_dir"}; +my $CHARSET = "UTF-8"; + +my %cf = get_config(); -for (@ARGV) { - chomp(my $zone = `idn --quiet "$_"`); +my $opt_interactive = 0; + +MAIN: { - if (-d "$master_dir/$zone") { - rmtree "$master_dir/$zone/" - and print "zone-dir for $zone removed\n"; - } - else { - print "$master_dir/$zone: $!\n"; - } + GetOptions( + "i|interactive!" => \$opt_interactive, + "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) }, + "m|man" => sub { + pod2usage( + -exit => 0, + -verbose => 2, + -noperldoc => system("perldoc -V &>/dev/null") + ); + }, + ) + and @ARGV + or pod2usage; - if (-e "$conf_dir/$zone") { - unlink "$conf_dir/$zone" - and print "configuration-file for $zone removed\n"; - } - else { - print "$conf_dir/$zone: $!\n"; + for my $utf8zone (@ARGV) { + my $zone = idn_to_ascii($utf8zone, $CHARSET); + + if (not(-d "$cf{master_dir}/$zone" or -f "$cf{zone_conf_dir}/$zone")) { + say "$utf8zone ($zone): nothing found"; + next; + } + + if ($opt_interactive) { + print "Remove $utf8zone ($zone)? [y/n]: "; + chomp($_ = ); + next if not /^y(?:es)?$/i; + } + + remove_tree("$cf{master_dir}/$zone", "$cf{zone_conf_dir}/$zone", + { verbose => 1 }); + } } + +__END__ + +=head1 NAME + + zone-rm - remove a zone + +=head1 SYNOPSIS + + zone-rm [-i|--interactive] zone... + + zone-rm [-h|--help] + zone-rm [-m|--man] + +=head1 DESCRIPTION + +This removes the specified zone(s) from the configured directories. + +=head1 OPTIONS + +The standard B<-h>, B<--help>, B<-m>, and B<--man> options are +understood. + +=over + +=item B<-i>|B<--interactive> + +Ask for confirmation. (default: off) + +=cut diff -r cb92affcf59f -r 26c6306bd9cc t/00-perl-c.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/t/00-perl-c.t Sun Jan 23 23:35:31 2011 +0100 @@ -0,0 +1,17 @@ +use v5.10; +use strict; +use warnings; + +use Test::More; +use File::Find; + +plan skip_all => "no blib directories in \@INC" + if not /blib/ ~~ @INC; + +find(sub{ + -f -x or return; + system("perl -Mblib -c $_ &>/dev/null"); + is($? => 0, "syntax $File::Find::name"); +}, "blib/"); + +done_testing;