Skip to content

Commit 0d53d61

Browse files
pbmarklfhaarg
authored andcommittedJul 16, 2012
Added '-d' option to list only the specified Asset(s) (similar to '-d' in ls(1)).
Added the '-d' (--directory) option to list only the specified Assets, rather than their children. This is similar to the '-d' option for ls(1).
1 parent cc38761 commit 0d53d61

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed
 

‎lib/WGDev/Command/Ls.pm

+51-32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use parent qw(WGDev::Command::Base);
88

99
sub config_options {
1010
return qw(
11+
directory|d
1112
format|f=s
1213
long|l
1314
recursive|r
@@ -74,36 +75,42 @@ sub process {
7475
$error++;
7576
next;
7677
}
77-
if ($show_header) {
78-
print "$parent:\n";
78+
if ($self->option('directory')) {
79+
my $parent_asset = $wgd->asset->find($parent);
80+
print $self->format_output( $format, $parent_asset ), "\n";
7981
}
80-
my $child_iter = $asset->getLineageIterator(
81-
[$relatives],
82-
{
83-
$exclude_classes ? ( excludeClasses => $exclude_classes )
84-
: (),
85-
$include_only_classes
86-
? ( includeOnlyClasses => $include_only_classes )
87-
: (),
88-
defined $limit
89-
&& !defined $self->{filter_match} ? ( limit => $limit )
90-
: (),
91-
$isa ? ( isa => $isa ) : (),
92-
} );
93-
while ( my $child = $child_iter->() ) {
94-
next
95-
if !$self->pass_filter($child);
96-
97-
# Handle limit ourselves because smartmatch filtering happens
98-
# *after* getLineage returns its results
99-
last PARENT
100-
if defined $limit && $limit-- <= 0;
101-
102-
my $output = $self->format_output( $format, $child );
103-
print $output . "\n";
104-
}
105-
if (@parents) {
106-
print "\n";
82+
else {
83+
if ($show_header) {
84+
print "$parent:\n";
85+
}
86+
my $child_iter = $asset->getLineageIterator(
87+
[$relatives],
88+
{
89+
$exclude_classes ? ( excludeClasses => $exclude_classes )
90+
: (),
91+
$include_only_classes
92+
? ( includeOnlyClasses => $include_only_classes )
93+
: (),
94+
defined $limit
95+
&& !defined $self->{filter_match} ? ( limit => $limit )
96+
: (),
97+
$isa ? ( isa => $isa ) : (),
98+
} );
99+
while ( my $child = $child_iter->() ) {
100+
next
101+
if !$self->pass_filter($child);
102+
103+
# Handle limit ourselves because smartmatch filtering happens
104+
# *after* getLineage returns its results
105+
last PARENT
106+
if defined $limit && $limit-- <= 0;
107+
108+
my $output = $self->format_output( $format, $child );
109+
print $output . "\n";
110+
}
111+
if (@parents) {
112+
print "\n";
113+
}
107114
}
108115
}
109116
return (! $error);
@@ -154,16 +161,20 @@ sub format_output {
154161

155162
=head1 SYNOPSIS
156163
157-
wgd ls [-l] [--format=<format>] [-r] <asset> [<asset> ...]
164+
wgd ls [-d] [-l] [--format=<format>] [-r] <asset> [<asset> ...]
158165
159166
=head1 DESCRIPTION
160167
161-
Lists children of WebGUI assets
168+
Lists children of WebGUI asset(s), or just the asset(s) themselves
162169
163170
=head1 OPTIONS
164171
165172
=over 8
166173
174+
=item C<-d> C<--directory>
175+
176+
Print only the specified asset (similar to '-d' in ls(1)).
177+
167178
=item C<-l> C<--long>
168179
169180
Use long list format, which includes asset ID, URL, and title.
@@ -178,32 +189,38 @@ using C<%%>.
178189
=item C<-r> C<--recursive>
179190
180191
Recursively list all descendants (by default we only list children).
192+
Ignored when '-d' is set.
181193
182194
=item C<--includeOnlyClass=>
183195
184196
Specify one or more times to limit the results to a certain set of asset classes.
197+
Ignored when '-d' is set.
185198
186199
=item C<--excludeClass=>
187200
188201
Specify one or more times to filter out certain asset class(es) from the results.
202+
Ignored when '-d' is set.
189203
190204
=item C<--limit=>
191205
192-
The maximum amount of entries to return
206+
The maximum amount of entries to return.
207+
Ignored when '-d' is set.
193208
194209
=item C<--isa=>
195210
196211
A class name where you can look for classes of a similar base class.
197212
For example, if you're looking for Donations, Subscriptions, Products
198213
and other subclasses of L<WebGUI::Asset::Sku>, then specify the
199214
parameter C<--isa=WebGUI::Asset::Sku>.
215+
Ignored when '-d' is set.
200216
201217
=item C<--filter=>
202218
203219
Apply smart match filtering against the results. Format looks like
204220
C<%url% ~~ smartmatch>, where C<url> is the field to filter against,
205221
and C<smartmatch> is either a Perl regular expression such as
206222
C</(?i:partial_match)/> or a string such as C<my_exact_match>.
223+
Ignored when '-d' is set.
207224
208225
=back
209226
@@ -215,10 +232,12 @@ the format to output as specified in the L<format option|/-f>.
215232
=method C<option_filter ( $filter )>
216233
217234
Takes a filter specification, verifies that it is specified properly, and saves it.
235+
Ignored when '-d' is set.
218236
219237
=method C<pass_filter ( $asset )>
220238
221239
Checks if a given asset passes the saved filter. Returns true or false.
240+
Ignored when '-d' is set.
222241
223242
=cut
224243

0 commit comments

Comments
 (0)
Please sign in to comment.