YAY looking a lot better, need to do rest of filter error

This commit is contained in:
Peter Cottle 2012-12-25 18:27:50 -08:00
parent 01fb9ec25b
commit 82d9e7a223
5 changed files with 222 additions and 45 deletions

View file

@ -2,6 +2,13 @@ var _ = require('underscore');
var Backbone = require('backbone');
var Main = require('../app');
var GitCommands = require('../git/commands');
var Errors = require('../util/errors');
var CommandProcessError = Errors.CommandProcessError;
var GitError = Errors.GitError;
var Warning = Errors.Warning;
var CommandResult = Errors.CommandResult;
/**
* This class supports a few things we need for levels:
@ -13,7 +20,10 @@ var Main = require('../app');
function InputWaterfall(options) {
options = options || {};
this.listenEvent = options.listenEvent || 'processCommand';
this.disabledMap = options.disabledMap || {};
this.disabledMap = options.disabledMap || {
'git cherry-pick': true,
'git rebase': true
};
console.log('made');
@ -29,10 +39,51 @@ InputWaterfall.prototype.mute = function() {
};
InputWaterfall.prototype.process = function(command, callback) {
console.log('processing');
console.log('processing', command.get('rawStr'));
if (this.checkDisabledMap(command)) {
callback();
return;
}
// for now, just immediately fire it
Main.getEvents().trigger('processGitCommand', command, callback);
};
InputWaterfall.prototype.sliceGitOff = function(str) {
return str.slice('git '.length);
}
InputWaterfall.prototype.checkDisabledMap = function(command) {
try {
this.loopDisabledMap(command);
} catch(err) {
command.set('error', err);
return true;
}
// not needed explicitly, but included for clarity
return false;
};
InputWaterfall.prototype.loopDisabledMap = function(command) {
var toTest = this.sliceGitOff(command.get('rawStr'));
var regexMap = GitCommands.getRegexMap();
_.each(this.disabledMap, function(val, disabledGitCommand) {
disabledGitCommand = this.sliceGitOff(disabledGitCommand);
var regex = regexMap[disabledGitCommand];
if (!regex) {
console.warn('wut, no regex for command', disabledGitCommand);
return;
}
if (regex.test(toTest)) {
throw new GitError({
msg: 'That git command is disabled for this level!'
});
}
}, this);
};
exports.InputWaterfall = InputWaterfall;