/* webfan (C) Till Wehowski, Webfan.de - All rights reserved. */
'use strict';
function CompareVersion(v1, v2){
var _1 = v1.split('.');
var _2 = v2.split('.');
if(parseInt(_1[0]) < parseInt(_2[0]))return false;
if(parseInt(_1[1]) < parseInt(_2[1]))return false;
if(parseInt(_1[2]) < parseInt(_2[2]))return false;
return true;
}
var POS_SUBCMD = 1;
var POS_SIGNARG = 2;
var frdl = require('frdl');
var util = require('util');
var util_opts = {
showHidden : true,
depth : 4
};
var helper = require('http://'+frdl.route('HOST_CDN_PUBLIC_FRDL')+'/cdn/frdl/flow/components/frdl/webfan/js/helper');
var DBS = {
db : 'apc',
projects : 'projects',
packages : 'packages',
package_downloads : 'package_downloads'
};
var context = {
software_group : 'php'
};
var api_public = frdl.route('API_ENDPOINT');
var bounce = false;
var sub_command = false;
var first_significant_arg = false;
//tmp data
var _project = false;
var _projectID = false;
var _package = false;
var _packagefullname = false;
var _package_repository = false;
var _package_version = false;
var _taskGroup = false;
var sqlTask = frdl.task().ql;
var cliTask = frdl.task().cli;
var subCommands = {
'find' : {
description : 'Search for a php package in several composer repositries.',
fn : function(CLI){
var searchterm = first_significant_arg;
if(!searchterm){
CLI.error('You have to specify a searchterm as arg '+POS_SIGNARG);
return;
}
var api_url = api_public+'software/'+context.software_group+'/'+searchterm+'/search.json';
var eventKey = 'cmd.http-request:GET '+frdl.Sha1.hash(api_url);
CLI.finalState.add(eventKey);
$.ajax( {
url: api_url,
crossDomain: true,
cache:false,
headers: {'X-Requested-With': 'XMLHttpRequest'
},
type: 'GET',
dataType: 'json',
data: {
'ref' : 'frdl cli',
'-webkit-webfan' : frdl.nw
}
} )
.done(function(response) {
CLI.data.data = response.result.data;
})
.fail(function(jqXHR, textStatus) {
CLI.error('HTTP Error: ' + jqXHR.status +' (in response of '+api_url+')');
})
.always(function() {
CLI.emit(eventKey, 'complete');
});
},
prepare : function(CLI){
}
},
'get' : {
description : 'Get metainformations of a given php package from several composer repositries.',
fn : function(CLI){
var packagefullname = first_significant_arg;
if(!packagefullname){
CLI.error('You have to specify a packagefullname as arg '+POS_SIGNARG);
return;
}
var api_url = api_public+'software/'+context.software_group+'/'+packagefullname+'/package.json';
var eventKey = 'cmd.http-request:GET '+frdl.Sha1.hash(api_url);
CLI.finalState.add(eventKey);
$.ajax( {
url: api_url,
crossDomain: true,
cache:false,
headers: {'X-Requested-With': 'XMLHttpRequest'
},
type: 'GET',
dataType: 'json',
data: {
'ref' : 'frdl cli',
'-webkit-webfan' : frdl.nw
}
} )
.done(function(response) {
CLI.data.data = response.result.data;
})
.fail(function(jqXHR, textStatus) {
CLI.error('HTTP Error: ' + jqXHR.status +' (in response of '+api_url+')');
})
.always(function() {
CLI.emit(eventKey, 'complete');
});
},
prepare : function(CLI){
}
},
'add' : {
description : 'Add a php package to...',
fn : function(CLI){
var packagefullname = first_significant_arg;
var taskGroup = (false===_taskGroup) ? ('apc.package.add:' + packagefullname +'/'+_projectID+ ':'+frdl.Guid.newGuid()) : _taskGroup;
var priority = 3;
var group = frdl.task(taskGroup);
group.pause();
var _Project = false;
CLI.on('catch', function(err){
group.clearAll();
if(frdl.alert)frdl.alert.error(err, false, 0);
});
//todo...
if(!packagefullname){
CLI.error('You have to specify a packagefullname as arg '+POS_SIGNARG);
CLI.emit('catch', 'You have to specify a packagefullname as arg '+POS_SIGNARG);
return;
}
if(!_projectID){
CLI.error('You have to specify option --projectID=');
CLI.emit('catch', 'You have to specify option --projectID=');
return;
}
if(!_package_version){
CLI.error('You have to specify option --version=');
CLI.emit('catch', 'You have to specify option -version=');
return;
}
var api_url = api_public+'software/'+context.software_group+'/'+packagefullname+'/package.json';
var eventKey = 'cmd.http-request:GET '+frdl.Sha1.hash(api_url);
var eventKey_add_php_requirements_from_package_to_project_task = 'cmd.add_php_requirements_from_package_to_project_'+frdl.Sha1.hash(packagefullname+_projectID);
CLI.finalState.add(eventKey);
var eventKey_get_project = 'cmd.get_project_' + frdl.Sha1.hash(_projectID);
var eventKey_get_package = 'cmd.get_package_' + frdl.Sha1.hash(packagefullname);
var eventKey_add_package_to_project_sql_1 = 'cmd.add_package_to_project_sql_1_' + frdl.Sha1.hash(packagefullname);
CLI.finalState.add(eventKey_get_project);
CLI.finalState.add(eventKey_get_package);
CLI.finalState.add(eventKey_add_package_to_project_sql_1);
//.projects_required_php_packages (projectID, vendor, packagename, version)
var eventKey_add_package_to_project_sql_2 = 'cmd.add_package_to_project_sql_2_' + frdl.Sha1.hash(packagefullname);
CLI.finalState.add(eventKey_add_package_to_project_sql_2);
if(!_projectID){
CLI.emit('catch', 'No project specified');
return;
}
CLI.once(eventKey_get_package, function(___package){
CLI.finalState.add(eventKey_add_php_requirements_from_package_to_project_task);
var pn =frdl.explode('/', ___package.name,2);
frdl.task(taskGroup, 'schedule', new cliTask( 'DELETE FROM ' + DBS['db'] + '.projects_required_php_packages WHERE '
+ ' projectID='+frdl.ql_escape_string(_projectID)
+ ' AND vendor='+frdl.ql_escape_string(pn[0])
+ ' AND packagename='+frdl.ql_escape_string(pn[1]), function(err, resultset) {
if (err) {
// CLI.error(err);
// return;
}
}, (priority-priority)));
frdl.sql.query('SELECT * FROM ' + DBS['db'] + '.projects_required_php_packages WHERE '
+ ' projectID='+frdl.ql_escape_string(_projectID)
+ ' , vendor='+frdl.ql_escape_string(pn[0])
+ ' , packagename='+frdl.ql_escape_string(pn[1])
+ ' , version='+frdl.ql_escape_string(_package.version), function(err, resultset) {
if (err) {
CLI.error(err);
CLI.emit(eventKey_add_package_to_project_sql_2, false);
CLI.emit('catch', err);
return;
}
var row, _p=false;
if(0<resultset.data.length){
while((row = frdl.sql.fetch_object(resultset)) && row){
_p = row;
}
}
if(!_p){
// frdl.alert.error('@ToDo pm add (replace into, new package data...');
//(vendor, packagename, version_latest, last_time_fetched_composer, composer)
frdl.sql.query('INSERT INTO ' + DBS['db'] + '.projects_required_php_packages '
+' SET '
+ ' vendor='+frdl.ql_escape_string(pn[0])
+ ' ,packagename='+frdl.ql_escape_string(pn[1])
+ ' ,version='+frdl.ql_escape_string(_package_version)
+ ' ,projectID='+frdl.ql_escape_string(_projectID)
, function(e, r) {
if (e) {
console.warn(e);
return;
}
CLI.emit(eventKey_add_package_to_project_sql_2);
});
// }else if(false===!!CompareVersion(_p.version_latest, _package.version)){
}else if(_p && (!_package_version || !_p.version_latest || false===!!helper.changeVersion(_package_version, _p.version_latest))){
frdl.sql.query('UPDATE ' + DBS['db'] + '.projects_required_php_packages '
+' SET '
+ ' vendor='+frdl.ql_escape_string(pn[0])
+ ' ,packagename='+frdl.ql_escape_string(pn[1])
+ ' ,version='+frdl.ql_escape_string(_package_version)
+ ' ,projectID='+frdl.ql_escape_string(_projectID)
+ ' WHERE '
+ ' projectID='+frdl.ql_escape_string(_projectID)
+ ' AND vendor='+frdl.ql_escape_string(pn[0])
+ ' AND packagename='+frdl.ql_escape_string(pn[1])
+ ' LIMIT 1 '
, function(e, r) {
if (e) {
console.warn(e);
return;
}
CLI.emit(eventKey_add_package_to_project_sql_2);
});
}
CLI.emit(eventKey_add_php_requirements_from_package_to_project_task);
});
});
CLI.once(eventKey_get_project, function(___project){
_project = _Project = ___project;
$.ajax( {
url: api_url,
crossDomain: true,
cache:false,
headers: {'X-Requested-With': 'XMLHttpRequest'
},
type: 'GET',
dataType: 'json',
data: {
'ref' : 'frdl cli',
'-webkit-webfan' : frdl.nw
}
} )
.done(function(response) {
// CLI.data.data = response.result.data;
frdl.each(response.result.data, function(i,info){
if(_package_repository!==info.repository)return true;
var exc = true;
if(info.packageinfo && info.packageinfo.package && info.packageinfo.package.versions){
frdl.each(info.packageinfo.package.versions, function(version,v){
if(_package_version!==version && '*' !== _package_version && 'dev-master' !== _package_version)return true;
_package = v;
if('undefined'===typeof _package.extra){
_package.extra = {};
}
if('undefined'===typeof _package.frdl){
_package.frdl = true;
}
if('undefined'===typeof _package.apc){
_package.apc = {};
}
_package.apc.repository = info.repository;
exc = false;
var _pn =frdl.explode('/', _package.name,2);
var vendor = _pn[0];
var packname = _pn[1];
frdl.sql.query('SELECT * FROM ' + DBS['db'] + '.' + DBS['packages'] + ' WHERE '
+' vendor='+frdl.ql_escape_string(vendor)+' AND packagename='+frdl.ql_escape_string(packname)+' LIMIT 1 ', function(err, resultset) {
if (err) {
// console.error(err);
CLI.emit(eventKey_add_package_to_project_sql_1, false);
CLI.emit(eventKey_get_package, _package);
return;
}
var row, _p=false;
if(0<resultset.data.length){
while((row = frdl.sql.fetch_object(resultset)) && row){
var _p = row;
}
}
if(0===resultset.data.length || false===_p){
// frdl.alert.error('@ToDo pm add (replace into, new package data...');
//(vendor, packagename, version_latest, last_time_fetched_composer, composer)
frdl.sql.query('INSERT INTO ' + DBS['db'] + '.' + DBS['packages']
+' SET '
+ ' vendor='+frdl.ql_escape_string(vendor)
+ ' ,packagename='+frdl.ql_escape_string(packname)
+ ' ,version_latest='+frdl.ql_escape_string(_lastversion)
+ ' ,last_time_fetched_composer='+frdl.ql_escape_string(new Date().getTime())
+ ' ,composer='+frdl.ql_escape_string(composer)
, function(e, r) {
if (e) {
console.warn(e);
return;
}
});
// }else if(false===!!CompareVersion(_p.version_latest, _package.version)){
}else if(_p && false===!!helper.changeVersion(_package.version, _p.version_latest)){
frdl.sql.query('UPDATE ' + DBS['db'] + '.' + DBS['packages']
+' SET '
+ ' vendor='+frdl.ql_escape_string(vendor)
+ ' ,packagename='+frdl.ql_escape_string(packname)
+ ' ,version_latest='+frdl.ql_escape_string(_lastversion)
+ ' ,last_time_fetched_composer='+frdl.ql_escape_string(new Date().getTime())
+ ' ,composer='+frdl.ql_escape_string(composer)
+ ' WHERE '
+ ' vendor='+frdl.ql_escape_string(vendor)
+ ' AND packagename='+frdl.ql_escape_string(packname)
+ ' LIMIT 1 '
, function(e, r) {
if (e) {
console.warn(e);
return;
}
});
}
CLI.emit(eventKey_add_package_to_project_sql_1, _package);
CLI.emit(eventKey_get_package, _package);
});
return false;
});
}
return exc;
});
})
.fail(function(jqXHR, textStatus) {
CLI.error('HTTP Error: ' + jqXHR.status +' (in response of '+api_url+')');
})
.always(function() {
CLI.emit(eventKey, 'completed http for package');
});
});
//eond of CLI.on(eventKey_get_project)
frdl.task(taskGroup, 'schedule', new cliTask( 'SELECT * FROM ' + DBS.db
+ '.' +DBS.projects+ " WHERE id="+frdl.ql_escape_string(_projectID)
+ " LIMIT 1", function(err, data){
if(err || 0===data.data.length){
CLI.error((err || 'Project projectID='+_projectID+' does not exist'));
CLI.emit('catch');
return;
}
// if(0===data.data.length)return;
var row;
while((row = frdl.sql.fetch_object(data)) && row){
_project = _Project = row;
CLI.emit(eventKey_get_project, _Project);
}
}, (priority-2)));
// group.resume();
if(false!==_taskGroup) group.release();
group.resume();
},
prepare : function(CLI){
CLI.addOption('projectID', 'Add projectID', function(name, value) {
_projectID=value;
}, ' [TEXT]')
.addOption('repository', 'Choose repository (packagist || phpclasses)', function(name, value) {
_package_repository=value;
}, ' [TEXT]')
.addOption('version', 'Choose a package version (of selected package)', function(name, value) {
_package_version=value;
}, ' [TEXT]')
;
}
},
'config' : {
description : 'Apply foo to bar',
fn : function(CLI){
if(CLI._bufCom.subCmd){
CLI.finalState.add('cmd.fin.config.'+CLI._bufCom.subCmd);
}
CLI.addOption('projectID', 'Add projectID', function(name, value) {
_projectID=value;
}, ' [TEXT]')
.addOption('repository', 'Choose repository (packagist || phpclasses)', function(name, value) {
_package_repository=value;
}, ' [TEXT]')
.addOption('version', 'Choose a package version (of selected package)', function(name, value) {
_package_version=value;
}, ' [TEXT]')
;
;
}
},
'check-php-requirements' : {
description : 'check-php-requirements',
fn : function(CLI){
if(!CLI._bufCom._projectID){
CLI.emit('catch', 'You have to specify option --projectID=');
return;
}
CLI.data.data={
recordChanged : false,
nextbatch : [],
requiredPHPVersion : '0.0.0'
}
var taskGroup = (false===_taskGroup) ? ('check-php-requirements '+CLI._bufCom._projectID) : _taskGroup;
var group = frdl.task(taskGroup);
group.pause();
CLI.once('success', function(rdata){
var group = frdl.task(taskGroup);
group.pause();
frdl.each(rdata.nextbatch, function(i, _cmd){
frdl.task(taskGroup, 'schedule', new cliTask(_cmd, function(_err, data){
if(_err){
return;
}
}, 1000 + i)) ;
});
group.resume();
});
var _sIDv = 'cmd.fin.check-php-requirements.get-php-version-required-initial';
CLI.finalState.add(_sIDv);
frdl.task(taskGroup, 'schedule', new cliTask( 'SELECT * FROM ' + DBS.db + '.projects_required_php_version WHERE '
+' projectID='+frdl.ql_escape_string(CLI._bufCom._projectID)
+ ' LIMIT 1 ', function(err, data){
if(err){
CLI.emit('catch', err);
return;
}
var row;
while((row = frdl.sql.fetch_object(data)) && row){
CLI.data.data.requiredPHPVersion=row.version;
}
CLI.emit(_sIDv, CLI.data.data.requiredPHPVersion);
}, 0));
CLI.once(_sIDv, function(){
frdl.task(taskGroup, 'schedule',
(function(){
frdl.sql.query('SELECT * FROM ' + DBS.db + '.projects_required_php_packages WHERE '
+ ' projectID='+frdl.ql_escape_string(CLI._bufCom._projectID)
, function(err, _resultset) {
if (err) {
CLI.emit('catch', err);
return;
}
var _row;
if(0<_resultset.data.length){
while((_row = frdl.sql.fetch_object(_resultset)) && _row){
// frdl.alert.success('add package: '+ util.inspect(row, util_opts), 0);
var _required = _row.vendor + '/' + _row.packagename;
var _required_version = _row.version;
var vendor = _row.vendor;
var packname = _row.packagename;
var extension = false;
var _ex = frdl.explode('-',vendor,2);
if(1<_ex.length && 'ext'===_ex[0]){
extension=_ex[1];
}
if(false!==!!packname && false===!!extension){
frdl.sql.query('SELECT * FROM ' + DBS['db'] + '.' + DBS['packages'] + ' WHERE '
+ ' vendor='+frdl.ql_escape_string(vendor)
+ ' AND packagename='+frdl.ql_escape_string(packname)
+ ' LIMIT 1'
, function(err, resultset) {
if (err) {
CLI.emit('catch', err);
return;
}
var row;
var row, _p=false;
if(0<resultset.data.length){
while((row = frdl.sql.fetch_object(resultset)) && row){
var _p = row;
_p.composer = JSON.parse(frdl.base64_decode(_p.composer));
if(_p.composer.require && true==frdl.isTraversable(_p.composer.require) ){
frdl.each(_p.composer.require, function(___requiredName, ___requiredVersion){
var __n = frdl.explode('/', ___requiredName, 2);
if('php'===___requiredName){
if(false===!!helper.changeVersion(___requiredVersion, CLI.data.data.requiredPHPVersion)){
CLI.data.data.requiredPHPVersion=___requiredVersion;
var cmd = 'pm config --set="php" version --version='+frdl.ql_escape_string(CLI.data.data.requiredPHPVersion);
cmd+=' --projectID='+frdl.ql_escape_string(CLI._bufCom._projectID);
cmd +=' --task='+frdl.ql_escape_string(frdl.base64_encode(taskGroup));
frdl.task(taskGroup, 'schedule', new cliTask(cmd, function(_err, d){
if(_err){
CLI.error(_err);
return;
}
}, 0));
}
} else if(2===__n.length && ( 0 === _resultset.data.length || false===!!helper.changeVersion(___requiredVersion, CLI.data.data.requiredPHPVersion))){
var cmd = 'pm add ' + ___requiredName;
cmd+=' --projectID='+frdl.ql_escape_string(CLI._bufCom._projectID);
cmd+=' --repository='+frdl.ql_escape_string('*');
cmd+=' --version='+frdl.ql_escape_string(___requiredVersion);
cmd +=' --task='+frdl.ql_escape_string(frdl.base64_encode(taskGroup));
var _sID = 'cmd.fin.check-php-requirements.'+ frdl.Sha1.hash(cmd);
CLI.finalState.add(_sID);
frdl.task(taskGroup, 'schedule', new cliTask(cmd, function(_err, d){
CLI.emit(_sID, _err || d);
if(_err){
CLI.error(_err);
return;
}
// alert('Test: '+util.inspect(d, util_opts));
}, 1000));
}
});
}
}
}
if(0===resultset.data.length
|| (false!==_p && _required_version !== _p.version && false===!!helper.changeVersion(_required_version, _p.version))
){
var cmd = 'pm add ' + _required;
cmd+=' --projectID='+frdl.ql_escape_string(CLI._bufCom._projectID);
cmd+=' --repository='+frdl.ql_escape_string('*');
cmd+=' --version='+frdl.ql_escape_string(_required_version);
cmd +=' --task='+frdl.ql_escape_string(frdl.base64_encode(taskGroup));
var _sID2 = 'cmd.fin.check-php-requirements.'+ frdl.Sha1.hash(cmd);
CLI.finalState.add(_sID2);
frdl.task(taskGroup, 'schedule', new cliTask(cmd, function(_err, data){
CLI.emit(_sID2, _err || data);
if(_err){
CLI.error(_err);
return;
}
if(false===!!CLI.data.data.recordChanged){
CLI.data.data.recordChanged = true;
var n_cmd = 'pm check-php-requirements --projectID=' + frdl.ql_escape_string(CLI._bufCom._projectID);
n_cmd +=' --task='+frdl.ql_escape_string(frdl.base64_encode(taskGroup));
if(-1===CLI.data.data.nextbatch.indexOf(n_cmd)){
CLI.data.data.nextbatch.push(n_cmd);
}
}
}, 3));
}
});
}else if(false!==!!extension){
var _sID3 = 'cmd.fin.check-php-requirements.ext.'+ frdl.Sha1.hash(extension + CLI._bufCom._projectID);
CLI.finalState.add(_sID3);
frdl.sql.query('SELECT * FROM ' + DBS.db + '.projects_required_php_ext WHERE '
+' projectID='+frdl.ql_escape_string(CLI._bufCom._projectID)
+' AND ext='+frdl.ql_escape_string(extension)
+ ' LIMIT 1 '
, function(err, resultset) {
if (err) {
CLI.emit('catch', err);
return;
}
var row, _e=false;
if(0<resultset.data.length){
while((row = frdl.sql.fetch_object(resultset)) && row){
var _e = row;
}
}
if(0===resultset.data.length){
frdl.sql.query('INSERT INTO ' + DBS.db + '.projects_required_php_ext '
+' SET '
+ ' projectID='+frdl.ql_escape_string(CLI._bufCom._projectID)
+', ext='+frdl.ql_escape_string(extension)
+ ',version='+frdl.ql_escape_string(_required_version)
, function(e, r) {
if (e) {
CLI.emit('catch', e);
return;
}
CLI.emit(_sID3, e || r);
});
}else if(false!==_e){
var newExtVer = (false===!!helper.changeVersion(_required_version, _e.version))
? _required_version
: _e.version;
frdl.sql.query('UPDATE ' + DBS.db + '.projects_required_php_ext '
+' SET '
+ ' version='+frdl.ql_escape_string(newExtVer)
+' WHERE '
+' projectID='+frdl.ql_escape_string(CLI._bufCom[CLI._bufCom.subCmd].projectID)
+' AND ext='+frdl.ql_escape_string(extension)
+ ' LIMIT 1 '
, function(e, r) {
if (e) {
CLI.emit('catch', e);
return;
}
CLI.emit(_sID3, e || r);
});
}
});
}
}
}
});
}),1);
});// CLI.on(_sIDv)//get init php version
try{
if(false!==_taskGroup) group.release();
} catch(err){
}
try{
group.resume();
} catch(err){
}
CLI.emit('cmd.fin.check-php-requirements');
},
prepare : function(CLI){
CLI.finalState.add('cmd.fin.check-php-requirements');
CLI.addOption('projectID', 'refer projectID', function(name, value) {
CLI._bufCom._projectID=value;
}, ' [TEXT]')
;
}
}
};
exports.finalize = function(){
var CLI = this;
if(false===sub_command || 'undefined' === typeof subCommands[sub_command]){
var _subCommands =[];
var subc;
for(subc in subCommands) {
_subCommands.push(subc);
}
CLI.error('The pm command requires a subcommand as nextarg, one of:\n' + _subCommands.join(', '));
CLI.emit('cmd.get-subcommand', false);
CLI.emit('cmd.finalize-subcommand', false);
CLI.emit('cmd.finalized', false);
return;
}
try{
frdl.c('CREATE TABLE IF NOT EXISTS ' + DBS['db'] + '.' + DBS['packages'] + ' (vendor, packagename, version_latest, last_time_fetched_composer, composer)', function(err, data){
if(err){
return;
}
frdl.c('ALTER TABLE ' + DBS['db'] + '.' + DBS['packages'] + ' ADD PRIMARY KEY ( vendor, packagename )');
}, true, CLI);
}catch(err){
//console.warn(err);
}
try{
frdl.c('CREATE TABLE IF NOT EXISTS ' + DBS['db'] + '.' + DBS['package_downloads'] + ' (vendor, packagename, version, time_last_download, zip, file, dir)', function(err, data){
if(err){
return;
}
frdl.c('ALTER TABLE ' + DBS['db'] + '.' + DBS['package_downloads'] + ' ADD PRIMARY KEY ( vendor, packagename, version )');
}, true, CLI);
}catch(err){
//console.warn(err);
}
try{
frdl.c('CREATE TABLE IF NOT EXISTS ' + DBS['db'] + '.projects_required_php_version (projectID, version)', function(err, data){
if(err){
return;
}
frdl.c('ALTER TABLE ' + DBS['db'] + '.projects_required_php_version ADD PRIMARY KEY ( projectID )');
}, true, CLI);
}catch(err){
// console.warn(err);
}
try{
frdl.c('CREATE TABLE IF NOT EXISTS ' + DBS['db'] + '.projects_required_php_packages (projectID, vendor, packagename, version)', function(err, data){
if(err){
return;
}
frdl.c('ALTER TABLE ' + DBS['db'] + '.projects_required_php_packages ADD PRIMARY KEY ( projectID, vendor, packagename )');
}, true, CLI);
}catch(err){
//console.warn(err);
}
try{
frdl.c('CREATE TABLE IF NOT EXISTS ' + DBS['db'] + '.projects_required_php_ext (projectID, ext, version)', function(err, data){
if(err){
return;
}
frdl.c('ALTER TABLE ' + DBS['db'] + '.projects_required_php_ext ADD PRIMARY KEY ( projectID, ext )');
}, true, CLI);
}catch(err){
//console.warn(err);
}
CLI.emit('cmd.finalize-subcommand', sub_command);
CLI.emit('cmd.finalized', CLI.data.data);
};
exports.prepare = function(CLI){
CLI._bufCom = {
};
CLI.finalState.add('cmd.finalized');
CLI.finalState.add('cmd.get-subcommand');
CLI.finalState.add('cmd.finalize-subcommand');
sub_command = ('undefined'!==typeof CLI.argv[1] ) ? CLI.argv[1] : false;
// CLI.once('cmd.get-subcommand', function(subcmd){
// if(false===subcmd)return;
// if('undefined'!==typeof subCommands[subcmd] && 'function'===typeof subCommands[subcmd].prepare){
// subCommands[subcmd].prepare.apply(CLI,[CLI]);
// }
// });
if(false !== sub_command && 'undefined'!==typeof subCommands[sub_command] && 'function'===typeof subCommands[sub_command].prepare){
subCommands[sub_command].prepare.apply(CLI,[CLI]);
} else{
// frdl.alert.log(util.inspect(CLI.argv, util_opts), false, 0);
}
CLI.once('cmd.finalize-subcommand', function(subcmd){
if(false===subcmd)return;
if('undefined'!==typeof subCommands[subcmd] && 'function'===typeof subCommands[subcmd].fn){
subCommands[subcmd].fn.apply(CLI,[CLI]);
}
});
// CLI.addToken('pm', '*', function(c, result_length, token, current_option){
// sub_command = token;
// CLI.emit('cmd.get-subcommand', sub_command);
// });
var parse_second_arg_as_sub_command = function(value){
sub_command = value;
CLI.emit('cmd.get-subcommand', sub_command);
};
var parse_third_arg_as_first_significant_arg = function(value){
first_significant_arg = value;
CLI.emit('cmd.get-first-significant-arg', first_significant_arg);
};
CLI.positionalSwitches[POS_SUBCMD] = parse_second_arg_as_sub_command;
CLI.positionalSwitches[POS_SIGNARG] = parse_third_arg_as_first_significant_arg;
CLI.addOption('db', 'Add databsesetting in form of key:value', function(name, value) {
var kv = frdl.explode(':', value);
if(2===kv.length)DBS[kv[0]]=kv[1] || false;
}, ' [DBSETTING]')
.filter('DBSETTING', function(value) {
var kv = frdl.explode(':', value);
return (2===kv.length && 'undefined'!==typeof DBS[kv[0]]) ? value : undefined;
})
.addOption('softgroup', 'Select a context.software-group', function(name, value) {
context.software_group = value;
}, ' [SOFTWAREGROUP]')
.filter('SOFTWAREGROUP', function(value) {
var groups = ['php', 'js', 'npm', 'widget', 'browser', 'install'];
return (-1 !== groups.indexOf(value)) ? value : undefined;
})
.addOption('bounce', 'Prefer apc client API rather than public Webfan.de API while this request', function(name, value) {
bounce=value;
}, ' [SWITCH]', '-b')
;
CLI .addOption('task', 'Apply an task-ID', function(name, value) {
_taskGroup=frdl.base64_decode(value);
CLI.once('catch', function(err){
try{
frdl.task(_taskGroup).clearAll();
}catch(e){
}
});
}, ' [TEXT]')
;
};
|