Adding prompts to admin:user:create cli command#2690
Adding prompts to admin:user:create cli command#2690steverobbins wants to merge 2 commits intomagento:developfrom
Conversation
|
Thank you for the PR! We are currently waiting for the travis builds to work again, which should happen in a few days. Once that is running and the tests are green we can continue to process your contribution. |
There was a problem hiding this comment.
getOption() verified that such option is supported and that it is set. Accessing it directly in the array can be risky because there is no guarantee that such key exists. I'd suggest to add some validation for all such cases. Maybe a new private method can be dedicated to it.
There was a problem hiding this comment.
At this point of execution it is guaranteed that this key exists in the array. It has gone through the optional prompting step and has been validated with addUserInfoRules().
There was a problem hiding this comment.
I'm not totally against this approach in this particular case, so I'm ok, if it will be as is.
Just, in general, I'd prefer to not rely on internal logic of a method, but rather rely on the interface/signature. Even, if it is in the same class. Sometimes, it may happen that different developers touch the code and they may miss usage of data returned by a method.
Also, in this case, the method is protected, which means that it's behavior may be modified (close to 0 chance in this particular case, but I'm saying in general).
Again, it's ok to leave it as is in this case.
90f50b2 to
fbd3313
Compare
|
@buskamuza I've addressed two of your comments in an update commit. |
|
@steverobbins , thanks for the update! I hope, we'll merge the PR soon. |
|
@steverobbins Please merge latest from develop and rerun builds. |
|
Hello @steverobbins, would be nice to add tescase into setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php according to your changes. Thank you. |
99d1c88 to
91f93d1
Compare
|
Rebased on develop. Looks like there are some issues with the |
|
Internal ticket - MAGETWO-49808. |
There was a problem hiding this comment.
I do not think we can change the signature of this method.
There was a problem hiding this comment.
We can do anything if we set our minds to it 😛
Yes, I'm having a rethink on my implementation that will also address @buskamuza's array access comment.
|
Still working through this (see latest commit), but it's turning into a much bigger thing that I'm not sure you'll accept. In order to keep the signature of the This seems to work in practice but there's still work to do due to how |
|
@steverobbins you are right, this is significant change. Looks like we have no good way how to implement user interaction now. Let us discuss this internally. |
|
@steverobbins can you please merge this PR with the latest develop? Going to work on accepting it. |
0d2ee5f to
7e07366
Compare
|
@vrann Squashed and rebased... Let's see if tests still pass a year later 😟 |
|
@steverobbins you have couple failures. Also adding one comment to the code |
| ]; | ||
| foreach ($keys as $key) { | ||
| if (!$input->getOption($key)) { | ||
| $input->promptForOption($dialog, $output, $key, $key === AdminAccount::KEY_PASSWORD); |
There was a problem hiding this comment.
Please check that input actually implements the interface which has promptForOption method
| */ | ||
| protected function setMissingValues(InputInterface &$input, OutputInterface $output) | ||
| { | ||
| if (!method_exists($input, 'promptForOption')) { |
There was a problem hiding this comment.
sorry for not being more specific earlier, but better way to achieve this is to introduce new interface, i.e. InputInteractiveInterface, which extends InputInterface. Then here either check is $input an instance of this interface or even better do type hinting to InputInteractiveInterface in the method signature. The latter is not always possible, so either way.
There was a problem hiding this comment.
There was a problem hiding this comment.
Can you clarify the question please? Literally, there should be an interface with the promptForOption method and here you should either have it in protected function setMissingValues(InputInteractiveInterface &$input, OutputInterface $output) (better) or call instanceof (still ok).
There was a problem hiding this comment.
Please let me know does this makes sense to you. I don't want to add too much work :)
|
@steverobbins Sorry this has been open so long. I'm attempting to resurrect this and get it merged in, but it looks like the test this PR adds is failing: In my manual test of the command, it appears to be working, so presumably it's the test that is broken. Can you fix this? |
|
I don't know when I'll be able to get to this, someone else might want to take over. |
|
Closing this PR. |
This will prompt for the admin info if not given in the options: