Skip to content

Commit 4dbb412

Browse files
committed
WIP
1 parent b597707 commit 4dbb412

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

lib/Dancer2/CLI/Gen.pm

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,23 @@ option application => (
2323
doc => 'application name',
2424
format => 's',
2525
format_doc => 'appname',
26-
required => 1,
26+
required => 0,
2727
spacer_before => 1,
2828
);
2929

30+
option plugin => (
31+
is => 'ro',
32+
short => 'p',
33+
doc => 'plugin name',
34+
format => 's',
35+
format_doc => 'plugin',
36+
required => 0,
37+
);
38+
3039
option directory => (
3140
is => 'ro',
3241
short => 'd',
33-
doc => 'application directory (default: same as application name)',
42+
doc => 'application/plugin directory (default: same as application/plugin name)',
3443
format => 's',
3544
format_doc => 'directory',
3645
required => 0,
@@ -39,11 +48,11 @@ option directory => (
3948

4049
# This was causing conflict with Path::Tiny's path(), so renaming to avoid
4150
# the overhead of making Path::Tiny an object.
42-
option app_path => (
51+
option output_path => (
4352
is => 'ro',
44-
short => 'p',
53+
short => 'o',
4554
option => 'path',
46-
doc => 'application path (default: current directory)',
55+
doc => 'output path (default: current directory)',
4756
format => 's',
4857
format_doc => 'directory',
4958
required => 0,
@@ -52,8 +61,8 @@ option app_path => (
5261

5362
option overwrite => (
5463
is => 'ro',
55-
short => 'o',
56-
doc => 'overwrite existing files',
64+
short => 'f',
65+
doc => 'force overwrite of existing files',
5766
required => 0,
5867
default => 0,
5968
);
@@ -122,6 +131,10 @@ has _engine => (
122131
sub BUILD {
123132
my ( $self, $args ) = @_;
124133

134+
$self->osprey_usage( 1, qq{
135+
Must provide wither an application name or plugin name.
136+
} ) unless $self->application || $self->plugin;
137+
125138
$self->osprey_usage( 1, qq{
126139
Invalid application name. Application names must not contain single colons,
127140
dots, hyphens or start with a number.
@@ -133,7 +146,7 @@ dots, hyphens or start with a number.
133146
unless $scheme =~ / ^ git \@ .+ : .+ \.git $ | ^ http /x;
134147
}
135148

136-
my $path = $self->app_path;
149+
my $path = $self->output_path;
137150
-d $path or $self->osprey_usage( 1, "path: directory '$path' does not exist" );
138151
-w $path or $self->osprey_usage( 1, "path: directory '$path' is not writeable" );
139152

@@ -148,16 +161,16 @@ sub run {
148161

149162
my $app_name = $self->application;
150163
my $app_file = $self->_get_app_file( $app_name );
151-
my $app_path = $self->_get_app_path( $self->app_path, $app_name );
164+
my $output_path = $self->_get_output_path( $self->output_path, $app_name );
152165

153166
if( my $dir = $self->directory ) {
154-
$app_path = path( $self->app_path, $dir );
167+
$output_path = path( $self->output_path, $dir );
155168
}
156169

157-
my $files_to_copy = $self->_build_file_list( $self->skel, $app_path );
170+
my $files_to_copy = $self->_build_file_list( $self->skel, $output_path );
158171
foreach my $pair( @$files_to_copy ) {
159172
if( $pair->[0] =~ m/lib\/AppFile.pm$/ ) {
160-
$pair->[1] = path( $app_path, $app_file );
173+
$pair->[1] = path( $output_path, $app_file );
161174
last;
162175
}
163176
}
@@ -169,9 +182,9 @@ sub run {
169182
my $vars = {
170183
appname => $app_name,
171184
appfile => $app_file->stringify,
172-
apppath => $app_path,
173-
appdir => File::Spec->rel2abs( $app_path ),
174-
apppath => $app_path,
185+
apppath => $output_path,
186+
appdir => File::Spec->rel2abs( $output_path ),
187+
apppath => $output_path,
175188
perl_interpreter => $self->_get_perl_interpreter,
176189
cleanfiles => $self->_get_dashed_name( $app_name ),
177190
dancer_version => $self->parent_command->_dancer2_version,
@@ -180,8 +193,8 @@ sub run {
180193

181194
$self->_copy_templates( $files_to_copy, $vars, $self->overwrite );
182195
unless( $self->no_package_files ) {
183-
$self->_create_manifest( $files_to_copy, $app_path );
184-
$self->_add_to_manifest_skip( $app_path );
196+
$self->_create_manifest( $files_to_copy, $output_path );
197+
$self->_add_to_manifest_skip( $output_path );
185198
}
186199

187200
$self->_check_git( $vars );
@@ -211,11 +224,11 @@ commands:
211224
-x $git or die "Can't execute git: $!";
212225

213226
#my $dist_dir = $self->parent_command->_dist_dir;
214-
my $app_path = $vars->{ apppath };
227+
my $output_path = $vars->{ apppath };
215228
my $gitignore = path( $self->parent_command->_dist_dir, '.gitignore' );
216-
path( $gitignore )->copy( $app_path );
229+
path( $gitignore )->copy( $output_path );
217230

218-
chdir File::Spec->rel2abs( $app_path ) or die "Can't cd to $app_path: $!";
231+
chdir File::Spec->rel2abs( $output_path ) or die "Can't cd to $output_path: $!";
219232
if( _run_shell_cmd( 'git', 'init') != 0 or
220233
_run_shell_cmd( 'git', 'add', '.') != 0 or
221234
_run_shell_cmd( 'git', 'commit', "-m 'Initial commit of $app_name by Dancer2'" ) != 0 ) {
@@ -256,14 +269,14 @@ following commands:
256269
sub _how_to_run {
257270
my( $self, $vars ) = @_;
258271

259-
my $app_path = $vars->{ apppath };
272+
my $output_path = $vars->{ apppath };
260273
my $app_name = $vars->{ appname };
261274
if( $vars->{ docker } ) {
262275
my $image = lc $app_name;
263276
print qq{
264277
Your new application is ready! To run it:
265278
266-
cd $app_path
279+
cd $output_path
267280
docker build -t ${image} .
268281
docker run -d -p 5000:4000 --name $app_name ${image}
269282
@@ -278,7 +291,7 @@ You may also run your app without Docker:
278291
print "\nYour new application is ready! To run it:\n";
279292
}
280293
print qq{
281-
cd $app_path
294+
cd $output_path
282295
plackup bin/app.psgi
283296
284297
To access your application, point your browser to http://localhost:5000
@@ -396,7 +409,7 @@ sub _process_template {
396409

397410
# These are good candidates to move to Dancer2::CLI if other commands
398411
# need them later.
399-
sub _get_app_path {
412+
sub _get_output_path {
400413
my ( $self, $path, $appname ) = @_;
401414
return path( $path, $self->_get_dashed_name( $appname ));
402415
}

0 commit comments

Comments
 (0)