byrokrat / giroapp

Command line app for managing autogiro donations.
GNU General Public License v3.0
4 stars 2 forks source link

Refactor commands that read options #56

Closed hanneskod closed 7 years ago

hanneskod commented 7 years ago

We want InitCommand, AddCommand, EditCommand and maybe more to read options and/or interactively ask for user input. Requirements:

Can be solved using an OptionReader (injected at construct) with the following interface:

OptionReader::readOption(string $nameOfOption, callable $optionalFilter = null): mixed;

Where $optionalFilter can be used to process input (eg. create the account number object) and throw exceptions on invalid input (catching exceptions can trigger re-asks in interactive mode).

InteractiveOptionReader as a subclass of OptionReader. Choose implementation at setup in DIC.

It should for example be possible to do this

$this->donorBuilder->setAccount(
    $this->optionReader->readOption('account', [$this->accountFactory, 'createAccount'])
);

We also need to pass a description phrase to display in interactive mode when asking questions ("please write a valid account number...").

As a last touch option names and descriptions should be saved in some kind of tabular way so that the same phrases are not to be written in both configure() and execute().

hanneskod commented 7 years ago

A lot of this is supported natively in the question helper..

See http://symfony.com/doc/current/components/console/helpers/questionhelper.html