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