예제 #1
0
 private function runInteractiveSession()
 {
     pake_import('interactive');
     pake_echo("=================================================================================");
     pake_echo("Welcome to pake's interactive console. To get list of commands type \"?\" or \"help\"");
     pake_echo("type \"quit\" or press ^D to exit");
     pake_echo("=================================================================================");
     $this->showVersion();
     echo "\n";
     while (true) {
         $command = pakeInput::getString('pake> ', false);
         if (false === $command) {
             // Ctrl-D
             pakeInteractiveTask::run_quit_pake();
         }
         if ('' === $command) {
             continue;
         }
         $this->initAndRunTaskInSubprocess($command);
     }
 }
예제 #2
0
function pake_select_input($question, array $options, $default = null)
{
    if (null !== $default) {
        if (!is_numeric($default)) {
            throw new UnexpectedValueException("Default is specified, but is not numeric");
        }
        if (!isset($options[$default])) {
            throw new UnexpectedValueException("Default is specified, but it is not one of options");
        }
    }
    pake_echo($question);
    $i = 1;
    $options_strs = array();
    foreach ($options as $option) {
        $options_strs[] = '(' . $i++ . ') ' . $option;
    }
    pake_echo('  ' . implode("\n  ", $options_strs));
    while (true) {
        if (null === $default) {
            $prompt = '[>] ';
        } else {
            $prompt = '[> default="' . ($default + 1) . '"] ';
        }
        $retval = pakeInput::getString($prompt);
        if ('' === $retval) {
            if (null === $default) {
                continue;
            }
            $retval = $options[$default];
        } else {
            if (!is_numeric($retval)) {
                pake_echo_error("Just enter number");
                continue;
            }
            if (!isset($options[$retval - 1])) {
                pake_echo_error("There is no option " . $retval);
                continue;
            }
            $retval = $options[$retval - 1];
        }
        break;
    }
    return $retval;
}