diff --git a/bin/magento b/bin/magento
index 3fa9221763cf5..8daff9847bfca 100755
--- a/bin/magento
+++ b/bin/magento
@@ -20,7 +20,7 @@ try {
$handler = new \Magento\Framework\App\ErrorHandler();
set_error_handler([$handler, 'handler']);
$application = new Magento\Framework\Console\Cli('Magento CLI');
- $application->run();
+ $application->run(new Magento\Framework\Console\Input);
} catch (\Exception $e) {
while ($e) {
echo $e->getMessage();
diff --git a/lib/internal/Magento/Framework/Console/Input.php b/lib/internal/Magento/Framework/Console/Input.php
new file mode 100644
index 0000000000000..50ca3324f760e
--- /dev/null
+++ b/lib/internal/Magento/Framework/Console/Input.php
@@ -0,0 +1,32 @@
+definition->getOption($name)->setDefault($dialog->$method(
+ $output,
+ '' . ucwords(str_replace('-', ' ', $name)) . ': '
+ ));
+ }
+}
diff --git a/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php b/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php
index 33a63ce02cb1f..dd53a8463eb64 100644
--- a/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php
+++ b/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php
@@ -45,7 +45,7 @@ public function __construct(InstallerFactory $installerFactory, UserValidationRu
protected function configure()
{
$this->setName('admin:user:create')
- ->setDescription('Creates an administrator')
+ ->setDescription('Creates an administrator. Values for required options will be prompted, if not specified')
->setDefinition($this->getOptionsList());
parent::configure();
}
@@ -55,6 +55,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
+ $this->setMissingValues($input, $output);
$errors = $this->validate($input);
if ($errors) {
$output->writeln('' . implode('' . PHP_EOL . '', $errors) . '');
@@ -123,4 +124,31 @@ public function validate(InputInterface $input)
return $errors;
}
+
+ /**
+ * Get admin user data
+ *
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return void
+ */
+ protected function setMissingValues(InputInterface &$input, OutputInterface $output)
+ {
+ if (!method_exists($input, 'promptForOption')) {
+ return;
+ }
+ $dialog = $this->getHelper('dialog');
+ $keys = [
+ AdminAccount::KEY_FIRST_NAME,
+ AdminAccount::KEY_LAST_NAME,
+ AdminAccount::KEY_USER,
+ AdminAccount::KEY_EMAIL,
+ AdminAccount::KEY_PASSWORD,
+ ];
+ foreach ($keys as $key) {
+ if (!$input->getOption($key)) {
+ $input->promptForOption($dialog, $output, $key, $key === AdminAccount::KEY_PASSWORD);
+ }
+ }
+ }
}
diff --git a/setup/src/Magento/Setup/Console/Input/PromptableInputOption.php b/setup/src/Magento/Setup/Console/Input/PromptableInputOption.php
new file mode 100644
index 0000000000000..a0d6376a8f975
--- /dev/null
+++ b/setup/src/Magento/Setup/Console/Input/PromptableInputOption.php
@@ -0,0 +1,48 @@
+setDefault($dialog->ask(
+ new ConsoleOutput,
+ '' . ucwords(str_replace('-', ' ', $this->getName())) . ': '
+ ));
+ return parent::getDefault();
+ }
+}
diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php
index c1d382ee6cd24..999455ce4198f 100644
--- a/setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/AdminUserCreateCommandTest.php
@@ -5,10 +5,13 @@
*/
namespace Magento\Setup\Test\Unit\Console\Command;
+use Magento\Framework\Console\Input;
use Magento\Setup\Model\AdminAccount;
use Magento\Setup\Console\Command\AdminUserCreateCommand;
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
use Magento\User\Model\UserValidationRules;
+use Symfony\Component\Console\Helper\HelperSet;
+use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Tester\CommandTester;
class AdminUserCreateCommandTest extends \PHPUnit_Framework_TestCase
@@ -27,6 +30,7 @@ public function setUp()
{
$this->installerFactoryMock = $this->getMock(\Magento\Setup\Model\InstallerFactory::class, [], [], '', false);
$this->command = new AdminUserCreateCommand($this->installerFactoryMock, new UserValidationRules());
+ $this->command->setHelperSet(new HelperSet([new DialogHelper]));
}
public function testExecute()
@@ -119,4 +123,34 @@ public function validateDataProvider()
[['John', 'Doe', 'admin', 'test@test.com', '123123q', '123123q'], []],
];
}
+
+ public function testExecuteWithPrompts()
+ {
+ $data = [
+ AdminAccount::KEY_USER => 'user',
+ AdminAccount::KEY_PASSWORD => '123123q',
+ AdminAccount::KEY_EMAIL => 'test@test.com',
+ AdminAccount::KEY_FIRST_NAME => 'John',
+ AdminAccount::KEY_LAST_NAME => 'Doe',
+ ];
+ $commandTester = new CommandTester($this->command);
+ $installerMock = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false);
+ $installerMock->expects($this->once())->method('installAdminUser')->with($data);
+ $this->installerFactoryMock->expects($this->once())->method('create')->willReturn($installerMock);
+
+ $helper = $this->command->getHelper('dialog');
+ $helper->setInputStream($this->getInputStream("John\nDoe\nuser\ntest@test.com\n123123q\n"));
+
+ $commandTester->execute([], ['interactive' => new Input]);
+ $this->assertContains('Created Magento administrator user named user', $commandTester->getDisplay());
+ }
+
+ protected function getInputStream($input)
+ {
+ $stream = fopen('php://memory', 'r+', false);
+ fputs($stream, $input);
+ rewind($stream);
+
+ return $stream;
+ }
}