App-Glacier
view release on metacpan or search on metacpan
lib/App/Glacier/Command/ListVault.pm view on Meta::CPAN
=item B<long-iso>
List ISO 8601 date and time in minutes, e.g., "2017-05-23 15:53". Equivalent
to "B<+%Y-%m-%d %H:%M>".
=item B<iso>
B<GNU ls>-compatible "iso": ISO 8601 dates for non-recent timestamps (e.g.,
"2017-05-23"), and ISO 8601 month, day, hour, and minute for recent
timestamps (e.g., "03-30 23:45"). Timestamp is considered "recent", if it
is not older than 6 months ago.
=item B<locale>
List timestamps in a locale-dependent form. This is equivalent to B<+%c>.
=back
=back
=head1 SEE ALSO
B<glacier>(1),
B<strftime>(3).
=cut
sub new {
my ($class, $argref, %opts) = @_;
my %sort_vaults = (
none => undef,
name => sub {
my ($a, $b) = @_;
$a->{VaultName} cmp $b->{VaultName}
},
time => sub {
my ($a, $b) = @_;
$a->{CreationDate}->epoch <=> $b->{CreationDate}->epoch;
},
size => sub {
my ($a, $b) = @_;
$a->{SizeInBytes} <=> $b->{SizeInBytes}
}
);
my %sort_archives = (
none => undef,
name => sub {
my ($a, $b) = @_;
$a->{FileName} cmp $b->{FileName}
},
time => sub {
my ($a, $b) = @_;
$a->{CreationDate}->epoch <=> $b->{CreationDate}->epoch;
},
size => sub {
my ($a, $b) = @_;
$a->{Size} <=> $b->{Size}
}
);
my $self = $class->SUPER::new(
$argref,
optmap => {
'cached|c' => 'cached',
'directory|d' => 'd',
'l' => 'l',
'sort=s' => 'sort',
't' => sub { $_[0]->{_options}{sort} = 'time' },
'S' => sub { $_[0]->{_options}{sort} = 'size' },
'U' => sub { $_[0]->{_options}{sort} = 'none' },
'human-readable|h' => 'h',
'reverse|r' => 'r',
'time-style=s' => sub { $_[0]->set_time_style_option($_[2]) }
}, %opts);
$self->{_options}{d} = 1 if ($self->command_line == 0);
$self->{_options}{sort} //= 'name';
my $sortfun = $self->{_options}{d}
? \%sort_vaults : \%sort_archives;
$self->usage_error("unknown sort field")
unless exists($sortfun->{$self->{_options}{sort}});
$self->{_options}{sort} = $sortfun->{$self->{_options}{sort}};
return $self;
}
sub run {
my $self = shift;
if ($self->{_options}{d}) {
$self->list_vaults($self->get_vault_list($self->command_line));
} else {
$self->list_archives($self->get_vault_inventory($self->command_line));
}
}
sub get_vault_list {
my $self = shift;
my $glob = new App::Glacier::Glob(@_);
if ($glob->is_literal) {
return [$self->describe_vault(@_)];
} else {
my $res = $self->glacier->List_vaults();
if ($self->glacier->lasterr) {
$self->abend(EX_FAILURE, "can't list vaults: ",
$self->glacier->last_error_message);
}
return [map { timestamp_deserialize($_) }
$glob->filter(sub {
my ($x) = @_;
return $x->{VaultName}
}, @$res)];
}
}
sub list_vaults {
my ($self, $ref) = @_;
foreach my $v (defined($self->{_options}{sort})
( run in 1.008 second using v1.01-cache-2.11-cpan-800906f7e73 )