2016-10-19 08:16:21 +00:00
|
|
|
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
|
|
|
|
2016-12-07 11:22:49 +00:00
|
|
|
require_once __ROOT__.'/exporter/Exporter.php';
|
2016-10-19 08:16:21 +00:00
|
|
|
|
|
|
|
/* [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;
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
/* (2) Load package's config */
|
2016-10-19 08:16:21 +00:00
|
|
|
$exporter = new Exporter();
|
|
|
|
|
|
|
|
/* [2] Commands
|
|
|
|
=========================================================*/
|
|
|
|
switch($arguments[0]){
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
/* (0) Reset enabled packages
|
2016-12-05 13:49:51 +00:00
|
|
|
---------------------------------------------------------*/
|
|
|
|
case 'init': {
|
|
|
|
|
|
|
|
$exporter->init();
|
|
|
|
|
|
|
|
echo "** success **\n";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
/* (1) Packages listing
|
2016-10-19 08:16:21 +00:00
|
|
|
---------------------------------------------------------*/
|
2016-12-12 00:45:59 +00:00
|
|
|
case 'packages': case 'p': {
|
2016-10-19 08:16:21 +00:00
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
echo "available packages:\n";
|
|
|
|
$packages = $exporter->available();
|
2016-10-19 08:16:21 +00:00
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
foreach($packages as $package=>$versions){
|
2016-10-19 08:16:21 +00:00
|
|
|
|
|
|
|
foreach($versions as $version)
|
2016-12-05 13:42:38 +00:00
|
|
|
// if enabled
|
|
|
|
if( $version['enabled'] )
|
2016-12-05 18:54:19 +00:00
|
|
|
echo " [*] $package:".$version['version']."\n";
|
2016-12-05 13:42:38 +00:00
|
|
|
else
|
2016-12-05 18:54:19 +00:00
|
|
|
echo " [ ] $package:".$version['version']."\n";
|
2016-10-19 08:16:21 +00:00
|
|
|
|
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
/* (2) Enables a package and its version
|
2016-10-19 08:16:21 +00:00
|
|
|
---------------------------------------------------------*/
|
2016-12-12 00:45:59 +00:00
|
|
|
case 'install': case 'i': {
|
2016-10-19 08:16:21 +00:00
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
if( $arglen < 2 || !preg_match("/^([^:]+)(:(?:[0-9\.-]+))?$/i", $arguments[1], $matches) ){
|
|
|
|
echo "You must specify @package:@version.\n";
|
2016-10-19 08:16:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
$err = $exporter->install($matches[1], count($matches) > 2 ? substr($matches[2], 1) : null);
|
2016-10-19 08:16:21 +00:00
|
|
|
|
|
|
|
/* (1) Managing state */
|
2016-12-05 13:42:38 +00:00
|
|
|
if( $err === true ) echo "\n\n** success **\n";
|
2016-10-19 08:16:21 +00:00
|
|
|
else echo $err;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
/* (3) Disabled a package
|
2016-10-19 08:16:21 +00:00
|
|
|
---------------------------------------------------------*/
|
2016-12-12 00:45:59 +00:00
|
|
|
case 'remove': case 'r': {
|
2016-10-19 08:16:21 +00:00
|
|
|
|
|
|
|
if( $arglen < 2 ){
|
2016-12-05 18:54:19 +00:00
|
|
|
echo "You must specify @package.\n";
|
2016-10-19 08:16:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-05 18:54:19 +00:00
|
|
|
$err = $exporter->remove($arguments[1]);
|
2016-10-19 08:16:21 +00:00
|
|
|
|
|
|
|
/* (1) Managing state */
|
2016-12-05 13:42:38 +00:00
|
|
|
if( $err === true ) echo "\n\n** success **\n";
|
|
|
|
else echo $err;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
/* (3) Builds a project
|
|
|
|
---------------------------------------------------------*/
|
2016-12-12 00:45:59 +00:00
|
|
|
case 'build': case 'b': {
|
2016-12-05 13:42:38 +00:00
|
|
|
|
|
|
|
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";
|
2016-10-19 08:16:21 +00:00
|
|
|
else echo $err;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2017-09-07 18:18:04 +00:00
|
|
|
/* (4) Help message
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
default: {
|
|
|
|
|
|
|
|
echo "xfw: xdrm framework\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "COMMANDS\n";
|
|
|
|
echo "\tinit\n";
|
|
|
|
echo "\t\tInitialize a new framework environment.\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "\tpackages\n";
|
|
|
|
echo "\t\tList all available packages and its versions.\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "\tinstall @pkg_name:@version\n";
|
|
|
|
echo "\t\tAdd the version @version of the package @pkg_name to the environment.\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "\tremove @pkg_name\n";
|
|
|
|
echo "\t\tRemove the package @pkg_name from the environment.\n";
|
|
|
|
echo "\n";
|
|
|
|
echo "\tbuild @root_path\n";
|
|
|
|
echo "\t\tBuild from the environment at the location @root_path.\n";
|
|
|
|
echo "\n";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2016-10-19 08:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|