CloudHealth-CLI
view release on metacpan or search on metacpan
bin/cloudhealth view on Meta::CPAN
has argv_struct => (is => 'ro', lazy => 1, default => sub {
my $self = shift;
my @params = @{ $self->argv };
shift @params;
my $arg_parser = ARGV::Struct->new(argv => [ '{', @params, '}' ]);
return $arg_parser->parse;
});
has argv => (is => 'ro', isa => ArrayRef, required => 1);
has ch => (is => 'ro', lazy => 1, default => sub { CloudHealth::API->new });
has credentials_detected => (is => 'ro', isa => Bool, lazy => 1, default => sub {
my $self = shift;
$self->ch->credentials->is_set;
});
has run_method => (is => 'ro', isa => Maybe[Str], lazy => 1, default => sub { shift->argv->[0] });
has method_specified => (is => 'ro', isa => Bool, lazy => 1, default => sub {
my $self = shift;
defined $self->run_method;
});
has method_exists => (is => 'ro', isa => Bool, lazy => 1, default => sub {
my $self = shift;
bin/cloudhealth view on Meta::CPAN
});
has wants_help => (is => 'ro', isa => Bool, lazy => 1, default => sub {
my $self = shift;
return grep { lc($_) eq '--help' or lc($_) eq 'help' } @{ $self->argv };
});
sub usage {
my $self = shift;
say " * Didn't detect credentials. Set env CLOUDHEALTH_APIKEY" if (not $self->credentials_detected);
say " * Didn't specify the method to call" if (not $self->method_specified);
say sprintf(" * Don't know method %s", $self->run_method) if ($self->method_specified and not $self->method_exists);
if (not $self->method_specified or not $self->method_exists or $self->wants_help) {
say 'The following methods are available:';
foreach my $kind (sort keys %{ $self->ch->method_classification }) {
say $kind;
foreach my $method (sort @{ $self->ch->method_classification->{ $kind } }) {
say " $method"
}
}
bin/cloudhealth view on Meta::CPAN
say " $_" foreach (map { $_->{ name } } @{ $callinfo_class->_body_params });
}
}
say "Usage: $0 method param1 param1value param2 param2value";
return 1;
}
sub run {
my ($self) = shift;
return $self->usage if (not $self->credentials_detected);
return $self->usage if (not $self->method_specified);
return $self->usage if (not $self->method_exists);
return $self->usage if ($self->wants_help);
my $method = $self->run_method;
my $result = eval {
$self->ch->$method(%{ $self->argv_struct });
};
if ($@) {
say $@;
( run in 0.268 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )