WIP have half of hg commands mapped

This commit is contained in:
Peter Cottle 2013-07-31 09:22:11 -07:00
parent 51e1cc2b77
commit a033173281
10 changed files with 817 additions and 27 deletions

View file

@ -4,6 +4,7 @@ var intl = require('../intl');
var Errors = require('../util/errors');
var GitCommands = require('../git/commands');
var MercurialCommands = require('../mercurial/commands');
var CommandProcessError = Errors.CommandProcessError;
var CommandResult = Errors.CommandResult;
@ -17,11 +18,45 @@ var commands = {
if (!commandConfigs[vcs][name]) {
throw new Error('i dont have a command for ' + name);
}
commandConfigs[vcs][name].execute.call(this, engine, commandObj);
console.log(commandObj.getSupportedMap());
console.log(commandObj.getGeneralArgs());
var config = commandConfigs[vcs][name];
if (config.delegate) {
return this.delegateExecute(config, engine, commandObj);
}
config.execute.call(this, engine, commandObj);
},
delegateExecute: function(config, engine, commandObj) {
// we have delegated to another vcs command, so lets
// execute that and get the result
var result = config.delegate.call(this, engine, commandObj);
if (result.multiDelegate) {
// we need to do multiple delegations with
// a different command at each step
_.each(result.multiDelegate, function(delConfig) {
// copy command, and then set opts
commandObj.setSupportedMap(delConfig.options || {});
commandObj.setGeneralArgs(delConfig.args || []);
commandConfigs[delConfig.vcs][delConfig.name].execute.call(this, engine, commandObj);
}, this);
} else {
config = commandConfigs[result.vcs][result.name];
// commandObj is PASSED BY REFERENCE
// and modified in the function
commandConfigs[result.vcs][result.name].execute.call(this, engine, commandObj);
}
},
blankMap: function() {
return {git: {}, hg: {}};
},
getShortcutMap: function() {
var map = {'git': {}, 'hg': {}};
var map = this.blankMap();
this.loop(function(config, name, vcs) {
if (!config.sc) {
return;
@ -32,7 +67,7 @@ var commands = {
},
getOptionMap: function() {
var optionMap = {'git': {}, 'hg': {}};
var optionMap = this.blankMap();
this.loop(function(config, name, vcs) {
var displayName = config.displayName || name;
var thisMap = {};
@ -46,7 +81,7 @@ var commands = {
},
getRegexMap: function() {
var map = {'git': {}, 'hg': {}};
var map = this.blankMap();
this.loop(function(config, name, vcs) {
var displayName = config.displayName || name;
map[vcs][displayName] = config.regex;
@ -58,7 +93,7 @@ var commands = {
* which commands count for the git golf game
*/
getCommandsThatCount: function() {
var counted = {'git': {}, 'hg': {}};
var counted = this.blankMap();
this.loop(function(config, name, vcs) {
if (config.dontCountForGolf) {
return;
@ -88,7 +123,13 @@ var parse = function(str) {
if (regex.exec(str)) {
vcs = thisVCS;
method = thisMethod;
options = str.slice(vcs.length + 1 + method.length + 1);
// every valid regex has to have the parts of
// <vcs> <command> <stuff>
// because there are always two spaces
// before our "stuff" we can simply
// split on spaces and grab everything after
// the second:
options = str.split(' ').slice(2).join(' ');
}
});
});