Added compiler extension and version structure detection

This commit is contained in:
Netkas 2022-10-21 02:29:03 -04:00
parent a7f7c1bdfd
commit 03185d3dc7
5 changed files with 141 additions and 7 deletions

View file

@ -0,0 +1,13 @@
<?php
namespace ncc\Abstracts;
abstract class CompilerExtensionDefaultVersions
{
// ----------------------------------------------------------------
// [0] = MinimumVersion
// [1] = MaximumVersion
// ----------------------------------------------------------------
const PHP = ['8.0', '8.1'];
}

View file

@ -0,0 +1,8 @@
<?php
namespace ncc\Abstracts;
abstract class CompilerExtensionSupportedVersions
{
const PHP = ['8.0', '8.1'];
}

View file

@ -0,0 +1,12 @@
<?php
namespace ncc\Abstracts;
abstract class CompilerExtensions
{
const PHP = 'php';
const All = [
CompilerExtensions::PHP
];
}

View file

@ -58,6 +58,10 @@
ProjectMenu::start($args); ProjectMenu::start($args);
exit(0); exit(0);
case 'build':
BuildMenu::start($args);
exit(0);
case 'credential': case 'credential':
CredentialMenu::start($args); CredentialMenu::start($args);
exit(0); exit(0);

View file

@ -3,6 +3,9 @@
namespace ncc\CLI; namespace ncc\CLI;
use Exception; use Exception;
use ncc\Abstracts\CompilerExtensionDefaultVersions;
use ncc\Abstracts\CompilerExtensions;
use ncc\Abstracts\CompilerExtensionSupportedVersions;
use ncc\Exceptions\InvalidPackageNameException; use ncc\Exceptions\InvalidPackageNameException;
use ncc\Exceptions\InvalidProjectNameException; use ncc\Exceptions\InvalidProjectNameException;
use ncc\Exceptions\ProjectAlreadyExistsException; use ncc\Exceptions\ProjectAlreadyExistsException;
@ -73,15 +76,103 @@
// Fetch the rest of the information needed for the project // Fetch the rest of the information needed for the project
//$compiler_extension = Console::getOptionInput($args, 'ce', 'Compiler Extension (php, java): '); //$compiler_extension = Console::getOptionInput($args, 'ce', 'Compiler Extension (php, java): ');
$compiler_extension = 'php'; // Always php, for now.
$package_name = Console::getOptionInput($args, 'package', 'Package Name (com.example.foo): '); $package_name = Console::getOptionInput($args, 'package', 'Package Name (com.example.foo): ');
$project_name = Console::getOptionInput($args, 'name', 'Project Name (Foo Bar Library): '); $project_name = Console::getOptionInput($args, 'name', 'Project Name (Foo Bar Library): ');
// Create the compiler configuration
$Compiler = new Compiler(); $Compiler = new Compiler();
$Compiler->Extension = $compiler_extension;
$Compiler->MaximumVersion = '8.1'; // Detect the specified compiler extension
$Compiler->MinimumVersion = '7.4'; if(isset($args['ext']) || isset($args['extension']))
{
$compiler_extension = strtolower(($args['extension'] ?? $args['ext']));
if(in_array($compiler_extension, CompilerExtensions::All))
{
$Compiler->Extension = $compiler_extension;
}
else
{
Console::outError('Unsupported extension: ' . $compiler_extension, true, 1);
return;
}
}
else
{
// Default PHP Extension
$Compiler->Extension = CompilerExtensions::PHP;
}
// If a minimum and maximum version is specified
if(
(isset($args['max-version']) || isset($args['max-ver'])) &&
(isset($args['min-version']) || isset($args['min-ver']))
)
{
$max_version = strtolower($args['max-version'] ?? $args['max-ver']);
$min_version = strtolower($args['min-version'] ?? $args['min-ver']);
switch($Compiler->Extension)
{
case CompilerExtensions::PHP:
if(!in_array($max_version, CompilerExtensionSupportedVersions::PHP))
{
Console::outError('The extension \'' . $Compiler->Extension . '\' does not support version ' . $max_version, true, 1);
return;
}
if(!in_array($min_version, CompilerExtensionSupportedVersions::PHP))
{
Console::outError('The extension \'' . $Compiler->Extension . '\' does not support version ' . $min_version, true, 1);
return;
}
$Compiler->MaximumVersion = $max_version;
$Compiler->MinimumVersion = $min_version;
break;
default:
Console::outError('Unsupported extension: ' . $Compiler->Extension, true, 1);
return;
}
}
// If a single version is specified
elseif(isset($args['version']) || isset($args['ver']))
{
$version = strtolower($args['version'] ?? $args['ver']);
switch($Compiler->Extension)
{
case CompilerExtensions::PHP:
if(!in_array($version, CompilerExtensionSupportedVersions::PHP))
{
Console::outError('The extension \'' . $Compiler->Extension . '\' does not support version ' . $version, true, 1);
return;
}
$Compiler->MaximumVersion = $version;
$Compiler->MinimumVersion = $version;
break;
default:
Console::outError('Unsupported extension: ' . $Compiler->Extension, true, 1);
return;
}
}
// If no version is specified, use the default version
else
{
switch($Compiler->Extension)
{
case CompilerExtensions::PHP:
$Compiler->MinimumVersion = CompilerExtensionDefaultVersions::PHP[1];
$Compiler->MaximumVersion = CompilerExtensionDefaultVersions::PHP[0];
break;
default:
Console::outError('Unsupported extension: ' . $Compiler->Extension, true, 1);
return;
}
}
// Now create the project // Now create the project
$ProjectManager = new ProjectManager($current_directory); $ProjectManager = new ProjectManager($current_directory);
@ -93,18 +184,22 @@
catch (InvalidPackageNameException $e) catch (InvalidPackageNameException $e)
{ {
Console::outException('The given package name is invalid, the value must follow the standard package naming convention', $e, 1); Console::outException('The given package name is invalid, the value must follow the standard package naming convention', $e, 1);
return;
} }
catch (InvalidProjectNameException $e) catch (InvalidProjectNameException $e)
{ {
Console::outException('The given project name is invalid, cannot be empty or larger than 126 characters', $e, 1); Console::outException('The given project name is invalid, cannot be empty or larger than 126 characters', $e, 1);
return;
} }
catch (ProjectAlreadyExistsException $e) catch (ProjectAlreadyExistsException $e)
{ {
Console::outException('A project has already been initialized in \'' . $current_directory . '\'', $e, 1); Console::outException('A project has already been initialized in \'' . $current_directory . '\'', $e, 1);
return;
} }
catch(Exception $e) catch(Exception $e)
{ {
Console::outException('There was an unexpected error while trying to initialize the project', $e, 1); Console::outException('There was an unexpected error while trying to initialize the project', $e, 1);
return;
} }
Console::out('Project successfully created'); Console::out('Project successfully created');
@ -121,7 +216,9 @@
$options = [ $options = [
new CliHelpSection(['help'], 'Displays this help menu about the value command'), new CliHelpSection(['help'], 'Displays this help menu about the value command'),
new CliHelpSection(['create', '--src', '--package', '--name'], 'Creates a new NCC project'), new CliHelpSection(['create', '--src', '--package', '--name'], 'Creates a new NCC project'),
new CliHelpSection(['create', '--makefile'], 'Generates a Makefile for the project'), new CliHelpSection(['create', '--ext'], 'Specifies the compiler extension'),
new CliHelpSection(['create', '--min-version', '--min-ver', '--maximum-ver', '-max-ver'], 'Specifies the compiler extension version'),
new CliHelpSection(['create-makefile'], 'Generates a Makefile for the project'),
]; ];
$options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4; $options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4;