App-Sqitch
view release on metacpan or search on metacpan
lib/App/Sqitch/Command/init.pm view on Meta::CPAN
package App::Sqitch::Command::init;
use 5.010;
use strict;
use warnings;
use utf8;
use Moo;
use App::Sqitch::Types qw(URI Maybe);
use Locale::TextDomain qw(App-Sqitch);
use App::Sqitch::X qw(hurl);
use List::MoreUtils qw(natatime);
use Path::Class;
use App::Sqitch::Plan;
use namespace::autoclean;
use constant extra_target_keys => qw(engine target);
extends 'App::Sqitch::Command';
with 'App::Sqitch::Role::TargetConfigCommand';
our $VERSION = 'v1.6.1'; # VERSION
sub execute {
my ( $self, $project ) = @_;
$self->_validate_project($project);
$self->write_config;
my $target = $self->config_target;
$self->write_plan(
project => $project,
uri => $self->uri,
target => $target,
);
$self->make_directories_for($target);
return $self;
}
has uri => (
is => 'ro',
isa => Maybe[URI],
);
sub options {
return qw(uri=s);
}
sub _validate_project {
my ( $self, $project ) = @_;
$self->usage unless $project;
my $name_re = 'App::Sqitch::Plan'->name_regex;
hurl init => __x(
qq{invalid project name "{project}": project names must not }
. 'begin with punctuation, contain "@", ":", "#", "[", "]", or blanks, or end in '
. 'punctuation or digits following punctuation',
project => $project
) unless $project =~ /\A$name_re\z/;
}
sub configure {
my ( $class, $config, $opt ) = @_;
if ( my $uri = $opt->{uri} ) {
require URI;
$opt->{uri} = 'URI'->new($uri);
}
return $opt;
}
sub write_config {
my $self = shift;
my $sqitch = $self->sqitch;
my $config = $sqitch->config;
my $file = $config->local_file;
if ( -f $file ) {
( run in 0.564 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )