setName('lookup-user')
->setAliases(['lookup'])
->addArgument(
'key',
InputArgument::REQUIRED,
'The username, email, id, or key to lookup'
)
->setDescription('Finds user info based on some data')
->setHelp('The lookup-user finds a user based on some data query.')
;
}
/**
* @return int|null|void
*/
protected function serve()
{
include __DIR__ . '/../vendor/autoload.php';
$io = new SymfonyStyle($this->input, $this->output);
$grav = Grav::instance();
$grav->setup();
$io->title('Looking up user');
// Initialize Plugins
$grav['plugins']->init();
$grav->fireEvent('onCliInitialize');
$key = $this->input->getArgument('key');
/** @var UserCollectionInterface $users */
$users = $grav['accounts'];
/** @var UserInterface $user */
$user = $users->find($key, ['username', 'email', 'fullname', 'storage_key', 'flex_key']);
if ($user->exists()) {
/** @var $io SymfonyStyle */
$io->text('Username: '. $user->username . '');
$io->text('Name: ' . $user->fullname . '');
if ($user instanceof FlexObject) {
$io->text('Flex Key: ' . $user->getFlexKey() . '');
}
$io->text('Email: ' . $user->email . '');
$io->newLine();
exit;
}
$io->error('Sorry, the user with query: "' . $key . '", was not found');
}
}