Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SymfonyCon 2013 Lightning Talk about the Consol...

SymfonyCon 2013 Lightning Talk about the Console in 2.5

Fabien Potencier

December 13, 2013
Tweet

More Decks by Fabien Potencier

Other Decks in Programming

Transcript

  1. select ask askConfirmation askHiddenResponse AskAndValidate askHiddenResponseAn dValidate a﬙empts Y Y

    Y Y hidden answer Y Y autocompleter Y Y validator Y Y Y default value Y Y Y Y yes/no Y choices Y
  2. $question->setValidator(function ($value) { if (!empty($value)) { return $value; } throw

    new \InvalidArgumentException( 'You need to provide a non-empty value.'); });
  3. $question = new ChoiceQuestion('Choose a color', array('red', 'blue'), 'blue'); $question->setMultiselect(true);

    $question->setPrompt(' > '); $question->setErrorMessage("That's not a valid color!");
  4. Better feedback when running external processes from a Console application

    https://secure.flickr.com/photos/petergorges/3052698754
  5. $callback = function ($type, $buffer) use ($output) { $output->write($buffer); };

    $process->run(OutputInterface::VERBOSITY_VERBOSE < $output- >getVerbosity() ? $callback : null);
  6. $callback = function ($type, $buffer) use ($output, &$startedOut, &$startedErr) {

    if ('err' === $type) { if (!$startedErr) { $output->write("\n<bg=red;fg=white> ERR </> "); $startedErr = true; $startedOut = false; } $output->write(str_replace("\n", "\n<bg=red;fg=white> ERR </> ", $buffer)); } else { if (!$startedOut) { $output->write("\n<bg=green;fg=white> OUT </> "); $startedOut = true; $startedErr = false; } $output->write(str_replace("\n", "\n<bg=green;fg=white> OUT </> ", $buffer)); } };
  7. $formatter = $this->getHelperSet()->get('debug_formatter'); // start a session $start = $formatter->start($uuid,

    $cmd); $output->write($start); // give some feedback $progress = $formatter->progress($uuid, $buffer, $isError); $output->write($progress); // at the end $stop = $formatter->stop($uuid, $message, $isSuccessful); $output->write($stop); 2.5