coa 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- package/.npmignore +6 -0
- package/.nyc_output/1f2a0db5a6d6559149db56d397f47cfc.json +1 -0
- package/.nyc_output/75b82d38f2186df930141082076e11c6.json +1 -0
- package/.travis.yml +9 -0
- package/GNUmakefile +34 -0
- package/README.md +1 -19
- package/coverage/base.css +212 -0
- package/coverage/coa/index.html +93 -0
- package/coverage/coa/index.js.html +68 -0
- package/coverage/coa/lib/arg.js.html +239 -0
- package/coverage/coa/lib/cmd.js.html +1556 -0
- package/coverage/coa/lib/coaobject.js.html +365 -0
- package/coverage/coa/lib/coaparam.js.html +440 -0
- package/coverage/coa/lib/color.js.html +131 -0
- package/coverage/coa/lib/completion.js.html +593 -0
- package/coverage/coa/lib/index.html +197 -0
- package/coverage/coa/lib/index.js.html +107 -0
- package/coverage/coa/lib/opt.js.html +524 -0
- package/coverage/coa/lib/shell.js.html +107 -0
- package/coverage/index.html +106 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +1 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +158 -0
- package/index.js +1 -1
- package/lib/arg.js +161 -44
- package/lib/cmd.js +547 -434
- package/lib/color.js +22 -19
- package/lib/completion.js +119 -161
- package/lib/index.js +10 -14
- package/lib/opt.js +313 -130
- package/lib/shell.js +13 -13
- package/package.json +14 -19
- package/qq.js +17 -0
- package/src/arg.coffee +130 -0
- package/src/cmd.coffee +456 -0
- package/src/color.coffee +25 -0
- package/src/completion.coffee +156 -0
- package/src/index.coffee +5 -0
- package/src/opt.coffee +243 -0
- package/src/shell.coffee +10 -0
- package/test/coa.js +496 -0
- package/test/mocha.opts +2 -0
- package/test/shell-test.js +60 -0
- package/tests/api-h.js +9 -0
- package/tests/h.js +6 -0
- package/LICENSE +0 -21
- package/lib/coaobject.js +0 -100
- package/lib/coaparam.js +0 -125
package/lib/color.js
CHANGED
@@ -1,22 +1,25 @@
|
|
1
|
-
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
2
|
+
var colors;
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
4
|
+
colors = {
|
5
|
+
black: '30',
|
6
|
+
dgray: '1;30',
|
7
|
+
red: '31',
|
8
|
+
lred: '1;31',
|
9
|
+
green: '32',
|
10
|
+
lgreen: '1;32',
|
11
|
+
brown: '33',
|
12
|
+
yellow: '1;33',
|
13
|
+
blue: '34',
|
14
|
+
lblue: '1;34',
|
15
|
+
purple: '35',
|
16
|
+
lpurple: '1;35',
|
17
|
+
cyan: '36',
|
18
|
+
lcyan: '1;36',
|
19
|
+
lgray: '37',
|
20
|
+
white: '1;37'
|
20
21
|
};
|
21
22
|
|
22
|
-
|
23
|
+
exports.Color = function(c, str) {
|
24
|
+
return ['\x1B[', colors[c], 'm', str, '\x1B[m'].join('');
|
25
|
+
};
|
package/lib/completion.js
CHANGED
@@ -1,176 +1,134 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const constants = require('constants');
|
4
|
-
const fs = require('fs');
|
5
|
-
const path = require('path');
|
6
|
-
|
7
|
-
const Q = require('q');
|
8
|
-
|
9
|
-
const shell = require('./shell');
|
10
|
-
const escape = shell.escape;
|
11
|
-
const unescape = shell.unescape;
|
12
|
-
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
13
2
|
/**
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
* @returns {COA.CoaObject}
|
18
|
-
*/
|
19
|
-
module.exports = function completion() {
|
20
|
-
return this
|
21
|
-
.title('Shell completion')
|
22
|
-
.helpful()
|
23
|
-
.arg()
|
24
|
-
.name('raw')
|
25
|
-
.title('Completion words')
|
26
|
-
.arr()
|
27
|
-
.end()
|
28
|
-
.act((opts, args) => {
|
29
|
-
if(process.platform === 'win32') {
|
30
|
-
const e = new Error('shell completion not supported on windows');
|
31
|
-
e.code = 'ENOTSUP';
|
32
|
-
e.errno = constants.ENOTSUP;
|
33
|
-
return this.reject(e);
|
34
|
-
}
|
3
|
+
Most of the code adopted from the npm package shell completion code.
|
4
|
+
See https://github.com/isaacs/npm/blob/master/lib/completion.js
|
5
|
+
*/
|
35
6
|
|
36
|
-
|
37
|
-
if((process.env.COMP_CWORD == null)
|
38
|
-
|| (process.env.COMP_LINE == null)
|
39
|
-
|| (process.env.COMP_POINT == null)) {
|
40
|
-
return dumpScript(this._cmd._name);
|
41
|
-
}
|
7
|
+
var Q, complete, dumpScript, escape, getOpts, unescape;
|
42
8
|
|
43
|
-
|
44
|
-
console.error('COMP_CWORD: %s', process.env.COMP_CWORD);
|
45
|
-
console.error('COMP_POINT: %s', process.env.COMP_POINT);
|
46
|
-
console.error('args: %j', args.raw);
|
9
|
+
Q = require('q');
|
47
10
|
|
48
|
-
|
49
|
-
opts = getOpts(args.raw);
|
11
|
+
escape = require('./shell').escape;
|
50
12
|
|
51
|
-
|
52
|
-
const parsed = this._cmd._parseCmd(opts.partialWords);
|
53
|
-
return Q.when(complete(parsed.cmd, parsed.opts), compls => {
|
54
|
-
console.error('filtered: %j', compls);
|
55
|
-
return console.log(compls.map(escape).join('\n'));
|
56
|
-
});
|
57
|
-
});
|
58
|
-
};
|
59
|
-
|
60
|
-
function dumpScript(name) {
|
61
|
-
const defer = Q.defer();
|
13
|
+
unescape = require('./shell').unescape;
|
62
14
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
15
|
+
module.exports = function() {
|
16
|
+
return this.title('Shell completion').helpful().arg().name('raw').title('Completion words').arr().end().act(function(opts, args) {
|
17
|
+
var argv, cmd, e, _ref;
|
18
|
+
if (process.platform === 'win32') {
|
19
|
+
e = new Error('shell completion not supported on windows');
|
20
|
+
e.code = 'ENOTSUP';
|
21
|
+
e.errno = require('constants').ENOTSUP;
|
22
|
+
return this.reject(e);
|
23
|
+
}
|
24
|
+
if ((process.env.COMP_CWORD == null) || (process.env.COMP_LINE == null) || (process.env.COMP_POINT == null)) {
|
25
|
+
return dumpScript(this._cmd._name);
|
26
|
+
}
|
27
|
+
console.error('COMP_LINE: %s', process.env.COMP_LINE);
|
28
|
+
console.error('COMP_CWORD: %s', process.env.COMP_CWORD);
|
29
|
+
console.error('COMP_POINT: %s', process.env.COMP_POINT);
|
30
|
+
console.error('args: %j', args.raw);
|
31
|
+
opts = getOpts(args.raw);
|
32
|
+
_ref = this._cmd._parseCmd(opts.partialWords), cmd = _ref.cmd, argv = _ref.argv;
|
33
|
+
return Q.when(complete(cmd, opts), function(compls) {
|
34
|
+
console.error('filtered: %j', compls);
|
35
|
+
return console.log(compls.map(escape).join('\n'));
|
69
36
|
});
|
37
|
+
});
|
38
|
+
};
|
70
39
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
if(err.errno !== constants.EPIPE) return defer.reject(err);
|
40
|
+
dumpScript = function(name) {
|
41
|
+
var defer, fs, path;
|
42
|
+
fs = require('fs');
|
43
|
+
path = require('path');
|
44
|
+
defer = Q.defer();
|
45
|
+
fs.readFile(path.resolve(__dirname, 'completion.sh'), 'utf8', function(err, d) {
|
46
|
+
var onError;
|
47
|
+
if (err) {
|
48
|
+
return defer.reject(err);
|
49
|
+
}
|
50
|
+
d = d.replace(/{{cmd}}/g, path.basename(name)).replace(/^\#\!.*?\n/, '');
|
51
|
+
onError = function(err) {
|
52
|
+
if (err.errno === require('constants').EPIPE) {
|
85
53
|
process.stdout.removeListener('error', onError);
|
86
54
|
return defer.resolve();
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
function getOpts(argv) {
|
91
|
-
// get the partial line and partial word, if the point isn't at the end
|
92
|
-
// ie, tabbing at: cmd foo b|ar
|
93
|
-
const line = process.env.COMP_LINE;
|
94
|
-
const w = +process.env.COMP_CWORD;
|
95
|
-
const point = +process.env.COMP_POINT;
|
96
|
-
const words = argv.map(unescape);
|
97
|
-
const word = words[w];
|
98
|
-
const partialLine = line.substr(0, point);
|
99
|
-
const partialWords = words.slice(0, w);
|
100
|
-
|
101
|
-
// figure out where in that last word the point is
|
102
|
-
let partialWord = argv[w] || '';
|
103
|
-
let i = partialWord.length;
|
104
|
-
while(partialWord.substr(0, i) !== partialLine.substr(-1 * i) && i > 0) i--;
|
105
|
-
|
106
|
-
partialWord = unescape(partialWord.substr(0, i));
|
107
|
-
partialWord && partialWords.push(partialWord);
|
108
|
-
|
109
|
-
return {
|
110
|
-
line,
|
111
|
-
w,
|
112
|
-
point,
|
113
|
-
words,
|
114
|
-
word,
|
115
|
-
partialLine,
|
116
|
-
partialWords,
|
117
|
-
partialWord
|
55
|
+
} else {
|
56
|
+
return defer.reject(err);
|
57
|
+
}
|
118
58
|
};
|
119
|
-
|
59
|
+
process.stdout.on('error', onError);
|
60
|
+
return process.stdout.write(d, function() {
|
61
|
+
return defer.resolve();
|
62
|
+
});
|
63
|
+
});
|
64
|
+
return defer.promise;
|
65
|
+
};
|
120
66
|
|
121
|
-
function
|
122
|
-
|
123
|
-
|
67
|
+
getOpts = function(argv) {
|
68
|
+
var i, line, partialLine, partialWord, partialWords, point, w, word, words;
|
69
|
+
line = process.env.COMP_LINE;
|
70
|
+
w = +process.env.COMP_CWORD;
|
71
|
+
point = +process.env.COMP_POINT;
|
72
|
+
words = argv.map(unescape);
|
73
|
+
word = words[w];
|
74
|
+
partialLine = line.substr(0, point);
|
75
|
+
partialWords = words.slice(0, w);
|
76
|
+
partialWord = argv[w] || '';
|
77
|
+
i = partialWord.length;
|
78
|
+
while (partialWord.substr(0, i) !== partialLine.substr(-1 * i) && i > 0) {
|
79
|
+
i--;
|
80
|
+
}
|
81
|
+
partialWord = unescape(partialWord.substr(0, i));
|
82
|
+
if (partialWord) {
|
83
|
+
partialWords.push(partialWord);
|
84
|
+
}
|
85
|
+
return {
|
86
|
+
line: line,
|
87
|
+
w: w,
|
88
|
+
point: point,
|
89
|
+
words: words,
|
90
|
+
word: word,
|
91
|
+
partialLine: partialLine,
|
92
|
+
partialWords: partialWords,
|
93
|
+
partialWord: partialWord
|
94
|
+
};
|
95
|
+
};
|
124
96
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
// complete on opt values: --opt=| case
|
137
|
-
const m = opts.partialWord.match(/^(--\w[\w-_]*)=(.*)$/);
|
138
|
-
if(m) {
|
139
|
-
optWord = m[1];
|
140
|
-
optPrefix = optWord + '=';
|
141
|
-
} else
|
142
|
-
// complete on opts
|
143
|
-
// don't complete on opts in case of --opt=val completion
|
144
|
-
// TODO: don't complete on opts in case of unknown arg after commands
|
145
|
-
// TODO: complete only on opts with arr() or not already used
|
146
|
-
// TODO: complete only on full opts?
|
147
|
-
compls = Object.keys(cmd._optsByKey);
|
97
|
+
complete = function(cmd, opts) {
|
98
|
+
var compls, m, o, opt, optPrefix, optWord;
|
99
|
+
compls = [];
|
100
|
+
if (opts.partialWord.indexOf('-')) {
|
101
|
+
compls = Object.keys(cmd._cmdsByName);
|
102
|
+
} else {
|
103
|
+
if (m = opts.partialWord.match(/^(--\w[\w-_]*)=(.*)$/)) {
|
104
|
+
optWord = m[1];
|
105
|
+
optPrefix = optWord + '=';
|
106
|
+
} else {
|
107
|
+
compls = Object.keys(cmd._optsByKey);
|
148
108
|
}
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
console.error('partialWord: %s', opts.partialWord);
|
173
|
-
console.error('compls: %j', complitions);
|
174
|
-
return compls.filter(c => c.indexOf(opts.partialWord) === 0);
|
109
|
+
}
|
110
|
+
if (!(o = opts.partialWords[opts.w - 1]).indexOf('-')) {
|
111
|
+
optWord = o;
|
112
|
+
}
|
113
|
+
if (optWord && (opt = cmd._optsByKey[optWord])) {
|
114
|
+
if (!opt._flag && opt._comp) {
|
115
|
+
compls = Q.join(compls, Q.when(opt._comp(opts), function(c, o) {
|
116
|
+
return c.concat(o.map(function(v) {
|
117
|
+
return (optPrefix || '') + v;
|
118
|
+
}));
|
119
|
+
}));
|
120
|
+
}
|
121
|
+
}
|
122
|
+
if (cmd._comp) {
|
123
|
+
compls = Q.join(compls, Q.when(cmd._comp(opts)), function(c, o) {
|
124
|
+
return c.concat(o);
|
125
|
+
});
|
126
|
+
}
|
127
|
+
return Q.when(compls, function(compls) {
|
128
|
+
console.error('partialWord: %s', opts.partialWord);
|
129
|
+
console.error('compls: %j', compls);
|
130
|
+
return compls.filter(function(c) {
|
131
|
+
return c.indexOf(opts.partialWord) === 0;
|
175
132
|
});
|
176
|
-
}
|
133
|
+
});
|
134
|
+
};
|
package/lib/index.js
CHANGED
@@ -1,14 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
classes : { Cmd, Opt, Arg },
|
12
|
-
shell,
|
13
|
-
require
|
14
|
-
};
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
2
|
+
exports.Cmd = require('./cmd').Cmd;
|
3
|
+
|
4
|
+
exports.Opt = require('./cmd').Opt;
|
5
|
+
|
6
|
+
exports.Arg = require('./cmd').Arg;
|
7
|
+
|
8
|
+
exports.shell = require('./shell');
|
9
|
+
|
10
|
+
exports.require = require;
|