Skip to content

Commit be3d058

Browse files
committedJan 18, 2012
Add a command to list assets in the trash.
1 parent 4ae4877 commit be3d058

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed
 

‎lib/WGDev/Command/Trash.pm

+37-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package WGDev::Command::Trash;
22
# ABSTRACT: Trash assets by URL/assetId
33
use strict;
44
use warnings;
5+
use WGDev::Command::Ls;
56
use 5.008008;
67

78
use parent qw(WGDev::Command::Base);
@@ -12,17 +13,29 @@ sub config_options {
1213
return qw(
1314
purge
1415
restore
16+
list
1517
);
1618
}
1719

1820
sub process {
1921
my $self = shift;
2022
my $wgd = $self->wgd;
21-
my @asset_specs = $self->arguments;
23+
if ($self->option('list')) {
24+
return $self->list_trash;
25+
}
26+
else {
27+
return $self->trash;
28+
}
29+
}
30+
31+
sub trash {
32+
my $self = shift;
33+
my $wgd = $self->wgd;
2234
my $error;
2335
my $method = $self->option('purge') ? 'purge'
2436
: $self->option('restore') ? 'restore'
2537
: 'trash';
38+
my @asset_specs = $self->arguments;
2639
ASSET:
2740
while ( my $asset_spec = shift @asset_specs ) {
2841
my $asset;
@@ -41,15 +54,33 @@ sub process {
4154
return (! $error);
4255
}
4356

57+
sub list_trash {
58+
my $self = shift;
59+
my $wgd = $self->wgd;
60+
my $root = $wgd->asset->root;
61+
my $trashed_assets = $root->getAssetsInTrash();
62+
my $ls = WGDev::Command::Ls->new($wgd);
63+
my $format = '%assetId% %url:-35% %title%';
64+
ASSET:
65+
foreach my $asset ( @{ $trashed_assets } ) {
66+
next ASSET unless $asset;
67+
my $output = $ls->format_output( $format, $asset );
68+
print $output . "\n";
69+
}
70+
71+
return 1;
72+
}
73+
4474
1;
4575

4676
=head1 SYNOPSIS
4777
4878
wgd trash [--purge] [--restore] <asset> [<asset> ...]
79+
wgd trash [--list]
4980
5081
=head1 DESCRIPTION
5182
52-
Puts assets into the trash, or purges them.
83+
Methods for working with assets in the trash.
5384
5485
=head1 OPTIONS
5586
@@ -63,6 +94,10 @@ Purges the assets from the system instead of putting it into the trash.
6394
6495
Restores the assets that have been trashed to the regular, published state.
6596
97+
=item C<--list>
98+
99+
Lists all assets in the trash.
100+
66101
=item C<< <asset> >>
67102
68103
Either an asset URL or an ID. As many can be specified as desired.

0 commit comments

Comments
 (0)
Please sign in to comment.