114 lines
2.5 KiB
PHP
114 lines
2.5 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 package's config */
|
|
$exporter = new Exporter();
|
|
|
|
/* [2] Commands
|
|
=========================================================*/
|
|
switch($arguments[0]){
|
|
|
|
/* (0) Reset enabled packages
|
|
---------------------------------------------------------*/
|
|
case 'init': {
|
|
|
|
$exporter->init();
|
|
|
|
echo "** success **\n";
|
|
|
|
} break;
|
|
|
|
/* (1) Packages listing
|
|
---------------------------------------------------------*/
|
|
case 'packages': {
|
|
|
|
echo "available packages:\n";
|
|
$packages = $exporter->available();
|
|
|
|
foreach($packages as $package=>$versions){
|
|
|
|
foreach($versions as $version)
|
|
// if enabled
|
|
if( $version['enabled'] )
|
|
echo " [*] $package:".$version['version']."\n";
|
|
else
|
|
echo " [ ] $package:".$version['version']."\n";
|
|
|
|
echo "\n";
|
|
}
|
|
|
|
} break;
|
|
|
|
/* (2) Enables a package and its version
|
|
---------------------------------------------------------*/
|
|
case 'install': {
|
|
|
|
if( $arglen < 2 || !preg_match("/^([^:]+)(:(?:[0-9\.-]+))?$/i", $arguments[1], $matches) ){
|
|
echo "You must specify @package:@version.\n";
|
|
return;
|
|
}
|
|
|
|
$err = $exporter->install($matches[1], count($matches) > 2 ? substr($matches[2], 1) : null);
|
|
|
|
/* (1) Managing state */
|
|
if( $err === true ) echo "\n\n** success **\n";
|
|
else echo $err;
|
|
|
|
} break;
|
|
|
|
/* (3) Disabled a package
|
|
---------------------------------------------------------*/
|
|
case 'remove': {
|
|
|
|
if( $arglen < 2 ){
|
|
echo "You must specify @package.\n";
|
|
return;
|
|
}
|
|
|
|
$err = $exporter->remove($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;
|
|
|
|
}
|
|
|
|
|
|
?>
|