public function logIn(array $options = ['machine-token' => null, 'email' => null])
{
$tokens = $this->session()->getTokens();
if (isset($options['machine-token']) && !is_null($token_string = $options['machine-token'])) {
try {
$token = $tokens->get($token_string);
} catch (\Exception $e) {
$this->log()->notice('Logging in via machine token.');
$tokens->create($token_string);
}
} elseif (isset($options['email']) && !is_null($email = $options['email'])) {
$token = $tokens->get($email);
} elseif (count($all_tokens = $tokens->all()) == 1) {
$token = array_shift($all_tokens);
$this->log()->notice('Found a machine token for {email}.', ['email' => $token->get('email')]);
} else {
if (count($all_tokens) > 1) {
throw new TerminusException("Tokens were saved for the following email addresses:\n{tokens}\nYou may log in via `terminus" . " auth:login --email=<email>`, or you may visit the dashboard to generate a machine" . " token:\n{url}", ['tokens' => implode("\n", $tokens->ids()), 'url' => $this->getMachineTokenCreationURL()]);
} else {
throw new TerminusException("Please visit the dashboard to generate a machine token:\n{url}", ['url' => $this->getMachineTokenCreationURL()]);
}
}
if (isset($token)) {
$this->log()->notice('Logging in via machine token.');
$token->logIn();
}
}