[Bps-public-commit] r12862 - in Shipwright/trunk: . lib/Shipwright/Script t

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Jun 4 10:33:23 EDT 2008


Author: sunnavy
Date: Wed Jun  4 10:33:20 2008
New Revision: 12862

Added:
   Shipwright/trunk/lib/Shipwright/Script/Delete.pm
Modified:
   Shipwright/trunk/   (props changed)
   Shipwright/trunk/lib/Shipwright/Script.pm
   Shipwright/trunk/t/00.load.t

Log:
 r12941 at sunnavys-mb:  sunnavy | 2008-06-04 22:31:27 +0800
 added delete cmd


Modified: Shipwright/trunk/lib/Shipwright/Script.pm
==============================================================================
--- Shipwright/trunk/lib/Shipwright/Script.pm	(original)
+++ Shipwright/trunk/lib/Shipwright/Script.pm	Wed Jun  4 10:33:20 2008
@@ -8,7 +8,7 @@
 =cut
 
 sub alias {
-    return ( ls => 'list' );
+    return ( ls => 'list', 'del' => 'delete' );
 }
 
 =head2 prepare

Added: Shipwright/trunk/lib/Shipwright/Script/Delete.pm
==============================================================================
--- (empty file)
+++ Shipwright/trunk/lib/Shipwright/Script/Delete.pm	Wed Jun  4 10:33:20 2008
@@ -0,0 +1,110 @@
+package Shipwright::Script::Delete;
+
+use strict;
+use warnings;
+use Carp;
+
+use base qw/App::CLI::Command Class::Accessor::Fast Shipwright::Script/;
+__PACKAGE__->mk_accessors(qw/repository log_level log_file name/);
+
+use Shipwright;
+use File::Spec;
+use Shipwright::Util;
+
+sub options {
+    (
+        'r|repository=s' => 'repository',
+        'l|log-level=s'  => 'log_level',
+        'log-file=s'     => 'log_file',
+        'name=s'         => 'name',
+    );
+}
+
+sub run {
+    my $self = shift;
+    my $name = shift;
+
+    $self->name($name) if $name && !$self->name;
+
+    die "need name arg" unless $self->name();
+
+    my $shipwright = Shipwright->new(
+        repository => $self->repository,
+        log_level  => $self->log_level,
+        log_file   => $self->log_file,
+    );
+
+    my $map = $shipwright->backend->map || {};
+
+    if ( $map->{ $self->name } ) {
+
+        # it's a cpan module
+        $self->name( $map->{ $self->name } );
+    }
+
+    $name = $self->name;
+
+    my $order = $shipwright->backend->order;
+
+    die "no such dist: $name" unless grep { $_ eq $name } @$order;
+        
+    $shipwright->backend->delete( path => "dists/$name" );
+    $shipwright->backend->delete( path => "scripts/$name" );
+
+    # clean order.yml
+    @$order = grep { $_ ne $name } @$order;
+    $shipwright->backend->order($order);
+
+    # clean version.yml, map.yml, source.yml and flags.yml
+    my $version = $shipwright->backend->version;
+    for ( keys %$version ) {
+        if ( $_ eq $name ) {
+            delete $version->{$_};
+            last;
+        }
+    }
+
+    for ( keys %$map ) {
+        delete $map->{$_} if $map->{$_} eq $name;
+    }
+
+    my $source = $shipwright->backend->source || {};
+
+    for ( keys %$source ) {
+        if ( $_ eq $name ) {
+            delete $source->{$_} if $_ eq $name;
+            last;
+        }
+    }
+
+    my $flags = $shipwright->backend->flags;
+    for my $flag ( keys %$flags ) {
+        @{ $flags->{$flag} } = grep { $_ ne $name } @{ $flags->{$flag} };
+    }
+
+    $shipwright->backend->version($version);
+    $shipwright->backend->map($map);
+    $shipwright->backend->source($source);
+    $shipwright->backend->flags($flags);
+
+    print "deleted $name with success\n";
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Shipwright::Script::Delete - delete a dist
+
+=head1 SYNOPSIS
+
+  shipwright delete          delete a source
+
+ Options:
+   --repository(-r)   specify the repository of our project
+   --log-level(-l)    specify the log level
+   --log-file         specify the log file
+   --name             specify the dist name
+

Modified: Shipwright/trunk/t/00.load.t
==============================================================================
--- Shipwright/trunk/t/00.load.t	(original)
+++ Shipwright/trunk/t/00.load.t	Wed Jun  4 10:33:20 2008
@@ -1,4 +1,4 @@
-use Test::More tests => 26;
+use Test::More tests => 27;
 
 BEGIN {
     use_ok('Shipwright');
@@ -25,6 +25,7 @@
     use_ok('Shipwright::Script::Help');
     use_ok('Shipwright::Script::Maintain');
     use_ok('Shipwright::Script::Update');
+    use_ok('Shipwright::Script::Delete');
     use_ok('Shipwright::Test');
     use_ok('Shipwright::Util');
 }



More information about the Bps-public-commit mailing list