@@ -23,14 +23,23 @@ option application => (
23
23
doc => ' application name' ,
24
24
format => ' s' ,
25
25
format_doc => ' appname' ,
26
- required => 1 ,
26
+ required => 0 ,
27
27
spacer_before => 1,
28
28
);
29
29
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
+
30
39
option directory => (
31
40
is => ' ro' ,
32
41
short => ' d' ,
33
- doc => ' application directory (default: same as application name)' ,
42
+ doc => ' application/plugin directory (default: same as application/plugin name)' ,
34
43
format => ' s' ,
35
44
format_doc => ' directory' ,
36
45
required => 0,
@@ -39,11 +48,11 @@ option directory => (
39
48
40
49
# This was causing conflict with Path::Tiny's path(), so renaming to avoid
41
50
# the overhead of making Path::Tiny an object.
42
- option app_path => (
51
+ option output_path => (
43
52
is => ' ro' ,
44
- short => ' p ' ,
53
+ short => ' o ' ,
45
54
option => ' path' ,
46
- doc => ' application path (default: current directory)' ,
55
+ doc => ' output path (default: current directory)' ,
47
56
format => ' s' ,
48
57
format_doc => ' directory' ,
49
58
required => 0,
@@ -52,8 +61,8 @@ option app_path => (
52
61
53
62
option overwrite => (
54
63
is => ' ro' ,
55
- short => ' o ' ,
56
- doc => ' overwrite existing files' ,
64
+ short => ' f ' ,
65
+ doc => ' force overwrite of existing files' ,
57
66
required => 0,
58
67
default => 0,
59
68
);
@@ -122,6 +131,10 @@ has _engine => (
122
131
sub BUILD {
123
132
my ( $self , $args ) = @_ ;
124
133
134
+ $self -> osprey_usage( 1, qq{
135
+ Must provide wither an application name or plugin name.
136
+ } ) unless $self -> application || $self -> plugin;
137
+
125
138
$self -> osprey_usage( 1, qq{
126
139
Invalid application name. Application names must not contain single colons,
127
140
dots, hyphens or start with a number.
@@ -133,7 +146,7 @@ dots, hyphens or start with a number.
133
146
unless $scheme =~ / ^ git \@ .+ : .+ \. git $ | ^ http /x ;
134
147
}
135
148
136
- my $path = $self -> app_path ;
149
+ my $path = $self -> output_path ;
137
150
-d $path or $self -> osprey_usage( 1, " path: directory '$path ' does not exist" );
138
151
-w $path or $self -> osprey_usage( 1, " path: directory '$path ' is not writeable" );
139
152
@@ -148,16 +161,16 @@ sub run {
148
161
149
162
my $app_name = $self -> application;
150
163
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 );
152
165
153
166
if ( my $dir = $self -> directory ) {
154
- $app_path = path( $self -> app_path , $dir );
167
+ $output_path = path( $self -> output_path , $dir );
155
168
}
156
169
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 );
158
171
foreach my $pair ( @$files_to_copy ) {
159
172
if ( $pair -> [0] =~ m / lib\/ AppFile.pm$ / ) {
160
- $pair -> [1] = path( $app_path , $app_file );
173
+ $pair -> [1] = path( $output_path , $app_file );
161
174
last ;
162
175
}
163
176
}
@@ -169,9 +182,9 @@ sub run {
169
182
my $vars = {
170
183
appname => $app_name ,
171
184
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 ,
175
188
perl_interpreter => $self -> _get_perl_interpreter,
176
189
cleanfiles => $self -> _get_dashed_name( $app_name ),
177
190
dancer_version => $self -> parent_command-> _dancer2_version,
@@ -180,8 +193,8 @@ sub run {
180
193
181
194
$self -> _copy_templates( $files_to_copy , $vars , $self -> overwrite );
182
195
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 );
185
198
}
186
199
187
200
$self -> _check_git( $vars );
@@ -211,11 +224,11 @@ commands:
211
224
-x $git or die " Can't execute git: $! " ;
212
225
213
226
# my $dist_dir = $self->parent_command->_dist_dir;
214
- my $app_path = $vars -> { apppath };
227
+ my $output_path = $vars -> { apppath };
215
228
my $gitignore = path( $self -> parent_command-> _dist_dir, ' .gitignore' );
216
- path( $gitignore )-> copy( $app_path );
229
+ path( $gitignore )-> copy( $output_path );
217
230
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 : $! " ;
219
232
if ( _run_shell_cmd( ' git' , ' init' ) != 0 or
220
233
_run_shell_cmd( ' git' , ' add' , ' .' ) != 0 or
221
234
_run_shell_cmd( ' git' , ' commit' , " -m 'Initial commit of $app_name by Dancer2'" ) != 0 ) {
@@ -256,14 +269,14 @@ following commands:
256
269
sub _how_to_run {
257
270
my ( $self , $vars ) = @_ ;
258
271
259
- my $app_path = $vars -> { apppath };
272
+ my $output_path = $vars -> { apppath };
260
273
my $app_name = $vars -> { appname };
261
274
if ( $vars -> { docker } ) {
262
275
my $image = lc $app_name ;
263
276
print qq{
264
277
Your new application is ready! To run it:
265
278
266
- cd $app_path
279
+ cd $output_path
267
280
docker build -t ${image} .
268
281
docker run -d -p 5000:4000 --name $app_name ${image}
269
282
@@ -278,7 +291,7 @@ You may also run your app without Docker:
278
291
print " \n Your new application is ready! To run it:\n " ;
279
292
}
280
293
print qq{
281
- cd $app_path
294
+ cd $output_path
282
295
plackup bin/app.psgi
283
296
284
297
To access your application, point your browser to http://localhost:5000
@@ -396,7 +409,7 @@ sub _process_template {
396
409
397
410
# These are good candidates to move to Dancer2::CLI if other commands
398
411
# need them later.
399
- sub _get_app_path {
412
+ sub _get_output_path {
400
413
my ( $self , $path , $appname ) = @_ ;
401
414
return path( $path , $self -> _get_dashed_name( $appname ));
402
415
}
0 commit comments