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
@@ -0,0 +1,593 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<title>Code coverage report for coa/lib/completion.js</title>
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
<link rel="stylesheet" href="../../prettify.css" />
|
7
|
+
<link rel="stylesheet" href="../../base.css" />
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
9
|
+
<style type='text/css'>
|
10
|
+
.coverage-summary .sorter {
|
11
|
+
background-image: url(../../sort-arrow-sprite.png);
|
12
|
+
}
|
13
|
+
</style>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
<div class='wrapper'>
|
17
|
+
<div class='pad1'>
|
18
|
+
<h1>
|
19
|
+
<a href="../../index.html">All files</a> / <a href="index.html">coa/lib</a> completion.js
|
20
|
+
</h1>
|
21
|
+
<div class='clearfix'>
|
22
|
+
<div class='fl pad1y space-right2'>
|
23
|
+
<span class="strong">11.27% </span>
|
24
|
+
<span class="quiet">Statements</span>
|
25
|
+
<span class='fraction'>8/71</span>
|
26
|
+
</div>
|
27
|
+
<div class='fl pad1y space-right2'>
|
28
|
+
<span class="strong">0% </span>
|
29
|
+
<span class="quiet">Branches</span>
|
30
|
+
<span class='fraction'>0/32</span>
|
31
|
+
</div>
|
32
|
+
<div class='fl pad1y space-right2'>
|
33
|
+
<span class="strong">0% </span>
|
34
|
+
<span class="quiet">Functions</span>
|
35
|
+
<span class='fraction'>0/14</span>
|
36
|
+
</div>
|
37
|
+
<div class='fl pad1y space-right2'>
|
38
|
+
<span class="strong">12.5% </span>
|
39
|
+
<span class="quiet">Lines</span>
|
40
|
+
<span class='fraction'>8/64</span>
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
<div class='status-line low'></div>
|
45
|
+
<pre><table class="coverage">
|
46
|
+
<tr><td class="line-count quiet">1
|
47
|
+
2
|
48
|
+
3
|
49
|
+
4
|
50
|
+
5
|
51
|
+
6
|
52
|
+
7
|
53
|
+
8
|
54
|
+
9
|
55
|
+
10
|
56
|
+
11
|
57
|
+
12
|
58
|
+
13
|
59
|
+
14
|
60
|
+
15
|
61
|
+
16
|
62
|
+
17
|
63
|
+
18
|
64
|
+
19
|
65
|
+
20
|
66
|
+
21
|
67
|
+
22
|
68
|
+
23
|
69
|
+
24
|
70
|
+
25
|
71
|
+
26
|
72
|
+
27
|
73
|
+
28
|
74
|
+
29
|
75
|
+
30
|
76
|
+
31
|
77
|
+
32
|
78
|
+
33
|
79
|
+
34
|
80
|
+
35
|
81
|
+
36
|
82
|
+
37
|
83
|
+
38
|
84
|
+
39
|
85
|
+
40
|
86
|
+
41
|
87
|
+
42
|
88
|
+
43
|
89
|
+
44
|
90
|
+
45
|
91
|
+
46
|
92
|
+
47
|
93
|
+
48
|
94
|
+
49
|
95
|
+
50
|
96
|
+
51
|
97
|
+
52
|
98
|
+
53
|
99
|
+
54
|
100
|
+
55
|
101
|
+
56
|
102
|
+
57
|
103
|
+
58
|
104
|
+
59
|
105
|
+
60
|
106
|
+
61
|
107
|
+
62
|
108
|
+
63
|
109
|
+
64
|
110
|
+
65
|
111
|
+
66
|
112
|
+
67
|
113
|
+
68
|
114
|
+
69
|
115
|
+
70
|
116
|
+
71
|
117
|
+
72
|
118
|
+
73
|
119
|
+
74
|
120
|
+
75
|
121
|
+
76
|
122
|
+
77
|
123
|
+
78
|
124
|
+
79
|
125
|
+
80
|
126
|
+
81
|
127
|
+
82
|
128
|
+
83
|
129
|
+
84
|
130
|
+
85
|
131
|
+
86
|
132
|
+
87
|
133
|
+
88
|
134
|
+
89
|
135
|
+
90
|
136
|
+
91
|
137
|
+
92
|
138
|
+
93
|
139
|
+
94
|
140
|
+
95
|
141
|
+
96
|
142
|
+
97
|
143
|
+
98
|
144
|
+
99
|
145
|
+
100
|
146
|
+
101
|
147
|
+
102
|
148
|
+
103
|
149
|
+
104
|
150
|
+
105
|
151
|
+
106
|
152
|
+
107
|
153
|
+
108
|
154
|
+
109
|
155
|
+
110
|
156
|
+
111
|
157
|
+
112
|
158
|
+
113
|
159
|
+
114
|
160
|
+
115
|
161
|
+
116
|
162
|
+
117
|
163
|
+
118
|
164
|
+
119
|
165
|
+
120
|
166
|
+
121
|
167
|
+
122
|
168
|
+
123
|
169
|
+
124
|
170
|
+
125
|
171
|
+
126
|
172
|
+
127
|
173
|
+
128
|
174
|
+
129
|
175
|
+
130
|
176
|
+
131
|
177
|
+
132
|
178
|
+
133
|
179
|
+
134
|
180
|
+
135
|
181
|
+
136
|
182
|
+
137
|
183
|
+
138
|
184
|
+
139
|
185
|
+
140
|
186
|
+
141
|
187
|
+
142
|
188
|
+
143
|
189
|
+
144
|
190
|
+
145
|
191
|
+
146
|
192
|
+
147
|
193
|
+
148
|
194
|
+
149
|
195
|
+
150
|
196
|
+
151
|
197
|
+
152
|
198
|
+
153
|
199
|
+
154
|
200
|
+
155
|
201
|
+
156
|
202
|
+
157
|
203
|
+
158
|
204
|
+
159
|
205
|
+
160
|
206
|
+
161
|
207
|
+
162
|
208
|
+
163
|
209
|
+
164
|
210
|
+
165
|
211
|
+
166
|
212
|
+
167
|
213
|
+
168
|
214
|
+
169
|
215
|
+
170
|
216
|
+
171
|
217
|
+
172
|
218
|
+
173
|
219
|
+
174
|
220
|
+
175
|
221
|
+
176
|
222
|
+
177</td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
223
|
+
<span class="cline-any cline-neutral"> </span>
|
224
|
+
<span class="cline-any cline-yes">1x</span>
|
225
|
+
<span class="cline-any cline-yes">1x</span>
|
226
|
+
<span class="cline-any cline-yes">1x</span>
|
227
|
+
<span class="cline-any cline-neutral"> </span>
|
228
|
+
<span class="cline-any cline-yes">1x</span>
|
229
|
+
<span class="cline-any cline-neutral"> </span>
|
230
|
+
<span class="cline-any cline-yes">1x</span>
|
231
|
+
<span class="cline-any cline-yes">1x</span>
|
232
|
+
<span class="cline-any cline-yes">1x</span>
|
233
|
+
<span class="cline-any cline-neutral"> </span>
|
234
|
+
<span class="cline-any cline-neutral"> </span>
|
235
|
+
<span class="cline-any cline-neutral"> </span>
|
236
|
+
<span class="cline-any cline-neutral"> </span>
|
237
|
+
<span class="cline-any cline-neutral"> </span>
|
238
|
+
<span class="cline-any cline-neutral"> </span>
|
239
|
+
<span class="cline-any cline-neutral"> </span>
|
240
|
+
<span class="cline-any cline-yes">1x</span>
|
241
|
+
<span class="cline-any cline-no"> </span>
|
242
|
+
<span class="cline-any cline-neutral"> </span>
|
243
|
+
<span class="cline-any cline-neutral"> </span>
|
244
|
+
<span class="cline-any cline-neutral"> </span>
|
245
|
+
<span class="cline-any cline-neutral"> </span>
|
246
|
+
<span class="cline-any cline-neutral"> </span>
|
247
|
+
<span class="cline-any cline-neutral"> </span>
|
248
|
+
<span class="cline-any cline-neutral"> </span>
|
249
|
+
<span class="cline-any cline-neutral"> </span>
|
250
|
+
<span class="cline-any cline-no"> </span>
|
251
|
+
<span class="cline-any cline-no"> </span>
|
252
|
+
<span class="cline-any cline-no"> </span>
|
253
|
+
<span class="cline-any cline-no"> </span>
|
254
|
+
<span class="cline-any cline-no"> </span>
|
255
|
+
<span class="cline-any cline-neutral"> </span>
|
256
|
+
<span class="cline-any cline-neutral"> </span>
|
257
|
+
<span class="cline-any cline-neutral"> </span>
|
258
|
+
<span class="cline-any cline-no"> </span>
|
259
|
+
<span class="cline-any cline-neutral"> </span>
|
260
|
+
<span class="cline-any cline-neutral"> </span>
|
261
|
+
<span class="cline-any cline-no"> </span>
|
262
|
+
<span class="cline-any cline-neutral"> </span>
|
263
|
+
<span class="cline-any cline-neutral"> </span>
|
264
|
+
<span class="cline-any cline-no"> </span>
|
265
|
+
<span class="cline-any cline-no"> </span>
|
266
|
+
<span class="cline-any cline-no"> </span>
|
267
|
+
<span class="cline-any cline-no"> </span>
|
268
|
+
<span class="cline-any cline-neutral"> </span>
|
269
|
+
<span class="cline-any cline-neutral"> </span>
|
270
|
+
<span class="cline-any cline-no"> </span>
|
271
|
+
<span class="cline-any cline-neutral"> </span>
|
272
|
+
<span class="cline-any cline-neutral"> </span>
|
273
|
+
<span class="cline-any cline-no"> </span>
|
274
|
+
<span class="cline-any cline-no"> </span>
|
275
|
+
<span class="cline-any cline-no"> </span>
|
276
|
+
<span class="cline-any cline-no"> </span>
|
277
|
+
<span class="cline-any cline-neutral"> </span>
|
278
|
+
<span class="cline-any cline-neutral"> </span>
|
279
|
+
<span class="cline-any cline-neutral"> </span>
|
280
|
+
<span class="cline-any cline-neutral"> </span>
|
281
|
+
<span class="cline-any cline-neutral"> </span>
|
282
|
+
<span class="cline-any cline-no"> </span>
|
283
|
+
<span class="cline-any cline-neutral"> </span>
|
284
|
+
<span class="cline-any cline-no"> </span>
|
285
|
+
<span class="cline-any cline-no"> </span>
|
286
|
+
<span class="cline-any cline-no"> </span>
|
287
|
+
<span class="cline-any cline-neutral"> </span>
|
288
|
+
<span class="cline-any cline-no"> </span>
|
289
|
+
<span class="cline-any cline-no"> </span>
|
290
|
+
<span class="cline-any cline-neutral"> </span>
|
291
|
+
<span class="cline-any cline-neutral"> </span>
|
292
|
+
<span class="cline-any cline-no"> </span>
|
293
|
+
<span class="cline-any cline-neutral"> </span>
|
294
|
+
<span class="cline-any cline-neutral"> </span>
|
295
|
+
<span class="cline-any cline-neutral"> </span>
|
296
|
+
<span class="cline-any cline-neutral"> </span>
|
297
|
+
<span class="cline-any cline-neutral"> </span>
|
298
|
+
<span class="cline-any cline-neutral"> </span>
|
299
|
+
<span class="cline-any cline-neutral"> </span>
|
300
|
+
<span class="cline-any cline-neutral"> </span>
|
301
|
+
<span class="cline-any cline-neutral"> </span>
|
302
|
+
<span class="cline-any cline-neutral"> </span>
|
303
|
+
<span class="cline-any cline-neutral"> </span>
|
304
|
+
<span class="cline-any cline-neutral"> </span>
|
305
|
+
<span class="cline-any cline-no"> </span>
|
306
|
+
<span class="cline-any cline-no"> </span>
|
307
|
+
<span class="cline-any cline-no"> </span>
|
308
|
+
<span class="cline-any cline-neutral"> </span>
|
309
|
+
<span class="cline-any cline-neutral"> </span>
|
310
|
+
<span class="cline-any cline-neutral"> </span>
|
311
|
+
<span class="cline-any cline-neutral"> </span>
|
312
|
+
<span class="cline-any cline-neutral"> </span>
|
313
|
+
<span class="cline-any cline-neutral"> </span>
|
314
|
+
<span class="cline-any cline-no"> </span>
|
315
|
+
<span class="cline-any cline-no"> </span>
|
316
|
+
<span class="cline-any cline-no"> </span>
|
317
|
+
<span class="cline-any cline-no"> </span>
|
318
|
+
<span class="cline-any cline-no"> </span>
|
319
|
+
<span class="cline-any cline-no"> </span>
|
320
|
+
<span class="cline-any cline-no"> </span>
|
321
|
+
<span class="cline-any cline-neutral"> </span>
|
322
|
+
<span class="cline-any cline-neutral"> </span>
|
323
|
+
<span class="cline-any cline-no"> </span>
|
324
|
+
<span class="cline-any cline-no"> </span>
|
325
|
+
<span class="cline-any cline-no"> </span>
|
326
|
+
<span class="cline-any cline-neutral"> </span>
|
327
|
+
<span class="cline-any cline-no"> </span>
|
328
|
+
<span class="cline-any cline-no"> </span>
|
329
|
+
<span class="cline-any cline-neutral"> </span>
|
330
|
+
<span class="cline-any cline-no"> </span>
|
331
|
+
<span class="cline-any cline-neutral"> </span>
|
332
|
+
<span class="cline-any cline-neutral"> </span>
|
333
|
+
<span class="cline-any cline-neutral"> </span>
|
334
|
+
<span class="cline-any cline-neutral"> </span>
|
335
|
+
<span class="cline-any cline-neutral"> </span>
|
336
|
+
<span class="cline-any cline-neutral"> </span>
|
337
|
+
<span class="cline-any cline-neutral"> </span>
|
338
|
+
<span class="cline-any cline-neutral"> </span>
|
339
|
+
<span class="cline-any cline-neutral"> </span>
|
340
|
+
<span class="cline-any cline-neutral"> </span>
|
341
|
+
<span class="cline-any cline-neutral"> </span>
|
342
|
+
<span class="cline-any cline-neutral"> </span>
|
343
|
+
<span class="cline-any cline-neutral"> </span>
|
344
|
+
<span class="cline-any cline-no"> </span>
|
345
|
+
<span class="cline-any cline-neutral"> </span>
|
346
|
+
<span class="cline-any cline-neutral"> </span>
|
347
|
+
<span class="cline-any cline-no"> </span>
|
348
|
+
<span class="cline-any cline-no"> </span>
|
349
|
+
<span class="cline-any cline-neutral"> </span>
|
350
|
+
<span class="cline-any cline-neutral"> </span>
|
351
|
+
<span class="cline-any cline-neutral"> </span>
|
352
|
+
<span class="cline-any cline-neutral"> </span>
|
353
|
+
<span class="cline-any cline-neutral"> </span>
|
354
|
+
<span class="cline-any cline-neutral"> </span>
|
355
|
+
<span class="cline-any cline-neutral"> </span>
|
356
|
+
<span class="cline-any cline-neutral"> </span>
|
357
|
+
<span class="cline-any cline-neutral"> </span>
|
358
|
+
<span class="cline-any cline-no"> </span>
|
359
|
+
<span class="cline-any cline-no"> </span>
|
360
|
+
<span class="cline-any cline-no"> </span>
|
361
|
+
<span class="cline-any cline-no"> </span>
|
362
|
+
<span class="cline-any cline-neutral"> </span>
|
363
|
+
<span class="cline-any cline-neutral"> </span>
|
364
|
+
<span class="cline-any cline-neutral"> </span>
|
365
|
+
<span class="cline-any cline-neutral"> </span>
|
366
|
+
<span class="cline-any cline-neutral"> </span>
|
367
|
+
<span class="cline-any cline-neutral"> </span>
|
368
|
+
<span class="cline-any cline-no"> </span>
|
369
|
+
<span class="cline-any cline-neutral"> </span>
|
370
|
+
<span class="cline-any cline-neutral"> </span>
|
371
|
+
<span class="cline-any cline-neutral"> </span>
|
372
|
+
<span class="cline-any cline-no"> </span>
|
373
|
+
<span class="cline-any cline-neutral"> </span>
|
374
|
+
<span class="cline-any cline-neutral"> </span>
|
375
|
+
<span class="cline-any cline-neutral"> </span>
|
376
|
+
<span class="cline-any cline-no"> </span>
|
377
|
+
<span class="cline-any cline-neutral"> </span>
|
378
|
+
<span class="cline-any cline-neutral"> </span>
|
379
|
+
<span class="cline-any cline-neutral"> </span>
|
380
|
+
<span class="cline-any cline-neutral"> </span>
|
381
|
+
<span class="cline-any cline-neutral"> </span>
|
382
|
+
<span class="cline-any cline-no"> </span>
|
383
|
+
<span class="cline-any cline-neutral"> </span>
|
384
|
+
<span class="cline-any cline-neutral"> </span>
|
385
|
+
<span class="cline-any cline-neutral"> </span>
|
386
|
+
<span class="cline-any cline-neutral"> </span>
|
387
|
+
<span class="cline-any cline-no"> </span>
|
388
|
+
<span class="cline-any cline-neutral"> </span>
|
389
|
+
<span class="cline-any cline-neutral"> </span>
|
390
|
+
<span class="cline-any cline-neutral"> </span>
|
391
|
+
<span class="cline-any cline-neutral"> </span>
|
392
|
+
<span class="cline-any cline-no"> </span>
|
393
|
+
<span class="cline-any cline-no"> </span>
|
394
|
+
<span class="cline-any cline-no"> </span>
|
395
|
+
<span class="cline-any cline-no"> </span>
|
396
|
+
<span class="cline-any cline-neutral"> </span>
|
397
|
+
<span class="cline-any cline-neutral"> </span>
|
398
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">'use strict';
|
399
|
+
|
400
|
+
const constants = require('constants');
|
401
|
+
const fs = require('fs');
|
402
|
+
const path = require('path');
|
403
|
+
|
404
|
+
const Q = require('q');
|
405
|
+
|
406
|
+
const shell = require('./shell');
|
407
|
+
const escape = shell.escape;
|
408
|
+
const unescape = shell.unescape;
|
409
|
+
|
410
|
+
/**
|
411
|
+
* Most of the code adopted from the npm package shell completion code.
|
412
|
+
* See https://github.com/isaacs/npm/blob/master/lib/completion.js
|
413
|
+
*
|
414
|
+
* @returns {COA.CoaObject}
|
415
|
+
*/
|
416
|
+
module.exports = function <span class="fstat-no" title="function not covered" >completion(</span>) {
|
417
|
+
<span class="cstat-no" title="statement not covered" > return this</span>
|
418
|
+
.title('Shell completion')
|
419
|
+
.helpful()
|
420
|
+
.arg()
|
421
|
+
.name('raw')
|
422
|
+
.title('Completion words')
|
423
|
+
.arr()
|
424
|
+
.end()
|
425
|
+
.act(<span class="fstat-no" title="function not covered" >(o</span>pts, args) => {
|
426
|
+
<span class="cstat-no" title="statement not covered" > if(process.platform === 'win32') {</span>
|
427
|
+
const e = <span class="cstat-no" title="statement not covered" >new Error('shell completion not supported on windows');</span>
|
428
|
+
<span class="cstat-no" title="statement not covered" > e.code = 'ENOTSUP';</span>
|
429
|
+
<span class="cstat-no" title="statement not covered" > e.errno = constants.ENOTSUP;</span>
|
430
|
+
<span class="cstat-no" title="statement not covered" > return this.reject(e);</span>
|
431
|
+
}
|
432
|
+
|
433
|
+
// if the COMP_* isn't in the env, then just dump the script
|
434
|
+
<span class="cstat-no" title="statement not covered" > if((process.env.COMP_CWORD == null)</span>
|
435
|
+
|| (process.env.COMP_LINE == null)
|
436
|
+
|| (process.env.COMP_POINT == null)) {
|
437
|
+
<span class="cstat-no" title="statement not covered" > return dumpScript(this._cmd._name);</span>
|
438
|
+
}
|
439
|
+
|
440
|
+
<span class="cstat-no" title="statement not covered" > console.error('COMP_LINE: %s', process.env.COMP_LINE);</span>
|
441
|
+
<span class="cstat-no" title="statement not covered" > console.error('COMP_CWORD: %s', process.env.COMP_CWORD);</span>
|
442
|
+
<span class="cstat-no" title="statement not covered" > console.error('COMP_POINT: %s', process.env.COMP_POINT);</span>
|
443
|
+
<span class="cstat-no" title="statement not covered" > console.error('args: %j', args.raw);</span>
|
444
|
+
|
445
|
+
// completion opts
|
446
|
+
<span class="cstat-no" title="statement not covered" > opts = getOpts(args.raw);</span>
|
447
|
+
|
448
|
+
// cmd
|
449
|
+
const parsed = <span class="cstat-no" title="statement not covered" >this._cmd._parseCmd(opts.partialWords);</span>
|
450
|
+
<span class="cstat-no" title="statement not covered" > return Q.when(complete(parsed.cmd, parsed.opts), <span class="fstat-no" title="function not covered" >(c</span>ompls) => {</span>
|
451
|
+
<span class="cstat-no" title="statement not covered" > console.error('filtered: %j', compls);</span>
|
452
|
+
<span class="cstat-no" title="statement not covered" > return console.log(compls.map(escape).join('\n'));</span>
|
453
|
+
});
|
454
|
+
});
|
455
|
+
};
|
456
|
+
|
457
|
+
function <span class="fstat-no" title="function not covered" >dumpScript(</span>name) {
|
458
|
+
const defer = <span class="cstat-no" title="statement not covered" >Q.defer();</span>
|
459
|
+
|
460
|
+
<span class="cstat-no" title="statement not covered" > fs.readFile(path.resolve(__dirname, 'completion.sh'), 'utf8', <span class="fstat-no" title="function not covered" >fu</span>nction(err, d) {</span>
|
461
|
+
<span class="cstat-no" title="statement not covered" > if(err) <span class="cstat-no" title="statement not covered" >return defer.reject(err);</span></span>
|
462
|
+
<span class="cstat-no" title="statement not covered" > d = d.replace(/{{cmd}}/g, path.basename(name)).replace(/^\#\!.*?\n/, '');</span>
|
463
|
+
|
464
|
+
<span class="cstat-no" title="statement not covered" > process.stdout.on('error', onError);</span>
|
465
|
+
<span class="cstat-no" title="statement not covered" > process.stdout.write(d, <span class="fstat-no" title="function not covered" >()</span> => <span class="cstat-no" title="statement not covered" >defer.resolve())</span>;</span>
|
466
|
+
});
|
467
|
+
|
468
|
+
<span class="cstat-no" title="statement not covered" > return defer.promise;</span>
|
469
|
+
|
470
|
+
function <span class="fstat-no" title="function not covered" >onError(</span>err) {
|
471
|
+
// Darwin is a real dick sometimes.
|
472
|
+
//
|
473
|
+
// This is necessary because the "source" or "." program in
|
474
|
+
// bash on OS X closes its file argument before reading
|
475
|
+
// from it, meaning that you get exactly 1 write, which will
|
476
|
+
// work most of the time, and will always raise an EPIPE.
|
477
|
+
//
|
478
|
+
// Really, one should not be tossing away EPIPE errors, or any
|
479
|
+
// errors, so casually. But, without this, `. <(cmd completion)`
|
480
|
+
// can never ever work on OS X.
|
481
|
+
<span class="cstat-no" title="statement not covered" > if(err.errno !== constants.EPIPE) <span class="cstat-no" title="statement not covered" >return defer.reject(err);</span></span>
|
482
|
+
<span class="cstat-no" title="statement not covered" > process.stdout.removeListener('error', onError);</span>
|
483
|
+
<span class="cstat-no" title="statement not covered" > return defer.resolve();</span>
|
484
|
+
}
|
485
|
+
}
|
486
|
+
|
487
|
+
function <span class="fstat-no" title="function not covered" >getOpts(</span>argv) {
|
488
|
+
// get the partial line and partial word, if the point isn't at the end
|
489
|
+
// ie, tabbing at: cmd foo b|ar
|
490
|
+
const line = <span class="cstat-no" title="statement not covered" >process.env.COMP_LINE;</span>
|
491
|
+
const w = <span class="cstat-no" title="statement not covered" >+process.env.COMP_CWORD;</span>
|
492
|
+
const point = <span class="cstat-no" title="statement not covered" >+process.env.COMP_POINT;</span>
|
493
|
+
const words = <span class="cstat-no" title="statement not covered" >argv.map(unescape);</span>
|
494
|
+
const word = <span class="cstat-no" title="statement not covered" >words[w];</span>
|
495
|
+
const partialLine = <span class="cstat-no" title="statement not covered" >line.substr(0, point);</span>
|
496
|
+
const partialWords = <span class="cstat-no" title="statement not covered" >words.slice(0, w);</span>
|
497
|
+
|
498
|
+
// figure out where in that last word the point is
|
499
|
+
let partialWord = <span class="cstat-no" title="statement not covered" >argv[w] || '';</span>
|
500
|
+
let i = <span class="cstat-no" title="statement not covered" >partialWord.length;</span>
|
501
|
+
<span class="cstat-no" title="statement not covered" > while(partialWord.substr(0, i) !== partialLine.substr(-1 * i) && i > 0) <span class="cstat-no" title="statement not covered" >i--;</span></span>
|
502
|
+
|
503
|
+
<span class="cstat-no" title="statement not covered" > partialWord = unescape(partialWord.substr(0, i));</span>
|
504
|
+
<span class="cstat-no" title="statement not covered" > partialWord && partialWords.push(partialWord);</span>
|
505
|
+
|
506
|
+
<span class="cstat-no" title="statement not covered" > return {</span>
|
507
|
+
line,
|
508
|
+
w,
|
509
|
+
point,
|
510
|
+
words,
|
511
|
+
word,
|
512
|
+
partialLine,
|
513
|
+
partialWords,
|
514
|
+
partialWord
|
515
|
+
};
|
516
|
+
}
|
517
|
+
|
518
|
+
function <span class="fstat-no" title="function not covered" >complete(</span>cmd, opts) {
|
519
|
+
let optWord, optPrefix,
|
520
|
+
compls = <span class="cstat-no" title="statement not covered" >[];</span>
|
521
|
+
|
522
|
+
// Complete on cmds
|
523
|
+
<span class="cstat-no" title="statement not covered" > if(opts.partialWord.indexOf('-'))</span>
|
524
|
+
<span class="cstat-no" title="statement not covered" > compls = Object.keys(cmd._cmdsByName);</span>
|
525
|
+
// Complete on required opts without '-' in last partial word
|
526
|
+
// (if required not already specified)
|
527
|
+
//
|
528
|
+
// Commented out because of uselessness:
|
529
|
+
// -b, --block suggest results in '-' on cmd line;
|
530
|
+
// next completion suggest all options, because of '-'
|
531
|
+
//.concat Object.keys(cmd._optsByKey).filter (v) -> cmd._optsByKey[v]._req
|
532
|
+
else {
|
533
|
+
// complete on opt values: --opt=| case
|
534
|
+
const m = <span class="cstat-no" title="statement not covered" >opts.partialWord.match(/^(--\w[\w-_]*)=(.*)$/);</span>
|
535
|
+
<span class="cstat-no" title="statement not covered" > if(m) {</span>
|
536
|
+
<span class="cstat-no" title="statement not covered" > optWord = m[1];</span>
|
537
|
+
<span class="cstat-no" title="statement not covered" > optPrefix = optWord + '=';</span>
|
538
|
+
} else
|
539
|
+
// complete on opts
|
540
|
+
// don't complete on opts in case of --opt=val completion
|
541
|
+
// TODO: don't complete on opts in case of unknown arg after commands
|
542
|
+
// TODO: complete only on opts with arr() or not already used
|
543
|
+
// TODO: complete only on full opts?
|
544
|
+
<span class="cstat-no" title="statement not covered" > compls = Object.keys(cmd._optsByKey);</span>
|
545
|
+
}
|
546
|
+
|
547
|
+
// complete on opt values: next arg case
|
548
|
+
<span class="cstat-no" title="statement not covered" > opts.partialWords[opts.w - 1].indexOf('-') || (optWord = opts.partialWords[opts.w - 1]);</span>
|
549
|
+
|
550
|
+
// complete on opt values: completion
|
551
|
+
let opt;
|
552
|
+
<span class="cstat-no" title="statement not covered" > optWord</span>
|
553
|
+
&& (opt = cmd._optsByKey[optWord])
|
554
|
+
&& !opt._flag
|
555
|
+
&& opt._comp
|
556
|
+
&& (compls = Q.join(compls,
|
557
|
+
Q.when(opt._comp(opts),
|
558
|
+
<span class="fstat-no" title="function not covered" > (c</span>, o) => <span class="cstat-no" title="statement not covered" >c.concat(o.map(<span class="fstat-no" title="function not covered" >v </span>=> <span class="cstat-no" title="statement not covered" >(optPrefix || '') + v)</span>))</span>));
|
559
|
+
|
560
|
+
// TODO: complete on args values (context aware, custom completion?)
|
561
|
+
|
562
|
+
// custom completion on cmds
|
563
|
+
<span class="cstat-no" title="statement not covered" > cmd._comp && (compls = Q.join(compls, Q.when(cmd._comp(opts)), <span class="fstat-no" title="function not covered" >(c</span>, o) => <span class="cstat-no" title="statement not covered" >c.concat(o))</span>);</span>
|
564
|
+
|
565
|
+
// TODO: context aware custom completion on cmds, opts and args
|
566
|
+
// (can depend on already entered values, especially options)
|
567
|
+
|
568
|
+
<span class="cstat-no" title="statement not covered" > return Q.when(compls, <span class="fstat-no" title="function not covered" >co</span>mplitions => {</span>
|
569
|
+
<span class="cstat-no" title="statement not covered" > console.error('partialWord: %s', opts.partialWord);</span>
|
570
|
+
<span class="cstat-no" title="statement not covered" > console.error('compls: %j', complitions);</span>
|
571
|
+
<span class="cstat-no" title="statement not covered" > return compls.filter(<span class="fstat-no" title="function not covered" >(c</span>) => <span class="cstat-no" title="statement not covered" >c.indexOf(opts.partialWord) === 0)</span>;</span>
|
572
|
+
});
|
573
|
+
}
|
574
|
+
</pre></td></tr>
|
575
|
+
</table></pre>
|
576
|
+
<div class='push'></div><!-- for sticky footer -->
|
577
|
+
</div><!-- /wrapper -->
|
578
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
579
|
+
Code coverage
|
580
|
+
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Feb 17 2017 22:25:28 GMT+0300 (MSK)
|
581
|
+
</div>
|
582
|
+
</div>
|
583
|
+
<script src="../../prettify.js"></script>
|
584
|
+
<script>
|
585
|
+
window.onload = function () {
|
586
|
+
if (typeof prettyPrint === 'function') {
|
587
|
+
prettyPrint();
|
588
|
+
}
|
589
|
+
};
|
590
|
+
</script>
|
591
|
+
<script src="../../sorter.js"></script>
|
592
|
+
</body>
|
593
|
+
</html>
|