Skip to content

Commit 8a308fe

Browse files
committedJan 29, 2022
Make argument optional to have interact working
1 parent 5199af4 commit 8a308fe

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed
 

‎src/Command/ActivateUserCommand.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function configure(): void
4444
$this
4545
->setDescription(static::$defaultDescription)
4646
->setDefinition([
47-
new InputArgument('username', InputArgument::REQUIRED, 'The username'),
47+
new InputArgument('username', InputArgument::OPTIONAL, 'The username'),
4848
])
4949
->setHelp(
5050
<<<'EOT'
@@ -78,11 +78,11 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
7878
{
7979
$username = $input->getArgument('username');
8080

81-
if (null === $username) {
82-
$question = new Question('Please choose a username:');
83-
$question->setValidator(static function ($username) {
84-
if (null === $username || '' === $username) {
85-
throw new \Exception('Username can not be empty');
81+
if (null === $username || '' === $username) {
82+
$question = new Question('Please choose a username: ');
83+
$question->setValidator(static function (?string $username) {
84+
if (null === $username) {
85+
throw new \InvalidArgumentException('Username can not be empty');
8686
}
8787

8888
return $username;

0 commit comments

Comments
 (0)