Skip to content

Commit 16e610a

Browse files
author
Barna Szalai
authored
Merge pull request #3 from mafecito/extend
Add optional args and random password option
2 parents ab73fa3 + 4db2c0a commit 16e610a

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/Commands/CliUserCreateCommand.php

+28-13
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CliUserCreateCommand extends Command
3333
*
3434
* @var string
3535
*/
36-
protected $signature = 'cliuser:create {--show-password : Show letters in password field}';
36+
protected $signature = 'cliuser:create {name?} {email?} {--random-password : Create the user with a random password} {--show-password : Show letters in password field}';
3737

3838
/**
3939
* The console command description.
@@ -94,20 +94,26 @@ public function handle()
9494
$fullname = $this->getFullname();
9595

9696
$email = $this->getEmail();
97-
98-
if ($this->confirm('Do you want to set password?')) {
99-
100-
$password = $this->getPassword();
10197

102-
$password_confirmation = $this->getPasswordConfirmation();
98+
if ($this->option('random-password')) {
10399

104-
if ($password !== $password_confirmation) {
105-
$this->error('The password confirmation doesn\'t match the password!');
106-
$this->getPasswordConfirmation();
107-
}
100+
$password = str_random(40);
108101

109102
} else {
110-
$password = null;
103+
if ($this->confirm('Do you want to set password?')) {
104+
105+
$password = $this->getPassword();
106+
107+
$password_confirmation = $this->getPasswordConfirmation();
108+
109+
if ($password !== $password_confirmation) {
110+
$this->error('The password confirmation doesn\'t match the password!');
111+
$this->getPasswordConfirmation();
112+
}
113+
114+
} else {
115+
$password = null;
116+
}
111117
}
112118

113119
try {
@@ -129,7 +135,11 @@ public function handle()
129135
*/
130136
private function getFullname()
131137
{
132-
$value = $this->ask('Full name');
138+
$value = $this->argument('name');
139+
140+
if (empty($value) === true) {
141+
$value = $this->ask('Full name');
142+
}
133143

134144
$v = $this->validator->make(
135145
['value' => trim($value)],
@@ -152,7 +162,12 @@ private function getFullname()
152162
*/
153163
private function getEmail()
154164
{
155-
$value = $this->ask('E-mail');
165+
166+
$value = $this->argument('email');
167+
168+
if (empty($value) === true) {
169+
$value = $this->ask('E-mail');
170+
}
156171

157172
$v = $this->validator->make(
158173
['value' => trim($value)],

0 commit comments

Comments
 (0)