package Sietima::CmdLine;
use Moo;
use Sietima::Policy;
use Sietima::Types qw(SietimaObj);
use Types::Standard qw(HashRef);
use Sietima;
use App::Spec;
use Sietima::Runner;
use namespace::clean;
has sietima => (
is => 'ro',
required => 1,
isa => SietimaObj,
);
has extra_spec => (
is => 'ro',
isa => HashRef,
default => sub { +{} },
);
sub BUILDARGS($class,@args) {
my $args = $class->next::method(@args);
$args->{sietima} //= do {
my $traits = delete $args->{traits} // [];
my $constructor_args = delete $args->{args} // {};
Sietima->with_traits($traits->@*)->new($constructor_args);
};
return $args;
}
has app_spec => (
is => 'lazy',
init_arg => undef,
);
sub _build_app_spec($self) {
my $spec_data = $self->sietima->command_line_spec();
return App::Spec->read({
$spec_data->%*,
$self->extra_spec->%*,
});
}
has runner => (
is => 'lazy',
init_arg => undef,
handles => [qw(run)],
);
sub _build_runner($self) {
return Sietima::Runner->new({
spec => $self->app_spec,
cmd => $self->sietima,
class => ref($self->sietima),
});
}
1;