App-Sqitch

 view release on metacpan or  search on metacpan

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

        target => $target->name,
    )) if @{ $targets };

    # Good to go.
    $self->target($target);
    my $engine = $target->engine;

    # Where are we?
    $self->comment( __x 'On database {db}', db => $engine->destination );

    # Exit with status 1 on no state, probably not expected.
    my $state = try {
        $engine->current_state( $self->project )
    } catch {
        # Just die on parse and I/O errors.
        die $_ if try { $_->ident eq 'parse' || $_->ident eq 'io' };

        # Hrm. Maybe not initialized?
        die $_ if $engine->initialized;
        hurl status => __x(
            'Database {db} has not been initialized for Sqitch',
            db => $engine->registry_destination
        );
    };

    hurl {
        ident   => 'status',
        message => __ 'No changes deployed',
        exitval => 1,
    } unless $state;

    # Emit the state basics.
    $self->emit_state($state);

    # Emit changes and tags, if required.
    $self->emit_changes;
    $self->emit_tags;

    my $plan_proj = try { $target->plan->project };
    if (defined $plan_proj && $self->project eq $plan_proj ) {
        $self->emit_status($state);
    } else {
        # If we have no access to the project plan, we can't emit the status.
        $self->comment('');
        $self->emit(__x(
            'Status unknown. Use --plan-file to assess "{project}" status',
            project => $self->project,
        ));
    }

    return $self;
}

sub configure {
    my ( $class, $config, $opt ) = @_;

    # Make sure the date format is valid.
    if (my $format = $opt->{date_format}
        || $config->get(key => 'status.date_format')
    ) {
        require App::Sqitch::DateTime;
        App::Sqitch::DateTime->validate_as_string_format($format);
    }

    # Set boolean options from config.
    for my $key (qw(show_changes show_tags)) {
        next if exists $opt->{$key};
        my $val = $config->get(key => "status.$key", as => 'bool') // next;
        $opt->{$key} = $val;
    }

    my $ret = $class->SUPER::configure( $config, $opt );
    $ret->{target_name} = delete $ret->{target} if exists $ret->{target};
    return $ret;
}

sub emit_state {
    my ( $self, $state ) = @_;
    $self->comment(__x(
        'Project:  {project}',
        project => $state->{project},
    ));
    $self->comment(__x(
        'Change:   {change_id}',
        change_id => $state->{change_id},
    ));
    $self->comment(__x(
        'Name:     {change}',
        change    => $state->{change},
    ));
    if (my @tags = @{ $state->{tags}} ) {
        $self->comment(__nx(
            'Tag:      {tags}',
            'Tags:     {tags}',
            @tags,
            tags => join(__ ', ', @tags),
        ));
    }

    $self->comment(__x(
        'Deployed: {date}',
        date => $state->{committed_at}->as_string(
            format => $self->date_format
        ),
    ));
    $self->comment(__x(
        'By:       {name} <{email}>',
        name => $state->{committer_name},
        email=> $state->{committer_email},
    ));
    return $self;
}

sub _all {
    my $iter = shift;
    my @res;
    while (my $row = $iter->()) {
        push @res => $row;
    }
    return \@res;
}



( run in 1.829 second using v1.01-cache-2.11-cpan-99c4e6809bf )