104 lines
2.3 KiB
PHP
104 lines
2.3 KiB
PHP
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
|
|
|
require_once 'Exporter.php';
|
|
|
|
/* [1] Initialisation
|
|
=========================================================*/
|
|
/* (1) Get arguments (excepted file) */
|
|
$arguments = array_slice($argv, 1);
|
|
$arglen = $argc - 1;
|
|
|
|
|
|
// si aucun argument
|
|
if( count($arguments) === 0 ){
|
|
echo "Missing arguments.\n";
|
|
return;
|
|
}
|
|
|
|
/* (2) Load module's config */
|
|
$exporter = new Exporter();
|
|
|
|
/* [2] Commands
|
|
=========================================================*/
|
|
switch($arguments[0]){
|
|
|
|
/* (1) Modules listing
|
|
---------------------------------------------------------*/
|
|
case 'modules': {
|
|
|
|
echo "available modules:\n";
|
|
$modules = $exporter->available();
|
|
|
|
foreach($modules as $module=>$versions){
|
|
|
|
foreach($versions as $version)
|
|
// if enabled
|
|
if( $version['enabled'] )
|
|
echo " [x] $module (version ".$version['version'].")\n";
|
|
else
|
|
echo " [ ] $module (version ".$version['version'].")\n";
|
|
|
|
echo "\n";
|
|
}
|
|
|
|
} break;
|
|
|
|
/* (2) Enables a module and its version
|
|
---------------------------------------------------------*/
|
|
case 'enable': {
|
|
|
|
if( $arglen < 2 || !preg_match("/^(.+):([0-9\.-]+)$/i", $arguments[1], $matches) ){
|
|
echo "You must specify @module:@version.\n";
|
|
return;
|
|
}
|
|
|
|
$err = $exporter->enable($matches[1], $matches[2]);
|
|
|
|
/* (1) Managing state */
|
|
if( $err === true ) echo "\n\n** success **\n";
|
|
else echo $err;
|
|
|
|
} break;
|
|
|
|
/* (3) Disabled a module
|
|
---------------------------------------------------------*/
|
|
case 'disable': {
|
|
|
|
if( $arglen < 2 ){
|
|
echo "You must specify @module.\n";
|
|
return;
|
|
}
|
|
|
|
$err = $exporter->disable($arguments[1]);
|
|
|
|
/* (1) Managing state */
|
|
if( $err === true ) echo "\n\n** success **\n";
|
|
else echo $err;
|
|
|
|
} break;
|
|
|
|
/* (3) Builds a project
|
|
---------------------------------------------------------*/
|
|
case 'build': {
|
|
|
|
if( $arglen < 2 || !is_dir($arguments[1]) ){
|
|
echo "You must specify your project root's @path.\n";
|
|
return;
|
|
}
|
|
|
|
// Removes the optional final '/'
|
|
$arguments[1] = preg_replace('/^(.+)\/$/', '$1', $arguments[1]);
|
|
|
|
$err = $exporter->build($arguments[1]);
|
|
|
|
/* (1) Managing state */
|
|
if( $err === true ) echo "\n\n** success **\n";
|
|
else echo $err;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
?>
|