Skip to content

Commit

Permalink
Added 'wgd snapshot' command
Browse files Browse the repository at this point in the history
Exports asset tree to file tree
  • Loading branch information
patspam committed Aug 19, 2009
1 parent 7e387f1 commit 9565d71
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions lib/WGDev/Command/Snapshot.pm
@@ -0,0 +1,92 @@
package WGDev::Command::Snapshot;
use strict;
use warnings;
use 5.008008;

our $VERSION = '0.2.0';

use WGDev::Command::Base;
use Carp;
BEGIN { our @ISA = qw(WGDev::Command::Base) }

use WGDev::X ();

sub config_options {
return qw(
to=s
);
}

sub process {
my $self = shift;

require Cwd;
require File::Spec;
require File::Path;
require File::Slurp::Tree;

my $to = $self->option('to') || Cwd::getcwd;
print "Writing to: $to\n";
File::Path::make_path("$to");
require Encode;
for my $asset_spec ( $self->arguments ? $self->arguments : 'root' ) {
my $asset = eval { $self->wgd->asset->find($asset_spec) };
if ( !$asset ) {
warn $@;
next;
}
my %tree;
my $assets = $asset->getLineageIterator(['self', 'descendants']);
while ( my $asset = $assets->() ) {
my $url = $asset->get('url');
File::Path::make_path("$to/$url");
$tree{"${url}_"} = Encode::encode('utf8', $self->wgd->asset->serialize($asset));
}
File::Slurp::Tree::spew_tree( $to => \%tree );
}
return 1;
}

1;

__END__
=head1 NAME
WGDev::Command::Snapshot - Snapshots asset tree to a file tree
=head1 SYNOPSIS
wgd snapshot [--to dir] <asset> [<asset> ...]
=head1 DESCRIPTION
Snapshots asset tree to file tree.
=head1 OPTIONS
=over 8
=item C<--to>
Target directory (defaults to current directory).
=item C<< <asset> >>
Either an asset URL, ID, class name. As many can be specified as desired.
=back
=head1 AUTHOR
Patrick Donelan <pat@patspam.com>
=head1 LICENSE
Copyright (c) Patrick Donelan.
This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut

0 comments on commit 9565d71

Please sign in to comment.