Gorm asks the questions

Exercise 3 of 6 in chapter 11 · 270 XP · 5 objectives checked by tests

Topics covered: Interactive mode#[Ask]#[Interact]$io->choice()$io->confirm()--no-interaction

Gorm wants to add dishes from the command line too. But he never remembers the order of the arguments, nor the exact names of the categories. He would like to type app:plat:ajouter, and nothing else, and have the command ask him the questions.

Interactive mode

A command meant for a human can ask for what it is missing:

The same command must remain usable by a script. With --no-interaction (-n), no question is asked, and the confirmations take their default value.

Your mission

Make app:plat:ajouter interactive:

  1. without arguments, it asks Dish name?, Its price, in gold pieces?, then Which category?, to be picked from the menu's list;
  2. an answer that is not in the list is rejected, and the question asked again;
  3. before writing, it asks Add "Blackberry Tart" (4.50 gp, Desserts) to the menu?. If Gorm answers no: Nothing was added., and nothing is saved;
  4. what is already given as an argument or an option is not asked again;
  5. a price that is not a number is rejected (The price is a number…, validator unPrix = a price); “4,5” with a comma is accepted too.

In the preview console

The browser console runs like a script, with nobody there to answer: it never asks questions. Try the non-interactive mode there, with all the arguments. The tests are the ones answering the questions, with CommandTester::setInputs(), exactly the way you test an interactive command in a real project.