mnapoli / silly

Silly CLI micro-framework based on Symfony Console
MIT License
922 stars 52 forks source link

private -> protected accessibility for overloading #31

Closed bpacholek closed 8 years ago

bpacholek commented 8 years ago

In order to develop Single command applications it is required to use the defaultCommand. To do we need to overload the ExpressionParser. In the method parse we need to disable the line:

$name = array_shift($tokens);

and later passing of the name:

        return [
        //    'name' => $name,
            'arguments' => $arguments,
            'options' => $options,
        ];

There would be no problem in that, but since methods like parseOption, startsWith (etc.) are private it is required to repeat them in the child class. Having them protected would allow use of inheritance:

class SingleCommandExpressionParser extends ExpressionParser

Going further, we need to update the method createCommand, but we also need to overload command as it calls createCommand of the parent scope if not overloaded. If overloaded then we need to repeat assertCallableIsValid (etc.) again to be accessible.

mnapoli commented 8 years ago

I'm not a huge fan of this change, I'm having trouble understanding why it's necessary to change everything to protected. Can the SingleCommandApplication take the command in its constructor? If so, do we still need to overload everything? Make with an example it would be clearer.

bpacholek commented 8 years ago

Another option would be to detect if command name was parsed in the constructor and modify both expression parser and commands to behave differently then, right.

Will provide a new PR.