-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneuron
More file actions
executable file
·107 lines (93 loc) · 2.59 KB
/
Copy pathneuron
File metadata and controls
executable file
·107 lines (93 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env php
<?php
/**
* Neuron CLI - Command-line interface for the Neuron PHP framework
*
* This script serves as the entry point for the Neuron CLI tool.
* It can be installed globally via Composer or run locally.
*/
// Find and load the autoloader
$autoloaderPaths = [
// When installed globally via Composer
__DIR__ . '/../../../autoload.php',
// When in development or installed as a dependency
__DIR__ . '/../vendor/autoload.php',
// When installed in a project
__DIR__ . '/../../../../vendor/autoload.php',
// Alternative paths
dirname( __DIR__, 3 ) . '/vendor/autoload.php',
dirname( __DIR__, 4 ) . '/vendor/autoload.php',
];
$autoloaderFound = false;
foreach( $autoloaderPaths as $path )
{
if( file_exists( $path ) )
{
require_once $path;
$autoloaderFound = true;
break;
}
}
if( !$autoloaderFound )
{
fwrite( STDERR, "Error: Unable to find Composer autoloader.\n" );
fwrite( STDERR, "Please run 'composer install' to install dependencies.\n" );
exit( 1 );
}
// Check PHP version
if( version_compare( PHP_VERSION, '8.4.0', '<' ) )
{
fwrite( STDERR, "Error: Neuron CLI requires PHP 8.4 or higher.\n" );
fwrite( STDERR, "Current PHP version: " . PHP_VERSION . "\n" );
exit( 1 );
}
// Load configuration if available
// Use SettingManagerFactory to load environment-specific configs and encrypted secrets
$settings = null;
$configPaths = [
getcwd() . '/config',
getcwd(),
];
foreach( $configPaths as $configPath )
{
$neuronYaml = $configPath . '/neuron.yaml';
if( file_exists( $neuronYaml ) )
{
try
{
// Use SettingManagerFactory to load all configuration layers:
// - Base config (neuron.yaml)
// - Environment-specific config (environments/{env}.yaml)
// - Base secrets (secrets.yml.enc)
// - Environment-specific secrets (environments/{env}.secrets.yml.enc)
// - .env variables (fallback)
$settings = \Neuron\Data\Settings\SettingManagerFactory::create( null, $configPath );
break;
}
catch( \Exception $e )
{
// Silently ignore config loading errors
}
}
}
// Create and run the application
try
{
$app = new \Neuron\Cli\Application( '0.1.0', $settings );
// Pass command-line arguments to the application
$app->run( $argv );
// Get the exit code from command execution
$exitCode = $app->getExitCode();
exit( $exitCode );
}
catch( \Exception $e )
{
fwrite( STDERR, "Fatal error: " . $e->getMessage() . "\n" );
// If verbose mode is enabled, show the stack trace
if( in_array( '--verbose', $argv ) || in_array( '-v', $argv ) )
{
fwrite( STDERR, "\nStack trace:\n" );
fwrite( STDERR, $e->getTraceAsString() . "\n" );
}
exit( 1 );
}