| 1 | package Imager::CommandLine::AllImages { | ||
| 2 | use MooseX::App; | ||
| 3 | use ARGV::Struct; | ||
| 4 | use CloudDeploy::AMIDB; | ||
| 5 | use CloudDeploy::Config; | ||
| 6 | use v5.10; | ||
| 7 | use Moose::Util::TypeConstraints; | ||
| 8 | use Imager::TabularDisplay; | ||
| 9 | |||
| 10 | has find_args => ( | ||
| 11 | is => 'ro', | ||
| 12 | isa => 'HashRef[Str]', | ||
| 13 | lazy => 1, | ||
| 14 | default => sub { | ||
| 15 | my $self = shift; | ||
| 16 | return ARGV::Struct->new(argv => [ '{', @{ $self->extra_argv }, '}' ])->parse; | ||
| 17 | } | ||
| 18 | ); | ||
| 19 | |||
| 20 | option cols => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => 'Str', | ||
| 23 | documentation => 'List of comma-separated names of columns to display', | ||
| 24 | default => 'Account,Name,Version,ImageId,Tags,Date,Type,Arch,Root' | ||
| 25 | ); | ||
| 26 | |||
| 27 | has _cols => ( | ||
| 28 | is => 'ro', | ||
| 29 | isa => 'ArrayRef[Str]', | ||
| 30 | lazy => 1, | ||
| 31 | default => sub { [ split /,/,shift->cols ] } | ||
| 32 | ); | ||
| 33 | |||
| 34 | sub run { | ||
| 35 | my ($self) = @_; | ||
| 36 | |||
| 37 | my $search = CloudDeploy::AMIDB->new; | ||
| 38 | |||
| 39 | my %criterion = %{ $self->find_args }; | ||
| 40 | |||
| 41 | my @res = $search->search(%criterion); | ||
| 42 | |||
| 43 | my @cols = @{ $self->_cols }; | ||
| 44 | |||
| 45 | Imager::TabularDisplay::print_table(\@cols, \@res); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; | ||
| 50 |