App-Critique

 view release on metacpan or  search on metacpan

lib/App/Critique/Command/process.pm  view on Meta::CPAN

package App::Critique::Command::process;

use strict;
use warnings;

our $VERSION   = '0.05';
our $AUTHORITY = 'cpan:STEVAN';

use Path::Tiny      ();
use List::Util      ();
use Term::ANSIColor ':constants';

use App::Critique::Session;

use App::Critique -command;

sub opt_spec {
    my ($class) = @_;
    return (
        [ 'reset',  'resets the file index to 0',            { default => 0 } ],
        [ 'back',   'back up and re-process the last file',  { default => 0 } ],
        [ 'next',   'skip over processing the current file', { default => 0 } ],
        [ 'goto=i', 'goto to file at given index' ],
        [],
        [ 'blame', 'show the `git blame` block for each violation', { default => 0 } ],
        [],
        $class->SUPER::opt_spec
    );
}

sub execute {
    my ($self, $opt, $args) = @_;

    error('No acceptable value found for EDITOR in the critique config, please set one.')
        unless $App::Critique::CONFIG{EDITOR};

    local $Term::ANSIColor::AUTORESET = 1;

    my $session = $self->cautiously_load_session( $opt, $args );

    info('Session file loaded.');

    # TODO:
    # check to see if there are changes in the
    # working directory, if so, exit with an
    # error.

    # TODO:
    # add a new flag that will look at the last
    # commit and assuming it included the current
    # file, add the SHA to the session data (with a
    # special note saying it was commited manually)

    my @tracked_files = $session->tracked_files;

    # TODO:
    # not all these options can be given together, so
    # we should do some validation for that.
    # - SL

    if ( $opt->back ) {
        $session->dec_file_idx;
        $tracked_files[ $session->current_file_idx ]->forget_all;
    }

    if ( $opt->next ) {
        $session->inc_file_idx;
    }

    if ( $opt->reset ) {
        $session->reset_file_idx;
        $_->forget_all foreach @tracked_files;
    }

    if ( my $idx = $opt->goto ) {
        $session->set_file_idx( $idx );
    }

    if ( $session->current_file_idx == scalar @tracked_files ) {
        info(HR_DARK);
        info('All files have already been processed.');
        info(HR_LIGHT);
        info('- run `critique status` to see more information');
        info('- run `critique process --reset` to review all files again');
        info(HR_DARK);
        return;
    }



( run in 0.487 second using v1.01-cache-2.11-cpan-5735350b133 )