Added basic menu for credential menu
This commit is contained in:
parent
f9141ae586
commit
6a399261a8
8 changed files with 150 additions and 29 deletions
71
src/ncc/CLI/CredentialMenu.php
Normal file
71
src/ncc/CLI/CredentialMenu.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ncc\CLI;
|
||||||
|
|
||||||
|
use ncc\Abstracts\Scopes;
|
||||||
|
use ncc\Exceptions\AccessDeniedException;
|
||||||
|
use ncc\Objects\CliHelpSection;
|
||||||
|
use ncc\Utilities\Resolver;
|
||||||
|
|
||||||
|
class CredentialMenu
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Displays the main help menu
|
||||||
|
*
|
||||||
|
* @param $args
|
||||||
|
* @return void
|
||||||
|
* @throws AccessDeniedException
|
||||||
|
*/
|
||||||
|
public static function start($args): void
|
||||||
|
{
|
||||||
|
if(isset($args['add']))
|
||||||
|
{
|
||||||
|
self::addCredential($args);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::displayOptions();
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $args
|
||||||
|
* @return void
|
||||||
|
* @throws AccessDeniedException
|
||||||
|
*/
|
||||||
|
public static function addCredential($args): void
|
||||||
|
{
|
||||||
|
$ResolvedScope = Resolver::resolveScope();
|
||||||
|
|
||||||
|
if($ResolvedScope !== Scopes::System)
|
||||||
|
{
|
||||||
|
throw new AccessDeniedException('Root permissions are required to manage the vault');
|
||||||
|
}
|
||||||
|
|
||||||
|
print('end' . PHP_EOL);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the main options section
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function displayOptions(): void
|
||||||
|
{
|
||||||
|
$options = [
|
||||||
|
new CliHelpSection(['help'], 'Displays this help menu about the value command'),
|
||||||
|
new CliHelpSection(['add'], 'Adds a new credential to the vault'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4;
|
||||||
|
|
||||||
|
print('Usage: ncc vault {command} [options]' . PHP_EOL);
|
||||||
|
print('Options:' . PHP_EOL);
|
||||||
|
foreach($options as $option)
|
||||||
|
{
|
||||||
|
print(' ' . $option->toString($options_padding) . PHP_EOL);
|
||||||
|
}
|
||||||
|
print(PHP_EOL);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,11 +9,21 @@
|
||||||
/**
|
/**
|
||||||
* Displays the main help menu
|
* Displays the main help menu
|
||||||
*
|
*
|
||||||
* @param $argv
|
* @param $args
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function start($argv)
|
public static function start($args)
|
||||||
{
|
{
|
||||||
|
$basic_ascii = false;
|
||||||
|
|
||||||
|
if(isset($args['basic-ascii']))
|
||||||
|
{
|
||||||
|
$basic_ascii = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Make copyright not hard-coded.
|
||||||
|
print(\ncc\Utilities\Functions::getBanner(NCC_VERSION_BRANCH . ' ' . NCC_VERSION_NUMBER, 'Copyright (c) 2022-2022 Nosial', $basic_ascii) . PHP_EOL);
|
||||||
|
|
||||||
print('Usage: ncc COMMAND [options]' . PHP_EOL);
|
print('Usage: ncc COMMAND [options]' . PHP_EOL);
|
||||||
print('Alternative Usage: ncc.php --ncc-cli=COMMAND [options]' . PHP_EOL . PHP_EOL);
|
print('Alternative Usage: ncc.php --ncc-cli=COMMAND [options]' . PHP_EOL . PHP_EOL);
|
||||||
print('Nosial Code Compiler / Project Toolkit' . PHP_EOL . PHP_EOL);
|
print('Nosial Code Compiler / Project Toolkit' . PHP_EOL . PHP_EOL);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace ncc\CLI;
|
namespace ncc\CLI;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use ncc\ncc;
|
||||||
use ncc\Utilities\Resolver;
|
use ncc\Utilities\Resolver;
|
||||||
|
|
||||||
class Main
|
class Main
|
||||||
|
@ -19,32 +21,32 @@
|
||||||
if(isset($args['ncc-cli']))
|
if(isset($args['ncc-cli']))
|
||||||
{
|
{
|
||||||
// Initialize NCC
|
// Initialize NCC
|
||||||
\ncc\ncc::initialize();
|
ncc::initialize();
|
||||||
|
|
||||||
if(isset($args['no-banner']) == false)
|
try
|
||||||
{
|
{
|
||||||
$basic_ascii = false;
|
switch(strtolower($args['ncc-cli']))
|
||||||
|
|
||||||
if(isset($args['basic-ascii']))
|
|
||||||
{
|
{
|
||||||
$basic_ascii = true;
|
default:
|
||||||
|
print('Unknown command ' . strtolower($args['ncc-cli']) . PHP_EOL);
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
case 'credential':
|
||||||
|
CredentialMenu::start($args);
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
case '1':
|
||||||
|
case 'help':
|
||||||
|
HelpMenu::start($args);
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make copyright not hard-coded.
|
|
||||||
print(\ncc\Utilities\Functions::getBanner(NCC_VERSION_BRANCH . ' ' . NCC_VERSION_NUMBER, 'Copyright (c) 2022-2022 Nosial', $basic_ascii) . PHP_EOL);
|
|
||||||
}
|
}
|
||||||
|
catch(Exception $e)
|
||||||
switch(strtolower($args['ncc-cli']))
|
|
||||||
{
|
{
|
||||||
default:
|
print('Error: ' . $e->getMessage() . ' (Code: ' . $e->getCode() . ')' . PHP_EOL);
|
||||||
print('Unknown command ' . strtolower($args['ncc-cli']) . PHP_EOL);
|
exit(1);
|
||||||
exit(1);
|
|
||||||
|
|
||||||
case '1':
|
|
||||||
case 'help':
|
|
||||||
HelpMenu::start($argv);
|
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace ncc\CLI;
|
|
||||||
|
|
||||||
class VaultMenu
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
10
src/ncc/Objects/Vault.php
Normal file
10
src/ncc/Objects/Vault.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ncc\Objects;
|
||||||
|
|
||||||
|
class Vault
|
||||||
|
{
|
||||||
|
public $Version;
|
||||||
|
|
||||||
|
public $Entries;
|
||||||
|
}
|
|
@ -5,6 +5,9 @@
|
||||||
use ncc\Exceptions\FileNotFoundException;
|
use ncc\Exceptions\FileNotFoundException;
|
||||||
use ncc\Exceptions\MalformedJsonException;
|
use ncc\Exceptions\MalformedJsonException;
|
||||||
use ncc\Objects\CliHelpSection;
|
use ncc\Objects\CliHelpSection;
|
||||||
|
use function chr;
|
||||||
|
use function is_int;
|
||||||
|
use function is_string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zi Xing Narrakas
|
* @author Zi Xing Narrakas
|
||||||
|
@ -181,4 +184,35 @@
|
||||||
|
|
||||||
return $banner;
|
return $banner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|null $prompt
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getInput(?string $prompt=null): string
|
||||||
|
{
|
||||||
|
if($prompt !== null)
|
||||||
|
{
|
||||||
|
print($prompt);
|
||||||
|
}
|
||||||
|
|
||||||
|
$handle = fopen ("php://stdin","r");
|
||||||
|
return fgets($handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $args
|
||||||
|
* @param string $option
|
||||||
|
* @param string $prompt
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getOptionInput(array $args, string $option, string $prompt): string
|
||||||
|
{
|
||||||
|
if(isset($args[$option]))
|
||||||
|
{
|
||||||
|
return $args[$option];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::getInput($prompt);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
namespace ncc\Utilities;
|
namespace ncc\Utilities;
|
||||||
|
|
||||||
use ncc\Abstracts\Scopes;
|
use ncc\Abstracts\Scopes;
|
||||||
|
use ncc\Exceptions\AccessDeniedException;
|
||||||
use ncc\Exceptions\InvalidScopeException;
|
use ncc\Exceptions\InvalidScopeException;
|
||||||
|
|
||||||
class PathFinder
|
class PathFinder
|
||||||
|
|
|
@ -13,6 +13,7 @@ spl_autoload_register(
|
||||||
'ncc\\abstracts\\regexpatterns' => '/Abstracts/RegexPatterns.php',
|
'ncc\\abstracts\\regexpatterns' => '/Abstracts/RegexPatterns.php',
|
||||||
'ncc\\abstracts\\scopes' => '/Abstracts/Scopes.php',
|
'ncc\\abstracts\\scopes' => '/Abstracts/Scopes.php',
|
||||||
'ncc\\abstracts\\stringpaddingmethod' => '/Abstracts/StringPaddingMethod.php',
|
'ncc\\abstracts\\stringpaddingmethod' => '/Abstracts/StringPaddingMethod.php',
|
||||||
|
'ncc\\cli\\credentialmenu' => '/CLI/CredentialMenu.php',
|
||||||
'ncc\\cli\\functions' => '/CLI/Functions.php',
|
'ncc\\cli\\functions' => '/CLI/Functions.php',
|
||||||
'ncc\\cli\\helpmenu' => '/CLI/HelpMenu.php',
|
'ncc\\cli\\helpmenu' => '/CLI/HelpMenu.php',
|
||||||
'ncc\\cli\\main' => '/CLI/Main.php',
|
'ncc\\cli\\main' => '/CLI/Main.php',
|
||||||
|
|
Loading…
Add table
Reference in a new issue