diff --git a/app/Commands/LoginCommand.php b/app/Commands/LoginCommand.php index c5436db..39dbab7 100644 --- a/app/Commands/LoginCommand.php +++ b/app/Commands/LoginCommand.php @@ -11,7 +11,7 @@ class LoginCommand extends Command * * @var string */ - protected $signature = 'login'; + protected $signature = 'login {--token= : Forge API token}'; /** * The description of the command. @@ -27,7 +27,11 @@ class LoginCommand extends Command */ public function handle() { - $token = $this->askStep('Please enter your Forge API token'); + $token = $this->option('token'); + + if ($token === null) { + $token = $this->askStep('Please enter your Forge API token'); + } $this->config->set('token', $token); diff --git a/tests/Feature/LoginCommandTest.php b/tests/Feature/LoginCommandTest.php index be55faf..50013c7 100755 --- a/tests/Feature/LoginCommandTest.php +++ b/tests/Feature/LoginCommandTest.php @@ -14,6 +14,19 @@ ->expectsOutput('==> Authenticated Successfully As [nuno@laravel.com]'); }); +it('authenticates users with token', function () { + $this->client->shouldReceive('user')->andReturn((object) [ + 'email' => 'nuno@laravel.com', + ]); + + $this->client->shouldReceive('servers')->andReturn([ + (object) ['id' => 1], + ]); + + $this->artisan('login --token 123123123') + ->expectsOutput('==> Authenticated Successfully As [nuno@laravel.com]'); +}); + it('sets current server', function () { $this->client->shouldReceive('user')->andReturn((object) [ 'email' => 'nuno@laravel.com',