Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions lib/Dancer2/CLI/Gen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ option skel => (
format_doc => 'directory',
required => 0,
default => sub{
my $self = shift;
path( $self->parent_command->_dist_dir, 'skel' );
my $self = shift;
path( $self->parent_command->_dist_dir, 'skel' );
},
);

Expand All @@ -95,7 +95,7 @@ option git => (
default => 0,
);

option remote => (
option remote => (
is => 'ro',
short => 'r',
doc => 'URI for git repository (implies -g)',
Expand All @@ -104,12 +104,19 @@ option remote => (
required => 0,
);

option no_package_files => (
is => 'ro',
doc => "don't create files needed for CPAN packaging",
required => 0,
default => 0,
);

# Last chance to validate args before we attempt to do something with them
sub BUILD {
my ( $self, $args ) = @_;

$self->osprey_usage( 1, qq{
Invalid application name. Application names must not contain single colons,
$self->osprey_usage( 1, qq{
Invalid application name. Application names must not contain single colons,
dots, hyphens or start with a number.
}) unless is_module_name( $self->application );

Expand Down Expand Up @@ -165,8 +172,10 @@ sub run {
};

$self->_copy_templates( $files_to_copy, $vars, $self->overwrite );
$self->_create_manifest( $files_to_copy, $app_path );
$self->_add_to_manifest_skip( $app_path);
unless( $self->no_package_files ) {
$self->_create_manifest( $files_to_copy, $app_path );
$self->_add_to_manifest_skip( $app_path );
}

$self->_check_git( $vars );
$self->_check_yaml;
Expand All @@ -183,7 +192,7 @@ sub _check_git {

WARNING: Couldn't initialize a git repo despite being asked to do so.

To resolve this, cd to your application directory and run the following
To resolve this, cd to your application directory and run the following
commands:

git init
Expand All @@ -200,13 +209,13 @@ commands:
path( $gitignore )->copy( $app_path );

chdir File::Spec->rel2abs( $app_path ) or die "Can't cd to $app_path: $!";
if( _run_shell_cmd( 'git', 'init') != 0 or
_run_shell_cmd( 'git', 'add', '.') != 0 or
if( _run_shell_cmd( 'git', 'init') != 0 or
_run_shell_cmd( 'git', 'add', '.') != 0 or
_run_shell_cmd( 'git', 'commit', "-m 'Initial commit of $app_name by Dancer2'" ) != 0 ) {
print $git_error;
}
else {
if( $self->remote &&
if( $self->remote &&
_run_shell_cmd( 'git', 'remote', 'add', 'origin', $self->remote ) != 0 ) {
print $git_error;
print " git remote add origin " . $self->remote . "\n";
Expand Down Expand Up @@ -290,7 +299,7 @@ sub _build_file_list {
warn "File not found: $file" unless $file->exists; # Paranoia
next if $file->basename =~ m{^\.git(/|$)};
next if $file->is_dir;

my $filename = $file->relative( $from );
push @result, [ $file, path( $to, $filename )];
}
Expand All @@ -302,6 +311,9 @@ sub _copy_templates {

foreach my $pair (@$files) {
my ( $from, $to ) = @{$pair};
next if $self->no_package_files && $from =~ /MANIFEST\.SKIP$/;
next if $self->no_package_files && $from =~ /Makefile.PL$/;

if ( -f $to && !$overwrite ) {
print "! $to exists, overwrite? (or rerun this command with -o) [N/y/a]: ";
my $res = <STDIN>; chomp($res);
Expand All @@ -315,7 +327,7 @@ sub _copy_templates {
$to_dir->mkpath;
}

# Skeleton files whose names are prefixed with + need to be executable, but we must strip
# Skeleton files whose names are prefixed with + need to be executable, but we must strip
# that from the name when copying them
my $to_file = path( $to )->basename;
my $ex = ( $to_file =~ s/^\+// );
Expand Down Expand Up @@ -378,7 +390,7 @@ sub _process_template {
return $engine->render( \$template, $tokens );
}

# These are good candidates to move to Dancer2::CLI if other commands
# These are good candidates to move to Dancer2::CLI if other commands
# need them later.
sub _get_app_path {
my ( $self, $path, $appname ) = @_;
Expand Down Expand Up @@ -431,8 +443,8 @@ sub _run_shell_cmd {

my $exit_status = try {
my $pid = IPC::Open3::open3(
my $stdin,
my $stdout,
my $stdin,
my $stdout,
my $stderr = Symbol::gensym,
@cmds,
);
Expand Down