Skip to content

Commit b6133a7

Browse files
[12.x] Enhance console commands (#1724)
* make migration and creating clients optional * use components on cli * fix tests * Update InstallCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent e063df3 commit b6133a7

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

src/Console/ClientCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function createPersonalClient(ClientRepository $clients)
6767
null, $name, 'http://localhost'
6868
);
6969

70-
$this->info('Personal access client created successfully.');
70+
$this->components->info('Personal access client created successfully.');
7171

7272
$this->outputClientDetails($client);
7373
}
@@ -97,7 +97,7 @@ protected function createPasswordClient(ClientRepository $clients)
9797
null, $name, 'http://localhost', $provider
9898
);
9999

100-
$this->info('Password grant client created successfully.');
100+
$this->components->info('Password grant client created successfully.');
101101

102102
$this->outputClientDetails($client);
103103
}
@@ -119,7 +119,7 @@ protected function createClientCredentialsClient(ClientRepository $clients)
119119
null, $name, ''
120120
);
121121

122-
$this->info('New client created successfully.');
122+
$this->components->info('New client created successfully.');
123123

124124
$this->outputClientDetails($client);
125125
}
@@ -149,7 +149,7 @@ protected function createAuthCodeClient(ClientRepository $clients)
149149
$userId, $name, $redirect, null, false, false, ! $this->option('public')
150150
);
151151

152-
$this->info('New client created successfully.');
152+
$this->components->info('New client created successfully.');
153153

154154
$this->outputClientDetails($client);
155155
}
@@ -167,7 +167,7 @@ protected function outputClientDetails(Client $client)
167167
$this->line('');
168168
}
169169

170-
$this->line('<comment>Client ID:</comment> '.$client->getKey());
171-
$this->line('<comment>Client secret:</comment> '.$client->plainSecret);
170+
$this->components->twoColumnDetail('<comment>Client ID</comment>', $client->getKey());
171+
$this->components->twoColumnDetail('<comment>Client secret</comment>', $client->plainSecret);
172172
}
173173
}

src/Console/HashCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class HashCommand extends Command
2929
public function handle()
3030
{
3131
if (! Passport::$hashesClientSecrets) {
32-
$this->warn('Please enable client hashing yet in your AppServiceProvider before continuing.');
32+
$this->components->warn('Please enable client hashing yet in your AppServiceProvider before continuing.');
3333

3434
return;
3535
}
@@ -49,7 +49,7 @@ public function handle()
4949
])->save();
5050
}
5151

52-
$this->info('All client secrets were successfully hashed.');
52+
$this->components->info('All client secrets were successfully hashed.');
5353
}
5454
}
5555
}

src/Console/InstallCommand.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class InstallCommand extends Command
3131
*/
3232
public function handle()
3333
{
34-
$provider = in_array('users', array_keys(config('auth.providers'))) ? 'users' : null;
35-
3634
$this->call('passport:keys', ['--force' => $this->option('force'), '--length' => $this->option('length')]);
3735

3836
$this->call('vendor:publish', ['--tag' => 'passport-migrations']);
@@ -41,10 +39,16 @@ public function handle()
4139
$this->configureUuids();
4240
}
4341

44-
$this->call('migrate');
42+
if ($this->confirm('Would you like to run all pending database migrations?', true)) {
43+
$this->call('migrate');
44+
45+
if ($this->confirm('Would you like to create the "personal access" and "password grant" clients?', true)) {
46+
$provider = in_array('users', array_keys(config('auth.providers'))) ? 'users' : null;
4547

46-
$this->call('passport:client', ['--personal' => true, '--name' => config('app.name').' Personal Access Client']);
47-
$this->call('passport:client', ['--password' => true, '--name' => config('app.name').' Password Grant Client', '--provider' => $provider]);
48+
$this->call('passport:client', ['--personal' => true, '--name' => config('app.name').' Personal Access Client']);
49+
$this->call('passport:client', ['--password' => true, '--name' => config('app.name').' Password Grant Client', '--provider' => $provider]);
50+
}
51+
}
4852
}
4953

5054
/**

src/Console/KeysCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function handle()
3939
];
4040

4141
if ((file_exists($publicKey) || file_exists($privateKey)) && ! $this->option('force')) {
42-
$this->error('Encryption keys already exist. Use the --force option to overwrite them.');
42+
$this->components->error('Encryption keys already exist. Use the --force option to overwrite them.');
4343

4444
return 1;
4545
} else {
@@ -60,7 +60,7 @@ public function handle()
6060
chmod($privateKey, 0600);
6161
}
6262

63-
$this->info('Encryption keys generated successfully.');
63+
$this->components->info('Encryption keys generated successfully.');
6464
}
6565

6666
return 0;

src/Console/PurgeCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ public function handle()
4141
Passport::refreshToken()->where('revoked', 1)->orWhereDate('expires_at', '<', $expired)->delete();
4242

4343
$this->option('hours')
44-
? $this->info('Purged revoked items and items expired for more than '.$this->option('hours').' hours.')
45-
: $this->info('Purged revoked items and items expired for more than seven days.');
44+
? $this->components->info('Purged revoked items and items expired for more than '.$this->option('hours').' hours.')
45+
: $this->components->info('Purged revoked items and items expired for more than seven days.');
4646
} elseif ($this->option('revoked')) {
4747
Passport::token()->where('revoked', 1)->delete();
4848
Passport::authCode()->where('revoked', 1)->delete();
4949
Passport::refreshToken()->where('revoked', 1)->delete();
5050

51-
$this->info('Purged revoked items.');
51+
$this->components->info('Purged revoked items.');
5252
} elseif ($this->option('expired')) {
5353
Passport::token()->whereDate('expires_at', '<', $expired)->delete();
5454
Passport::authCode()->whereDate('expires_at', '<', $expired)->delete();
5555
Passport::refreshToken()->whereDate('expires_at', '<', $expired)->delete();
5656

5757
$this->option('hours')
58-
? $this->info('Purged items expired for more than '.$this->option('hours').' hours.')
59-
: $this->info('Purged items expired for more than seven days.');
58+
? $this->components->info('Purged items expired for more than '.$this->option('hours').' hours.')
59+
: $this->components->info('Purged items expired for more than seven days.');
6060
}
6161
}
6262
}

tests/Feature/KeysCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public function testPrivateAndPublicKeysShouldNotBeGeneratedTwice()
1414
{
1515
$this->artisan('passport:keys')
1616
->assertFailed()
17-
->expectsOutput('Encryption keys already exist. Use the --force option to overwrite them.');
17+
->expectsOutputToContain('Encryption keys already exist. Use the --force option to overwrite them.');
1818
}
1919
}

0 commit comments

Comments
 (0)