| 1 | package Imager::CommandLine::AccountImages { | ||
| 2 | use MooseX::App; | ||
| 3 | use ARGV::Struct; | ||
| 4 | use CloudDeploy::AMIDB; | ||
| 5 | use CloudDeploy::Config; | ||
| 6 | use Imager::TabularDisplay; | ||
| 7 | use v5.10; | ||
| 8 | use Moose::Util::TypeConstraints; | ||
| 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,Region,Name,ImageId,Tags,Date' | ||
| 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 | if (not defined $criterion{Account}){ | ||
| 41 | $criterion{Account} = CloudDeploy::Config->new->account; | ||
| 42 | } elsif ($criterion{Account} eq '-') { | ||
| 43 | # list for all accounts | ||
| 44 | delete $criterion{Account}; | ||
| 45 | } | ||
| 46 | |||
| 47 | my @res = $search->search(%criterion); | ||
| 48 | |||
| 49 | my @cols = @{ $self->_cols }; | ||
| 50 | |||
| 51 | Imager::TabularDisplay::print_table(\@cols, \@res); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 |