logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

App::Cmd::Plugin::Prompt - plug prompting routines into your commands

Author

       Ricardo Signes <cpan@semiotic.systems>

Contributor

       Ricardo Signes <rjbs@semiotic.systems>

Name

       App::Cmd::Plugin::Prompt - plug prompting routines into your commands

Perl Version

       This library should run on perls released even a long time ago.  It should work on any version of perl
       released in the last five years.

       Although it may work on older versions of perl, no guarantee is made that the minimum required version
       will not be increased.  The version may be increased for any reason, and there is no promise that patches
       will be accepted to lower the minimum required perl.

See Also

       App::Cmd

Subroutines

prompt_str
         my $input = prompt_str($prompt, \%opt)

       This prompts a user for string input.  It can be directed to persist until input is 'acceptable'.

       Valid options are:

       •   input:  optional  coderef,  which, when invoked, returns the user's response; default is to read from
           STDIN.

       •   output:  optional  coderef,  which,  when  invoked  (with  two  arguments:   the   prompt   and   the
           choices/default), should prompt the user; default is to write to STDOUT.

       •   valid: an optional coderef which any input is passed into and which must return true in order for the
           program to continue

       •   default: may be any string; must pass the 'valid' coderef (if given)

       •   choices: what to display after the prompt; default is either the 'default' parameter or nothing

       •   no_valid_default: do not test the 'default' parameter against the 'valid' coderef

       •   invalid_default_error:  error  message  to  throw when the 'default' parameter is not valid (does not
           pass the 'valid' coderef)

   prompt_yn
         my $bool = prompt_yn($prompt, \%opt);

       This prompts the user for a yes or no response and won't give up until it gets one.  It returns true  for
       yes and false for no.

       Valid options are:

        default: may be yes or no, indicating how to interpret an empty response;
                 if empty, require an explicit answer; defaults to empty

   prompt_any_key($prompt)
         my $input = prompt_any_key($prompt);

       This  routine  prompts  the  user  to  "press any key to continue."  $prompt, if supplied, is the text to
       prompt with.

Synopsis

       In your app:

         package MyApp;
         use App::Cmd::Setup -app => {
           plugins => [ qw(Prompt) ],
         };

       In your command:

         package MyApp::Command::dostuff;
         use MyApp -command;

         sub run {
           my ($self, $opt, $args) = @_;

           return unless prompt_yn('really do stuff?', { default => 1 });

           ...
         }

Version

       version 1.006

See Also