Added 'list' command to CredentialMenu.php

https://git.n64.cc/nosial/ncc/-/issues/27
This commit is contained in:
Netkas 2022-12-07 18:08:38 -05:00
parent 5a83a7f6fe
commit e38a4df2ee

View file

@ -50,9 +50,47 @@
return;
}
if(isset($args['list']))
{
try
{
self::listEntries();
}
catch(Exception $e)
{
Console::outException('Cannot list credentials.', $e, 1);
}
return;
}
self::displayOptions();
}
/**
* Prints the list of entries in the vault
*
* @return void
*/
public static function listEntries(): void
{
$credential_manager = new CredentialManager();
$entries = $credential_manager->getVault()->getEntries();
if(count($entries) === 0)
{
Console::out('No credentials found.');
return;
}
foreach($entries as $entry)
{
Console::out(sprintf('%s%s', $entry->getName(), ($entry->isEncrypted() ? ' (encrypted)' : '')));
}
Console::out('Total: ' . count($entries));
}
/**
* @param $args
* @return void