NAME
Mojo::Console - Extend Mojolicious::Command to be able to ask for things from command line
SYNOPSIS
package MyApp::Command::helloworld;
use Mojo::Base 'Mojo::Console';
sub run {
my $self = shift;
my $name = $self->ask('What is your name?');
my $gender = $self->choice('Are you a male or a female?', ['male', 'female']);
my $bool = $self->confirm("Do you have a cat?");
$self->line("Hi $name\n");
$self->line("We found out that you are a $gender ");
if ($bool) {
$self->line("and you have a cat");
} else {
$self->line("and you don't have a cat");
}
if ($self->confirm("Would you like an icecream?")) {
$self->success("Thanks");
} else {
$self->error("Oh no!");
}
$self->info("You got here because you took an icecream");
}
1;
DESCRIPTION
Mojo::Console is an extension of Mojolicious::Command
ATTRIBUTES
Mojo::Console inherits all attributes from Mojolicious::Command.
METHODS
Mojo::Console inherits all methods from Mojolicious::Command and implements the following new ones.
ask
my $answer = $self->ask('What is your name?');
my $required_answer = $self->ask('What is your name?', 1); # this will ask for an answer maximum 10 times and will exit in case the answer is empty
confirm
my $bool = $self->confirm("Are you sure?");
my $bool_with_default_answer = $self->confirm("Are you sure?", 'yes');
choice
my $choice = $self->choice('Are you a male or a female?', ['male', 'female']);
my $choice_with_default_answer = $self->choice('Are you a male or a female?', ['male', 'female'], 'male');
error
$self->error("The program will stop here");
info
$self->info("This is just an info message");
line
$self->line("This message will not have a new line at the end");
newline
$self->line("This message will have a new line at the end");
success
$self->success("This is just a success message");
warn
$self->success("This is just a warning message");
SEE ALSO
Mojolicious::Command, Mojolicious, Mojolicious::Guides, https://mojolicious.org.