forked from c9/cloud9
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
103 lines (88 loc) · 2.8 KB
/
Copy pathindex.js
File metadata and controls
103 lines (88 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Git Shell Module for the Cloud9 IDE
*
* @copyright 2010, Ajax.org B.V.
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
*/
var Plugin = require("cloud9/plugin");
var sys = require("sys");
var ShellGitPlugin = module.exports = function(ide) {
this.ide = ide;
this.hooks = ["command"];
this.name = "git";
};
sys.inherits(ShellGitPlugin, Plugin);
(function() {
var githelp = "",
commandsMap = {
"default": {
"commands": {
"[PATH]": {"hint": "path pointing to a folder or file. Autocomplete with [TAB]"}
}
}
};
this.$commandHints = function(commands, message, callback) {
var _self = this;
if (!githelp) {
this.spawnCommand("git", null, message.cwd, null, null, function(code, err, out) {
if (!out)
return callback();
githelp = {"git": {
"hint": "the stupid content tracker",
"commands": {}
}};
out.replace(/[\s]{3,4}([\w]+)[\s]+(.*)\n/gi, function(m, sub, hint) {
githelp.git.commands[sub] = _self.augmentCommand(sub, {"hint": hint});
});
onfinish();
});
}
else {
onfinish();
}
function onfinish() {
_self.extend(commands, githelp);
callback();
}
};
this.augmentCommand = function(cmd, struct) {
var map = commandsMap[cmd] || commandsMap["default"];
return this.extend(struct, map || {});
};
this.command = function(user, message, client) {
if (message.command != "git")
return false;
var _self = this;
var argv = message.argv || [];
this.spawnCommand(message.command, argv.slice(1), message.cwd,
function(err) { // Error
_self.sendResult(0, message.command, {
code: 0,
argv: message.argv,
err: err,
out: null
});
},
function(out) { // Data
_self.sendResult(0, message.command, {
code: 0,
argv: message.argv,
err: null,
out: out
});
},
function(code, err, out) {
_self.sendResult(0, message.command, {
code: code,
argv: message.argv,
err: null,
out: null
});
});
return true;
};
this.dispose = function(callback) {
// TODO kill all running processes!
callback();
};
}).call(ShellGitPlugin.prototype);