coa 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/.npmignore +6 -0
  2. package/.nyc_output/1f2a0db5a6d6559149db56d397f47cfc.json +1 -0
  3. package/.nyc_output/75b82d38f2186df930141082076e11c6.json +1 -0
  4. package/.travis.yml +9 -0
  5. package/GNUmakefile +34 -0
  6. package/README.md +1 -19
  7. package/coverage/base.css +212 -0
  8. package/coverage/coa/index.html +93 -0
  9. package/coverage/coa/index.js.html +68 -0
  10. package/coverage/coa/lib/arg.js.html +239 -0
  11. package/coverage/coa/lib/cmd.js.html +1556 -0
  12. package/coverage/coa/lib/coaobject.js.html +365 -0
  13. package/coverage/coa/lib/coaparam.js.html +440 -0
  14. package/coverage/coa/lib/color.js.html +131 -0
  15. package/coverage/coa/lib/completion.js.html +593 -0
  16. package/coverage/coa/lib/index.html +197 -0
  17. package/coverage/coa/lib/index.js.html +107 -0
  18. package/coverage/coa/lib/opt.js.html +524 -0
  19. package/coverage/coa/lib/shell.js.html +107 -0
  20. package/coverage/index.html +106 -0
  21. package/coverage/prettify.css +1 -0
  22. package/coverage/prettify.js +1 -0
  23. package/coverage/sort-arrow-sprite.png +0 -0
  24. package/coverage/sorter.js +158 -0
  25. package/index.js +1 -1
  26. package/lib/arg.js +161 -44
  27. package/lib/cmd.js +547 -434
  28. package/lib/color.js +22 -19
  29. package/lib/completion.js +119 -161
  30. package/lib/index.js +10 -14
  31. package/lib/opt.js +313 -130
  32. package/lib/shell.js +13 -13
  33. package/package.json +14 -19
  34. package/qq.js +17 -0
  35. package/src/arg.coffee +130 -0
  36. package/src/cmd.coffee +456 -0
  37. package/src/color.coffee +25 -0
  38. package/src/completion.coffee +156 -0
  39. package/src/index.coffee +5 -0
  40. package/src/opt.coffee +243 -0
  41. package/src/shell.coffee +10 -0
  42. package/test/coa.js +496 -0
  43. package/test/mocha.opts +2 -0
  44. package/test/shell-test.js +60 -0
  45. package/tests/api-h.js +9 -0
  46. package/tests/h.js +6 -0
  47. package/LICENSE +0 -21
  48. package/lib/coaobject.js +0 -100
  49. package/lib/coaparam.js +0 -125
package/lib/color.js CHANGED
@@ -1,22 +1,25 @@
1
- 'use strict';
1
+ // Generated by CoffeeScript 1.6.3
2
+ var colors;
2
3
 
3
- const colors = {
4
- black : '30',
5
- dgray : '1;30',
6
- red : '31',
7
- lred : '1;31',
8
- green : '32',
9
- lgreen : '1;32',
10
- brown : '33',
11
- yellow : '1;33',
12
- blue : '34',
13
- lblue : '1;34',
14
- purple : '35',
15
- lpurple : '1;35',
16
- cyan : '36',
17
- lcyan : '1;36',
18
- lgray : '37',
19
- white : '1;37'
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
- module.exports = (c, str) => `\x1B[${colors[c]}m${str}\x1B[m`;
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
- 'use strict';
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
- * Most of the code adopted from the npm package shell completion code.
15
- * See https://github.com/isaacs/npm/blob/master/lib/completion.js
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
- // if the COMP_* isn't in the env, then just dump the script
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
- console.error('COMP_LINE: %s', process.env.COMP_LINE);
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
- // completion opts
49
- opts = getOpts(args.raw);
11
+ escape = require('./shell').escape;
50
12
 
51
- // cmd
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
- fs.readFile(path.resolve(__dirname, 'completion.sh'), 'utf8', function(err, d) {
64
- if(err) return defer.reject(err);
65
- d = d.replace(/{{cmd}}/g, path.basename(name)).replace(/^\#\!.*?\n/, '');
66
-
67
- process.stdout.on('error', onError);
68
- process.stdout.write(d, () => defer.resolve());
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
- return defer.promise;
72
-
73
- function onError(err) {
74
- // Darwin is a real dick sometimes.
75
- //
76
- // This is necessary because the "source" or "." program in
77
- // bash on OS X closes its file argument before reading
78
- // from it, meaning that you get exactly 1 write, which will
79
- // work most of the time, and will always raise an EPIPE.
80
- //
81
- // Really, one should not be tossing away EPIPE errors, or any
82
- // errors, so casually. But, without this, `. <(cmd completion)`
83
- // can never ever work on OS X.
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 complete(cmd, opts) {
122
- let optWord, optPrefix,
123
- compls = [];
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
- // Complete on cmds
126
- if(opts.partialWord.indexOf('-'))
127
- compls = Object.keys(cmd._cmdsByName);
128
- // Complete on required opts without '-' in last partial word
129
- // (if required not already specified)
130
- //
131
- // Commented out because of uselessness:
132
- // -b, --block suggest results in '-' on cmd line;
133
- // next completion suggest all options, because of '-'
134
- //.concat Object.keys(cmd._optsByKey).filter (v) -> cmd._optsByKey[v]._req
135
- else {
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
- // complete on opt values: next arg case
151
- opts.partialWords[opts.w - 1].indexOf('-') || (optWord = opts.partialWords[opts.w - 1]);
152
-
153
- // complete on opt values: completion
154
- let opt;
155
- optWord
156
- && (opt = cmd._optsByKey[optWord])
157
- && !opt._flag
158
- && opt._comp
159
- && (compls = Q.join(compls,
160
- Q.when(opt._comp(opts),
161
- (c, o) => c.concat(o.map(v => (optPrefix || '') + v)))));
162
-
163
- // TODO: complete on args values (context aware, custom completion?)
164
-
165
- // custom completion on cmds
166
- cmd._comp && (compls = Q.join(compls, Q.when(cmd._comp(opts)), (c, o) => c.concat(o)));
167
-
168
- // TODO: context aware custom completion on cmds, opts and args
169
- // (can depend on already entered values, especially options)
170
-
171
- return Q.when(compls, complitions => {
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
- const
2
- Cmd = require('./cmd'),
3
- Opt = require('./opt'),
4
- Arg = require('./arg'),
5
- shell = require('./shell');
6
-
7
- module.exports = {
8
- Cmd : Cmd.create,
9
- Opt : Opt.create,
10
- Arg : Arg.create,
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;