mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 01:10:04 +02:00
ok disbaled map is now just instants
This commit is contained in:
parent
4046916432
commit
4aeb56c840
6 changed files with 77 additions and 188 deletions
|
@ -5,6 +5,8 @@ var Constants = require('../util/constants');
|
|||
var Views = require('../views');
|
||||
var util = require('../util');
|
||||
var Command = require('../models/commandModel').Command;
|
||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||
var DisabledMap = require('../level/disabledMap').DisabledMap;
|
||||
|
||||
/**
|
||||
* Globals
|
||||
|
@ -112,6 +114,9 @@ function CommandUI() {
|
|||
collection: this.commandCollection
|
||||
});
|
||||
|
||||
this.parseWaterfall = new ParseWaterfall();
|
||||
this.parseWaterfall.addFirst('instantWaterfall', new DisabledMap().getInstantCommands());
|
||||
|
||||
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
|
||||
}
|
||||
|
||||
|
@ -119,7 +124,8 @@ CommandUI.prototype.commandSubmitted = function(value) {
|
|||
events.trigger('commandSubmittedPassive', value);
|
||||
util.splitTextCommand(value, function(command) {
|
||||
this.commandCollection.add(new Command({
|
||||
rawStr: command
|
||||
rawStr: command,
|
||||
parseWaterfall: this.parseWaterfall
|
||||
}));
|
||||
}, this);
|
||||
};
|
||||
|
|
|
@ -71,7 +71,7 @@ var parse = function(str) {
|
|||
_.each(regexMap, function(regex, thisMethod) {
|
||||
if (regex.exec(str)) {
|
||||
options = str.slice(thisMethod.length + 1);
|
||||
method = thisMethod;
|
||||
method = thisMethod.slice('git '.length);
|
||||
}
|
||||
}, this);
|
||||
|
||||
|
|
|
@ -6,9 +6,10 @@ var Errors = require('../util/errors');
|
|||
var GitError = Errors.GitError;
|
||||
|
||||
function DisabledMap(options) {
|
||||
options = options || {};
|
||||
this.disabledMap = options.disabledMap || {
|
||||
'cherry-pick': true,
|
||||
'rebase': true
|
||||
'git cherry-pick': true,
|
||||
'git rebase': true
|
||||
};
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
var _ = require('underscore');
|
||||
|
||||
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:
|
||||
~ A disabled map (to prevent certain git commands from firing)
|
||||
~ A post-git command hook (to compare the git tree against the solution)
|
||||
~ Extra level-specific commands (like help, hint, etc) that are async
|
||||
**/
|
||||
|
||||
function InputWaterfall(options) {
|
||||
options = options || {};
|
||||
this.listenEvent = options.listenEvent || 'processCommand';
|
||||
this.disabledMap = options.disabledMap || {
|
||||
'git cherry-pick': true,
|
||||
'git rebase': true
|
||||
};
|
||||
|
||||
this.listen();
|
||||
}
|
||||
|
||||
InputWaterfall.prototype.listen = function() {
|
||||
Main.getEvents().on(this.listenEvent, this.process, this);
|
||||
};
|
||||
|
||||
InputWaterfall.prototype.mute = function() {
|
||||
Main.getEvents().off(this.listenEvent, this.process, this);
|
||||
};
|
||||
|
||||
InputWaterfall.prototype.process = function(command, callback) {
|
||||
|
||||
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) {
|
||||
Errors.filterError(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.regexMap;
|
||||
|
||||
_.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;
|
||||
|
|
@ -5,6 +5,7 @@ var SandboxCommands = require('../level/SandboxCommands');
|
|||
|
||||
// more or less a static class
|
||||
function ParseWaterfall(options) {
|
||||
options = options || {};
|
||||
this.shortcutWaterfall = options.shortcutWaterfall || [
|
||||
GitCommands.shortcutMap
|
||||
];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue