addArgument('user', InputArgument::OPTIONAL, 'User name'); $this->addArgument('password', InputArgument::OPTIONAL, 'User password'); $this->addArgument('host', InputArgument::OPTIONAL, 'User host'); } protected function execute(InputInterface $input, OutputInterface $output): int { $question = $this->getHelper('question'); $user = $input->getArgument('user'); $password = $input->getArgument('password'); $host = $input->getArgument('host'); if (!$user) { $user = $question->ask($input, $output, new Question('User name: ')); } if (!$password) { $passwordQuestion = new Question('User password: '); $passwordQuestion->setHidden(true); $password = $question->ask($input, $output, $passwordQuestion); } $this->db->createUser($user, $password, $host); $output->writeln(sprintf('User "%s" successfully created', $user)); // ask to create a database for the user $createDbQuestion = new ConfirmationQuestion('Create a database for this user?', false); if ($question->ask($input, $output, $createDbQuestion)) { $this->db->createDatabase($user); $this->db->grantDatabaseAdminPermission($user, $user, $host); $output->writeln(sprintf('Database "%s" successfully created and granted to "%s"', $user, $user)); } return Command::SUCCESS; } }