diff --git a/lib/Mojolicious/Command/Author/generate.pm b/lib/Mojolicious/Command/Author/generate.pm index f129dc10c8..a3b14b43d4 100644 --- a/lib/Mojolicious/Command/Author/generate.pm +++ b/lib/Mojolicious/Command/Author/generate.pm @@ -25,7 +25,7 @@ Mojolicious::Command::Author::generate - Generator command Usage: APPLICATION generate GENERATOR [OPTIONS] mojo generate app - mojo generate lite_app + mojo generate lite-app =head1 DESCRIPTION diff --git a/lib/Mojolicious/Command/Author/generate/lite_app.pm b/lib/Mojolicious/Command/Author/generate/lite_app.pm index c8a5a13044..296b3372bc 100644 --- a/lib/Mojolicious/Command/Author/generate/lite_app.pm +++ b/lib/Mojolicious/Command/Author/generate/lite_app.pm @@ -20,10 +20,10 @@ Mojolicious::Command::Author::generate::lite_app - Lite app generator command =head1 SYNOPSIS - Usage: APPLICATION generate lite_app [OPTIONS] [NAME] + Usage: APPLICATION generate lite-app [OPTIONS] [NAME] - mojo generate lite_app - mojo generate lite_app foo.pl + mojo generate lite-app + mojo generate lite-app foo.pl Options: -h, --help Show this summary of available options diff --git a/lib/Mojolicious/Commands.pm b/lib/Mojolicious/Commands.pm index 8347f257ea..f9e8fd36a2 100644 --- a/lib/Mojolicious/Commands.pm +++ b/lib/Mojolicious/Commands.pm @@ -35,7 +35,8 @@ sub run { if (!$ENV{MOJO_NO_DETECT} && (my $env = $self->detect)) { $name = $env } # Run command - if ($name && $name =~ /^\w+$/ && ($name ne 'help' || $args[0])) { + if ($name && $name =~ /^\w[\w-]+$/ && ($name ne 'help' || $args[0])) { + $name =~ s/-/_/g; # Help $name = shift @args if my $help = $name eq 'help'; @@ -68,7 +69,12 @@ sub run { for grep { _command($_) } find_modules($ns), find_packages($ns); } - my @rows = map { [" $_", $all{$_}] } sort keys %all; + my @rows; + for my $class (sort keys %all) { + my $command = $class; + $command =~ s/(?message, tablify(\@rows), $self->hint; } @@ -106,7 +112,7 @@ Mojolicious::Commands - Command line interface Usage: APPLICATION COMMAND [OPTIONS] mojo version - mojo generate lite_app + mojo generate lite-app ./myapp.pl daemon -m production -l http://*:8080 ./myapp.pl get /foo ./myapp.pl routes -v @@ -177,9 +183,9 @@ List available options for generator command with short descriptions. Use L to generate application directory structure for a fully functional L application. -=head2 generate lite_app +=head2 generate lite-app - $ mojo generate lite_app + $ mojo generate lite-app Use L to generate a fully functional L application. diff --git a/lib/Mojolicious/Guides/Cookbook.pod b/lib/Mojolicious/Guides/Cookbook.pod index 8b623ea8ec..ef06efda4b 100644 --- a/lib/Mojolicious/Guides/Cookbook.pod +++ b/lib/Mojolicious/Guides/Cookbook.pod @@ -1797,7 +1797,7 @@ application to test something? Thanks to the command L you can do just that, the application object itself can be accessed via C. - $ mojo generate lite_app myapp.pl + $ mojo generate lite-app myapp.pl $ ./myapp.pl eval 'say for @{app->static->paths}' $ ./myapp.pl eval 'say for sort keys %{app->renderer->helpers}' diff --git a/lib/Mojolicious/Guides/Growing.pod b/lib/Mojolicious/Guides/Growing.pod index 41d1af24eb..4ce80292b8 100644 --- a/lib/Mojolicious/Guides/Growing.pod +++ b/lib/Mojolicious/Guides/Growing.pod @@ -167,7 +167,7 @@ Both application skeletons can be automatically generated with the commands L and L. - $ mojo generate lite_app myapp.pl + $ mojo generate lite-app myapp.pl $ mojo generate app MyApp Feature-wise both are almost equal, the only real differences are diff --git a/lib/Mojolicious/Guides/Tutorial.pod b/lib/Mojolicious/Guides/Tutorial.pod index d8e839166f..612adc262f 100644 --- a/lib/Mojolicious/Guides/Tutorial.pod +++ b/lib/Mojolicious/Guides/Tutorial.pod @@ -38,7 +38,7 @@ L, turning your script into a full featured web application. With L there is also a helper command to generate a small example application. - $ mojo generate lite_app myapp.pl + $ mojo generate lite-app myapp.pl =head2 Commands diff --git a/t/mojolicious/commands.t b/t/mojolicious/commands.t index 7c68f1a963..5d94a0dc84 100644 --- a/t/mojolicious/commands.t +++ b/t/mojolicious/commands.t @@ -71,18 +71,48 @@ is ref Mojolicious::Commands->new->run('psgi'), 'CODE', 'right reference'; 'right reference'; } -# Start application with application specific command +# Start application with application specific commands my $app; { local $ENV{MOJO_APP_LOADER} = 1; $app = Mojolicious::Commands->start_app('MojoliciousTest'); } -is $app->start('test_command'), 'works!', 'right result'; +is $app->start('test_command'), 'works!', 'right result'; +is $app->start('test-command'), 'works!', 'right result'; +is $app->start('_test2-command'), 'works 2!', 'right result'; { is(Mojolicious::Commands->start_app(MojoliciousTest => 'test_command'), 'works!', 'right result'); + is(Mojolicious::Commands->start_app(MojoliciousTest => 'test-command'), + 'works!', 'right result'); + is(Mojolicious::Commands->start_app(MojoliciousTest => '_test2-command'), + 'works 2!', 'right result'); } +# Application specific help +my $buffer = ''; +{ + open my $handle, '>', \$buffer; + local *STDOUT = $handle; + local $ENV{HARNESS_ACTIVE} = 0; + $app->start; +} +like $buffer, + qr/Usage: APPLICATION COMMAND \[OPTIONS\].*_test2-command.*cgi.*test-comm/s, + 'right output'; + +# Commands starting with a dash are not allowed +$buffer = ''; +{ + open my $handle, '>', \$buffer; + local *STDOUT = $handle; + local $ENV{HARNESS_ACTIVE} = 0; + $app->start('-test2-command'); +} +like $buffer, + qr/Usage: APPLICATION COMMAND \[OPTIONS\].*_test2-command.*cgi.*test-comm/s, + 'right output'; + # Do not pick up options for detected environments { local $ENV{MOJO_MODE}; @@ -99,7 +129,7 @@ is_deeply $commands->namespaces, ok $commands->description, 'has a description'; like $commands->message, qr/COMMAND/, 'has a message'; like $commands->hint, qr/help/, 'has a hint'; -my $buffer = ''; +$buffer = ''; { open my $handle, '>', \$buffer; local *STDOUT = $handle; @@ -107,19 +137,19 @@ my $buffer = ''; $commands->run; } like $buffer, - qr/Usage: APPLICATION COMMAND \[OPTIONS\].*daemon.*my_test_command.*version/s, + qr/Usage: APPLICATION COMMAND \[OPTIONS\].*daemon.*my-test-command.*version/s, 'right output'; like $buffer, qr/See, it works/, 'description has been picked up'; -unlike $buffer, qr/my_fake_test_command/, 'fake command has been ignored'; +unlike $buffer, qr/my-fake-test-command/, 'fake command has been ignored'; # help $buffer = ''; { open my $handle, '>', \$buffer; local *STDOUT = $handle; - $commands->run('help', 'generate', 'lite_app'); + $commands->run('help', 'generate', 'lite-app'); } -like $buffer, qr/Usage: APPLICATION generate lite_app \[OPTIONS\] \[NAME\]/, +like $buffer, qr/Usage: APPLICATION generate lite-app \[OPTIONS\] \[NAME\]/, 'right output'; $buffer = ''; { @@ -133,9 +163,9 @@ $buffer = ''; { open my $handle, '>', \$buffer; local *STDOUT = $handle; - $commands->run('generate', 'lite_app', '--help'); + $commands->run('generate', 'lite-app', '--help'); } -like $buffer, qr/Usage: APPLICATION generate lite_app \[OPTIONS\] \[NAME\]/, +like $buffer, qr/Usage: APPLICATION generate lite-app \[OPTIONS\] \[NAME\]/, 'right output'; # get @@ -245,7 +275,7 @@ $buffer = ''; $generator->run; } like $buffer, - qr/Usage: APPLICATION generate GENERATOR \[OPTIONS\].*lite_app.*plugin/s, + qr/Usage: APPLICATION generate GENERATOR \[OPTIONS\].*lite-app.*plugin/s, 'right output'; # generate app @@ -280,7 +310,7 @@ chdir $cwd; require Mojolicious::Command::Author::generate::lite_app; $app = Mojolicious::Command::Author::generate::lite_app->new; ok $app->description, 'has a description'; -like $app->usage, qr/lite_app/, 'has usage information'; +like $app->usage, qr/lite-app/, 'has usage information'; $dir = tempdir CLEANUP => 1; chdir $dir; $buffer = ''; diff --git a/t/mojolicious/lib/MojoliciousTest/Command/_test2_command.pm b/t/mojolicious/lib/MojoliciousTest/Command/_test2_command.pm new file mode 100644 index 0000000000..ba041e8640 --- /dev/null +++ b/t/mojolicious/lib/MojoliciousTest/Command/_test2_command.pm @@ -0,0 +1,6 @@ +package MojoliciousTest::Command::_test2_command; +use Mojo::Base 'Mojolicious::Command'; + +sub run {'works 2!'} + +1;