mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-26 07:58:34 +02:00
moving command fucntionality
This commit is contained in:
parent
1aa9d76a8b
commit
a9d14521de
4 changed files with 303 additions and 285 deletions
|
@ -1,5 +1,11 @@
|
|||
var _ = require('underscore');
|
||||
|
||||
var Errors = require('../util/errors');
|
||||
var CommandProcessError = Errors.CommandProcessError;
|
||||
var GitError = Errors.GitError;
|
||||
var Warning = Errors.Warning;
|
||||
var CommandResult = Errors.CommandResult;
|
||||
|
||||
var getRegexMap = function() {
|
||||
return {
|
||||
// ($|\s) means that we either have to end the string
|
||||
|
@ -40,5 +46,94 @@ var expandShortcut = function(commandStr) {
|
|||
return commandStr;
|
||||
};
|
||||
|
||||
/**
|
||||
* GitOptionParser
|
||||
*/
|
||||
function GitOptionParser(method, options) {
|
||||
this.method = method;
|
||||
this.rawOptions = options;
|
||||
|
||||
this.supportedMap = this.getMasterOptionMap()[method];
|
||||
if (this.supportedMap === undefined) {
|
||||
throw new Error('No option map for ' + method);
|
||||
}
|
||||
|
||||
this.generalArgs = [];
|
||||
this.explodeAndSet();
|
||||
}
|
||||
|
||||
GitOptionParser.prototype.getMasterOptionMap = function() {
|
||||
// here a value of false means that we support it, even if its just a
|
||||
// pass-through option. If the value is not here (aka will be undefined
|
||||
// when accessed), we do not support it.
|
||||
return {
|
||||
commit: {
|
||||
'--amend': false,
|
||||
'-a': false, // warning
|
||||
'-am': false, // warning
|
||||
'-m': false
|
||||
},
|
||||
status: {},
|
||||
log: {},
|
||||
add: {},
|
||||
'cherry-pick': {},
|
||||
branch: {
|
||||
'-d': false,
|
||||
'-D': false,
|
||||
'-f': false,
|
||||
'--contains': false
|
||||
},
|
||||
checkout: {
|
||||
'-b': false,
|
||||
'-B': false,
|
||||
'-': false
|
||||
},
|
||||
reset: {
|
||||
'--hard': false,
|
||||
'--soft': false // this will raise an error but we catch it in gitEngine
|
||||
},
|
||||
merge: {},
|
||||
rebase: {
|
||||
'-i': false // the mother of all options
|
||||
},
|
||||
revert: {},
|
||||
show: {}
|
||||
};
|
||||
};
|
||||
|
||||
GitOptionParser.prototype.explodeAndSet = function() {
|
||||
// split on spaces, except when inside quotes
|
||||
|
||||
var exploded = this.rawOptions.match(/('.*?'|".*?"|\S+)/g) || [];
|
||||
|
||||
for (var i = 0; i < exploded.length; i++) {
|
||||
var part = exploded[i];
|
||||
if (part.slice(0,1) == '-') {
|
||||
// it's an option, check supportedMap
|
||||
if (this.supportedMap[part] === undefined) {
|
||||
throw new CommandProcessError({
|
||||
msg: 'The option "' + part + '" is not supported'
|
||||
});
|
||||
}
|
||||
|
||||
// go through and include all the next args until we hit another option or the end
|
||||
var optionArgs = [];
|
||||
var next = i + 1;
|
||||
while (next < exploded.length && exploded[next].slice(0,1) != '-') {
|
||||
optionArgs.push(exploded[next]);
|
||||
next += 1;
|
||||
}
|
||||
i = next - 1;
|
||||
|
||||
// **phew** we are done grabbing those. theseArgs is truthy even with an empty array
|
||||
this.supportedMap[part] = optionArgs;
|
||||
} else {
|
||||
// must be a general arg
|
||||
this.generalArgs.push(part);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.getRegexMap = getRegexMap;
|
||||
exports.expandShortcut = expandShortcut;
|
||||
exports.GitOptionParser = GitOptionParser;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue