xdrm-framework/exporter/main.php

114 lines
2.6 KiB
PHP
Raw Normal View History

<?php define('__ROOT__', dirname(dirname(__FILE__)) );
2016-12-07 11:22:49 +00:00
require_once __ROOT__.'/exporter/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': case 'p': {
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': case 'i': {
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': case 'r': {
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': case 'b': {
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;
}
?>