really basic option parsing

This commit is contained in:
Peter Cottle 2012-09-10 16:08:02 -07:00
parent 908b403c4b
commit 513315af3c
2 changed files with 32 additions and 10 deletions

View file

@ -14,6 +14,10 @@ function GitEngine() {
this.id_gen = 0; this.id_gen = 0;
this.branches = []; this.branches = [];
// global variable to keep track of the options given
// along with the command call.
this.currentOptions = {};
events.on('gitCommandReady', _.bind(this.dispatch, this)); events.on('gitCommandReady', _.bind(this.dispatch, this));
this.init(); this.init();
@ -95,17 +99,20 @@ GitEngine.prototype.makeCommit = function(parent) {
}; };
GitEngine.prototype.commit = function() { GitEngine.prototype.commit = function() {
var targetCommit = null; var targetCommit = this.getCommitFromRef(this.HEAD);
if (this.getDetachedHead()) { // if we want to ammend, go one above
// in detached head mode, must warn user TODO if (this.currentOptions['--amend']) {
targetCommit = this.HEAD.get('target'); targetCommit = this.resolveId('HEAD~1');
} else {
var targetBranch = this.HEAD.get('target');
targetCommit = targetBranch.get('target');
} }
var newCommit = this.makeCommit(targetCommit); var newCommit = this.makeCommit(targetCommit);
targetBranch.set('target', newCommit);
if (this.getDetachedHead()) {
events.trigger('commandProcessWarn', "Warning!! Detached HEAD state");
} else {
var targetBranch = this.HEAD.get('target');
targetBranch.set('target', newCommit);
}
}; };
GitEngine.prototype.resolveId = function(idOrTarget) { GitEngine.prototype.resolveId = function(idOrTarget) {
@ -255,8 +262,7 @@ GitEngine.prototype.deleteBranch = function(name) {
}; };
GitEngine.prototype.dispatch = function(commandObj) { GitEngine.prototype.dispatch = function(commandObj) {
// TODO: parse arguments as well this.currentOptions = commandObj.optionParser.supportedMap;
console.log(commandObj);
this[commandObj.method](); this[commandObj.method]();
}; };

View file

@ -69,6 +69,10 @@ var CommandLineHistoryView = Backbone.View.extend({
this.commandError, this this.commandError, this
)); ));
events.on('commandProcessWarn', _.bind(
this.commandWarn, this
));
events.on('commandResultPrint', _.bind( events.on('commandResultPrint', _.bind(
this.commandResultPrint, this this.commandResultPrint, this
)); ));
@ -111,6 +115,18 @@ var CommandLineHistoryView = Backbone.View.extend({
); );
}, },
commandWarn: function(msg) {
this.$('#commandDisplay').append(
_.template(
this.resultTemplate,
{
className: 'commandWarn',
result: msg
}
)
);
},
commandResultPrint: function(err) { commandResultPrint: function(err) {
if (!err.msg.length) { if (!err.msg.length) {
// blank lines // blank lines