App-Sqitch

 view release on metacpan or  search on metacpan

lib/App/Sqitch/Command/show.pm  view on Meta::CPAN

package App::Sqitch::Command::show;

use 5.010;
use strict;
use warnings;
use utf8;
use Locale::TextDomain qw(App-Sqitch);
use App::Sqitch::X qw(hurl);
use List::Util qw(first);
use Moo;
use App::Sqitch::Types qw(Bool Str);

extends 'App::Sqitch::Command';
with 'App::Sqitch::Role::ContextCommand';

our $VERSION = 'v1.6.1'; # VERSION

has target => (
    is      => 'ro',
    isa     => Str,
);

has exists_only => (
    is       => 'ro',
    isa      => Bool,
    default  => 0,
);

sub options {
    return qw(
        target|t=s
        exists|e!
    );
}

sub configure {
    my ( $class, $config, $opt ) = @_;
    $opt->{exists_only} = delete $opt->{exists}
        if exists $opt->{exists};
    return $class->SUPER::configure( $config, $opt );
}

sub execute {
    my ( $self, $type, $key ) = @_;
    $self->usage unless $type && $key;

    require App::Sqitch::Target;
    my $target = $self->target ? App::Sqitch::Target->new(
        $self->target_params,
        name   => $self->target,
    ) : $self->default_target;
    my $plan = $target->plan;

    # Handle tags first.
    if ( $type eq 'tag' ) {
        my $is_id = $key =~ /^[0-9a-f]{40}/;
        my $change = $plan->get(
            $is_id ? $key : ($key =~ /^@/ ? '' : '@') . $key
        );

        my $tag = $change ? do {
            if ($is_id) {
                # It's a tag ID.
                first { $_->id eq $key } $change->tags;
            } else {
                # Tag name.
                (my $name = $key) =~ s/^[@]//;
                first { $_->name eq $name } $change->tags;
            }
        } : undef;
        unless ($tag) {
            return if $self->exists_only;
            hurl show => __x( 'Unknown tag "{tag}"', tag => $key );
        }
        $self->emit( $tag->info ) unless $self->exists_only;
        return $self;
    }

    # Make sure we recognize the type.
    hurl show => __x(
        'Unknown object type "{type}',
        type => $type,
    ) unless first { $type eq $_ } qw(change deploy revert verify);

    # Make sure we have a change object.
    my $change = $plan->get($key) or do {
        return if $self->exists_only;
        hurl show => __x(
            'Unknown change "{change}"',
            change => $key
        );
    };

    if ($type eq 'change') {
        # Just show its info.
        $self->emit( $change->info ) unless $self->exists_only;
        return $self;
    }

    my $meth = $change->can("$type\_file");



( run in 2.392 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )