App-Critique
view release on metacpan or search on metacpan
lib/App/Critique/Command/init.pm view on Meta::CPAN
package App::Critique::Command::init;
use strict;
use warnings;
our $VERSION = '0.05';
our $AUTHORITY = 'cpan:STEVAN';
use App::Critique::Session;
use App::Critique -command;
sub opt_spec {
my ($class) = @_;
return (
[ 'perl-critic-profile=s', 'path to a Perl::Critic profile to use (default let Perl::Critic decide)' ],
[ 'perl-critic-theme=s', 'Perl::Critic theme expression to use' ],
[ 'perl-critic-policy=s', 'singular Perl::Critic policy to use (overrides -theme and -policy)' ],
[],
[ 'force', 'force overwriting of existing session file' ],
[],
$class->SUPER::opt_spec,
)
}
sub execute {
my ($self, $opt, $args) = @_;
if ( $opt->verbose ) {
info(HR_LIGHT);
info('Attempting to initialize session file using the following options:');
info(HR_LIGHT);
info(' --perl-critic-profile = %s', $opt->perl_critic_profile // '[...]');
info(' --perl-critic-theme = %s', $opt->perl_critic_theme // '[...]');
info(' --perl-critic-policy = %s', $opt->perl_critic_policy // '[...]');
}
else {
info('Attempting to initialize session file ...');
}
my $session = App::Critique::Session->new(
perl_critic_profile => $opt->perl_critic_profile,
perl_critic_theme => $opt->perl_critic_theme,
perl_critic_policy => $opt->perl_critic_policy,
git_work_tree => $opt->git_work_tree,
);
if ( $opt->verbose ) {
info(HR_LIGHT);
info('Successuflly created session with the following configuration:');
info(HR_LIGHT);
info(' perl_critic_profile = %s', $session->perl_critic_profile // '[...]');
info(' perl_critic_theme = %s', $session->perl_critic_theme // '[...]');
info(' perl_critic_policy = %s', $session->perl_critic_policy // '[...]');
info(' git_work_tree = %s', $session->git_work_tree );
info(' git_work_tree_root = %s', $session->git_work_tree_root );
info(' git_branch = %s', $session->git_branch );
info(' git_HEAD_sha = %s', $session->git_head_sha );
info(HR_LIGHT);
}
else {
info('Successuflly created session.');
}
if ( $session->session_file_exists ) {
my $session_file_path = $session->session_file_path;
if ( $opt->force ) {
warning('Overwriting session file (%s) with --force option.', $session_file_path);
}
else {
error(
'Unable to overwrite session file (%s) without --force option.',
$session_file_path
);
}
}
( run in 2.668 seconds using v1.01-cache-2.11-cpan-d8267643d1d )