coa 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/opt.js CHANGED
@@ -1,155 +1,338 @@
1
- 'use strict';
1
+ // Generated by CoffeeScript 1.6.3
2
+ var Cmd, Color, Opt, Q, fs;
2
3
 
3
- const
4
- Q = require('q'),
4
+ fs = require('fs');
5
5
 
6
- CoaParam = require('./coaparam'),
7
- Color = require('./color');
6
+ Q = require('q');
7
+
8
+ Color = require('./color').Color;
9
+
10
+ Cmd = require('./cmd').Cmd;
8
11
 
9
12
  /**
10
- * Option
11
- *
12
- * Named entity. Options may have short and long keys for use from command line.
13
- *
14
- * @namespace
15
- * @class Opt
16
- * @extends CoaParam
17
- */
18
- module.exports = class Opt extends CoaParam {
19
- /**
20
- * @constructs
21
- * @param {COA.Cmd} cmd - parent command
22
- */
23
- constructor(cmd) {
24
- super(cmd);
25
-
26
- this._short = null;
27
- this._long = null;
28
- this._flag = false;
29
- this._only = false;
30
- this._cmd._opts.push(this);
31
- }
13
+ Option
32
14
 
33
- /**
34
- * Set a short key for option to be used with one hyphen from command line.
35
- *
36
- * @param {String} short - short name
37
- * @returns {COA.Opt} - this instance (for chainability)
38
- */
39
- short(short) {
40
- this._short = short;
41
- this._cmd._optsByKey[`-${short}`] = this;
42
- return this;
43
- }
15
+ Named entity. Options may have short and long keys for use from command line.
16
+ @namespace
17
+ @class Presents option
18
+ */
44
19
 
45
- /**
46
- * Set a short key for option to be used with double hyphens from command line.
47
- *
48
- * @param {String} long - long name
49
- * @returns {COA.Opt} - this instance (for chainability)
50
- */
51
- long(long) {
52
- this._long = long;
53
- this._cmd._optsByKey[`--${long}`] = this;
54
- return this;
55
- }
56
20
 
57
- /**
58
- * Make an option boolean, i.e. option without value.
59
- *
60
- * @returns {COA.Opt} - this instance (for chainability)
61
- */
62
- flag() {
63
- this._flag = true;
64
- return this;
65
- }
21
+ exports.Opt = Opt = (function() {
22
+ /**
23
+ @constructs
24
+ @param {COA.Cmd} cmd parent command
25
+ */
66
26
 
67
- /**
68
- * Makes an option to act as a command,
69
- * i.e. program will exit just after option action.
70
- *
71
- * @returns {COA.Opt} - this instance (for chainability)
72
- */
73
- only() {
74
- this._only = true;
75
- return this;
76
- }
27
+ function Opt(_cmd) {
28
+ this._cmd = _cmd;
29
+ this._cmd._opts.push(this);
30
+ }
77
31
 
78
- /**
79
- * Add action for current option command.
80
- * This action is performed if the current option
81
- * is present in parsed options (with any value).
82
- *
83
- * @param {Function} act - action function,
84
- * invoked in the context of command instance
85
- * and has the parameters:
86
- * - {Object} opts - parsed options
87
- * - {Array} args - parsed arguments
88
- * - {Object} res - actions result accumulator
89
- * It can return rejected promise by Cmd.reject (in case of error)
90
- * or any other value treated as result.
91
- * @returns {COA.Opt} - this instance (for chainability)
92
- */
93
- act(act) {
94
- // Need function here for arguments
95
- const opt = this;
96
- this._cmd.act(function(opts) {
97
- if(!opts.hasOwnProperty(opt._name)) return;
98
-
99
- const res = act.apply(this, arguments);
100
- if(!opt._only) return res;
101
-
102
- return Q.when(res, out => this.reject({
103
- toString : () => out.toString(),
104
- exitCode : 0
105
- }));
106
- });
107
-
108
- return this;
109
- }
32
+ /**
33
+ Set a canonical option identifier to be used anywhere in the API.
34
+ @param {String} _name option name
35
+ @returns {COA.Opt} this instance (for chainability)
36
+ */
110
37
 
111
- _saveVal(opts, val) {
112
- this._val && (val = this._val(val));
113
38
 
114
- const name = this._name;
115
- this._arr
116
- ? (opts[name] || (opts[name] = [])).push(val)
117
- : (opts[name] = val);
39
+ Opt.prototype.name = function(_name) {
40
+ this._name = _name;
41
+ return this;
42
+ };
118
43
 
119
- return val;
120
- }
44
+ /**
45
+ Set a long description for option to be used anywhere in text messages.
46
+ @param {String} _title option title
47
+ @returns {COA.Opt} this instance (for chainability)
48
+ */
121
49
 
122
- _parse(argv, opts) {
123
- return this._saveVal(opts, this._flag ? true : argv.shift());
124
- }
125
50
 
126
- _checkParsed(opts) {
127
- return !opts.hasOwnProperty(this._name);
128
- }
51
+ Opt.prototype.title = Cmd.prototype.title;
52
+
53
+ /**
54
+ Set a short key for option to be used with one hyphen from command line.
55
+ @param {String} _short
56
+ @returns {COA.Opt} this instance (for chainability)
57
+ */
58
+
59
+
60
+ Opt.prototype.short = function(_short) {
61
+ this._short = _short;
62
+ return this._cmd._optsByKey['-' + _short] = this;
63
+ };
64
+
65
+ /**
66
+ Set a short key for option to be used with double hyphens from command line.
67
+ @param {String} _long
68
+ @returns {COA.Opt} this instance (for chainability)
69
+ */
70
+
71
+
72
+ Opt.prototype.long = function(_long) {
73
+ this._long = _long;
74
+ return this._cmd._optsByKey['--' + _long] = this;
75
+ };
76
+
77
+ /**
78
+ Make an option boolean, i.e. option without value.
79
+ @returns {COA.Opt} this instance (for chainability)
80
+ */
81
+
82
+
83
+ Opt.prototype.flag = function() {
84
+ this._flag = true;
85
+ return this;
86
+ };
87
+
88
+ /**
89
+ Makes an option accepts multiple values.
90
+ Otherwise, the value will be used by the latter passed.
91
+ @returns {COA.Opt} this instance (for chainability)
92
+ */
93
+
94
+
95
+ Opt.prototype.arr = function() {
96
+ this._arr = true;
97
+ return this;
98
+ };
99
+
100
+ /**
101
+ Makes an option required.
102
+ @returns {COA.Opt} this instance (for chainability)
103
+ */
104
+
105
+
106
+ Opt.prototype.req = function() {
107
+ this._req = true;
108
+ return this;
109
+ };
110
+
111
+ /**
112
+ Makes an option to act as a command,
113
+ i.e. program will exit just after option action.
114
+ @returns {COA.Opt} this instance (for chainability)
115
+ */
116
+
117
+
118
+ Opt.prototype.only = function() {
119
+ this._only = true;
120
+ return this;
121
+ };
122
+
123
+ /**
124
+ Set a validation (or value) function for option.
125
+ Value from command line passes through before becoming available from API.
126
+ Using for validation and convertion simple types to any values.
127
+ @param {Function} _val validating function,
128
+ invoked in the context of option instance
129
+ and has one parameter with value from command line
130
+ @returns {COA.Opt} this instance (for chainability)
131
+ */
129
132
 
130
- _usage() {
131
- const res = [],
132
- nameStr = this._name.toUpperCase();
133
133
 
134
- if(this._short) {
135
- res.push('-', Color('lgreen', this._short));
136
- this._flag || res.push(' ' + nameStr);
137
- res.push(', ');
134
+ Opt.prototype.val = function(_val) {
135
+ this._val = _val;
136
+ return this;
137
+ };
138
+
139
+ /**
140
+ Set a default value for option.
141
+ Default value passed through validation function as ordinary value.
142
+ @param {Object} _def
143
+ @returns {COA.Opt} this instance (for chainability)
144
+ */
145
+
146
+
147
+ Opt.prototype.def = function(_def) {
148
+ this._def = _def;
149
+ return this;
150
+ };
151
+
152
+ /**
153
+ Make option value inputting stream.
154
+ It's add useful validation and shortcut for STDIN.
155
+ @returns {COA.Opt} this instance (for chainability)
156
+ */
157
+
158
+
159
+ Opt.prototype.input = function() {
160
+ process.stdin.pause();
161
+ return this.def(process.stdin).val(function(v) {
162
+ var s;
163
+ if (typeof v === 'string') {
164
+ if (v === '-') {
165
+ return process.stdin;
166
+ } else {
167
+ s = fs.createReadStream(v, {
168
+ encoding: 'utf8'
169
+ });
170
+ s.pause();
171
+ return s;
138
172
  }
173
+ } else {
174
+ return v;
175
+ }
176
+ });
177
+ };
178
+
179
+ /**
180
+ Make option value outputing stream.
181
+ It's add useful validation and shortcut for STDOUT.
182
+ @returns {COA.Opt} this instance (for chainability)
183
+ */
184
+
139
185
 
140
- if(this._long) {
141
- res.push('--', Color('green', this._long));
142
- this._flag || res.push('=' + nameStr);
186
+ Opt.prototype.output = function() {
187
+ return this.def(process.stdout).val(function(v) {
188
+ if (typeof v === 'string') {
189
+ if (v === '-') {
190
+ return process.stdout;
191
+ } else {
192
+ return fs.createWriteStream(v, {
193
+ encoding: 'utf8'
194
+ });
143
195
  }
196
+ } else {
197
+ return v;
198
+ }
199
+ });
200
+ };
144
201
 
145
- res.push(' : ', this._title);
202
+ /**
203
+ Add action for current option command.
204
+ This action is performed if the current option
205
+ is present in parsed options (with any value).
206
+ @param {Function} act action function,
207
+ invoked in the context of command instance
208
+ and has the parameters:
209
+ - {Object} opts parsed options
210
+ - {Array} args parsed arguments
211
+ - {Object} res actions result accumulator
212
+ It can return rejected promise by Cmd.reject (in case of error)
213
+ or any other value treated as result.
214
+ @returns {COA.Opt} this instance (for chainability)
215
+ */
146
216
 
147
- this._req && res.push(' ', Color('lred', '(required)'));
148
217
 
149
- return res.join('');
218
+ Opt.prototype.act = function(act) {
219
+ var name, opt;
220
+ opt = this;
221
+ name = this._name;
222
+ this._cmd.act(function(opts) {
223
+ var res,
224
+ _this = this;
225
+ if (name in opts) {
226
+ res = act.apply(this, arguments);
227
+ if (opt._only) {
228
+ return Q.when(res, function(res) {
229
+ return _this.reject({
230
+ toString: function() {
231
+ return res.toString();
232
+ },
233
+ exitCode: 0
234
+ });
235
+ });
236
+ } else {
237
+ return res;
238
+ }
239
+ }
240
+ });
241
+ return this;
242
+ };
243
+
244
+ /**
245
+ Set custom additional completion for current option.
246
+ @param {Function} completion generation function,
247
+ invoked in the context of option instance.
248
+ Accepts parameters:
249
+ - {Object} opts completion options
250
+ It can return promise or any other value treated as result.
251
+ @returns {COA.Opt} this instance (for chainability)
252
+ */
253
+
254
+
255
+ Opt.prototype.comp = Cmd.prototype.comp;
256
+
257
+ Opt.prototype._saveVal = function(opts, val) {
258
+ var _name;
259
+ if (this._val) {
260
+ val = this._val(val);
261
+ }
262
+ if (this._arr) {
263
+ (opts[_name = this._name] || (opts[_name] = [])).push(val);
264
+ } else {
265
+ opts[this._name] = val;
150
266
  }
267
+ return val;
268
+ };
269
+
270
+ Opt.prototype._parse = function(argv, opts) {
271
+ return this._saveVal(opts, this._flag ? true : argv.shift());
272
+ };
151
273
 
152
- _requiredText() {
153
- return `Missing required option:\n ${this._usage()}`;
274
+ Opt.prototype._checkParsed = function(opts, args) {
275
+ return !opts.hasOwnProperty(this._name);
276
+ };
277
+
278
+ Opt.prototype._usage = function() {
279
+ var nameStr, res;
280
+ res = [];
281
+ nameStr = this._name.toUpperCase();
282
+ if (this._short) {
283
+ res.push('-', Color('lgreen', this._short));
284
+ if (!this._flag) {
285
+ res.push(' ' + nameStr);
286
+ }
287
+ res.push(', ');
288
+ }
289
+ if (this._long) {
290
+ res.push('--', Color('green', this._long));
291
+ if (!this._flag) {
292
+ res.push('=' + nameStr);
293
+ }
154
294
  }
155
- };
295
+ res.push(' : ', this._title);
296
+ if (this._req) {
297
+ res.push(' ', Color('lred', '(required)'));
298
+ }
299
+ return res.join('');
300
+ };
301
+
302
+ Opt.prototype._requiredText = function() {
303
+ return 'Missing required option:\n ' + this._usage();
304
+ };
305
+
306
+ /**
307
+ Return rejected promise with error code.
308
+ Use in .val() for return with error.
309
+ @param {Object} reject reason
310
+ You can customize toString() method and exitCode property
311
+ of reason object.
312
+ @returns {Q.promise} rejected promise
313
+ */
314
+
315
+
316
+ Opt.prototype.reject = Cmd.prototype.reject;
317
+
318
+ /**
319
+ Finish chain for current option and return parent command instance.
320
+ @returns {COA.Cmd} parent command
321
+ */
322
+
323
+
324
+ Opt.prototype.end = Cmd.prototype.end;
325
+
326
+ /**
327
+ Apply function with arguments in context of option instance.
328
+ @param {Function} fn
329
+ @param {Array} args
330
+ @returns {COA.Opt} this instance (for chainability)
331
+ */
332
+
333
+
334
+ Opt.prototype.apply = Cmd.prototype.apply;
335
+
336
+ return Opt;
337
+
338
+ })();
package/lib/shell.js CHANGED
@@ -1,14 +1,14 @@
1
- module.exports = { escape, unescape };
1
+ // Generated by CoffeeScript 1.6.3
2
+ exports.unescape = function(w) {
3
+ w = w.charAt(0) === '"' ? w.replace(/^"|([^\\])"$/g, '$1') : w.replace(/\\ /g, ' ');
4
+ return w.replace(/\\("|'|\$|`|\\)/g, '$1');
5
+ };
2
6
 
3
- function unescape(w) {
4
- w = w.charAt(0) === '"'
5
- ? w.replace(/^"|([^\\])"$/g, '$1')
6
- : w.replace(/\\ /g, ' ');
7
-
8
- return w.replace(/\\("|'|\$|`|\\)/g, '$1');
9
- }
10
-
11
- function escape(w) {
12
- w = w.replace(/(["'$`\\])/g,'\\$1');
13
- return w.match(/\s+/) ? `"${w}"` : w;
14
- }
7
+ exports.escape = function(w) {
8
+ w = w.replace(/(["'$`\\])/g, '\\$1');
9
+ if (w.match(/\s+/)) {
10
+ return '"' + w + '"';
11
+ } else {
12
+ return w;
13
+ }
14
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "coa",
3
3
  "description": "Command-Option-Argument: Yet another parser for command line options.",
4
- "version": "1.0.3",
4
+ "version": "1.0.4",
5
5
  "homepage": "http://github.com/veged/coa",
6
6
  "author": "Sergey Berezhnoy <veged@ya.ru> (http://github.com/veged)",
7
7
  "maintainers": [
@@ -11,11 +11,6 @@
11
11
  "contributors": [
12
12
  "Sergey Belov <peimei@ya.ru> (http://github.com/arikon)"
13
13
  ],
14
- "files": [
15
- "lib/",
16
- "index.js",
17
- "README.ru.md"
18
- ],
19
14
  "repository": {
20
15
  "type": "git",
21
16
  "url": "git://github.com/veged/coa.git"
@@ -27,23 +22,23 @@
27
22
  "q": "^1.1.2"
28
23
  },
29
24
  "devDependencies": {
30
- "chai": "~1.7.2",
31
- "coveralls": "^2.11.16",
32
- "eslint": "^3.15.0",
33
- "eslint-config-pedant": "^0.8.0",
25
+ "coffee-script": "~1.6.3",
26
+ "istanbul": "~0.1.40",
27
+ "mocha-istanbul": "*",
34
28
  "mocha": "~1.21.4",
35
- "nyc": "^10.1.2"
29
+ "chai": "~1.7.2"
36
30
  },
37
31
  "scripts": {
38
- "clean": "rm -r .nyc_output coverage",
39
- "coverage": "nyc --reporter=text --reporter=html mocha; echo; echo 'Open coverage/index.html file in your browser'",
40
- "coveralls": "nyc report --reporter=text-lcov | coveralls",
41
- "lint": "eslint .",
42
- "pretest": "npm run lint",
43
- "test": "nyc mocha"
32
+ "test": "make test",
33
+ "coverage": "make coverage"
44
34
  },
45
35
  "engines": {
46
- "node": ">= 4.0"
36
+ "node": ">= 0.8.0"
47
37
  },
48
- "license": "MIT"
38
+ "licenses": [
39
+ {
40
+ "type": "MIT"
41
+ }
42
+ ],
43
+ "optionalDependencies": {}
49
44
  }
package/qq.js ADDED
@@ -0,0 +1,17 @@
1
+ const run = require('./test/util').run;
2
+
3
+ // run(cmd => cmd.arg().name('qwe').end().arg().name('zxc').end().act(function(opts, args) { console.log({opts, args}); }), ['qwe', 'zxc']) // cmd and args
4
+ // .then(res => {
5
+ // // code
6
+ // // stdout
7
+ // // stderr
8
+ // console.log(res);
9
+ // });
10
+
11
+ run(cmd => cmd.opt().name('version').short('v').only().flag().act((opts) => { return 'aasd'; }), ['-v']) // cmd and args
12
+ .then(res => {
13
+ // code
14
+ // stdout
15
+ // stderr
16
+ console.log(res);
17
+ });
package/src/arg.coffee ADDED
@@ -0,0 +1,130 @@
1
+ Color = require('./color').Color
2
+ Cmd = require('./cmd').Cmd
3
+ Opt = require('./opt').Opt
4
+
5
+ ###*
6
+ Argument
7
+
8
+ Unnamed entity. From command line arguments passed as list of unnamed values.
9
+ @namespace
10
+ @class Presents argument
11
+ ###
12
+ exports.Arg = class Arg
13
+
14
+ ###*
15
+ @constructs
16
+ @param {COA.Cmd} cmd parent command
17
+ ###
18
+ constructor: (@_cmd) -> @_cmd._args.push @
19
+
20
+ ###*
21
+ Set a canonical argument identifier to be used anywhere in text messages.
22
+ @param {String} _name argument name
23
+ @returns {COA.Arg} this instance (for chainability)
24
+ ###
25
+ name: Opt::name
26
+
27
+ ###*
28
+ Set a long description for argument to be used anywhere in text messages.
29
+ @param {String} _title argument title
30
+ @returns {COA.Arg} this instance (for chainability)
31
+ ###
32
+ title: Cmd::title
33
+
34
+ ###*
35
+ Makes an argument accepts multiple values.
36
+ Otherwise, the value will be used by the latter passed.
37
+ @returns {COA.Arg} this instance (for chainability)
38
+ ###
39
+ arr: Opt::arr
40
+
41
+ ###*
42
+ Makes an argument required.
43
+ @returns {COA.Arg} this instance (for chainability)
44
+ ###
45
+ req: Opt::req
46
+
47
+ ###*
48
+ Set a validation (or value) function for argument.
49
+ Value from command line passes through before becoming available from API.
50
+ Using for validation and convertion simple types to any values.
51
+ @param {Function} _val validating function,
52
+ invoked in the context of argument instance
53
+ and has one parameter with value from command line
54
+ @returns {COA.Arg} this instance (for chainability)
55
+ ###
56
+ val: Opt::val
57
+
58
+ ###*
59
+ Set a default value for argument.
60
+ Default value passed through validation function as ordinary value.
61
+ @param {Object} _def
62
+ @returns {COA.Arg} this instance (for chainability)
63
+ ###
64
+ def: Opt::def
65
+
66
+ ###*
67
+ Set custom additional completion for current argument.
68
+ @param {Function} completion generation function,
69
+ invoked in the context of argument instance.
70
+ Accepts parameters:
71
+ - {Object} opts completion options
72
+ It can return promise or any other value treated as result.
73
+ @returns {COA.Arg} this instance (for chainability)
74
+ ###
75
+ comp: Cmd::comp
76
+
77
+ ###*
78
+ Make argument value inputting stream.
79
+ It's add useful validation and shortcut for STDIN.
80
+ @returns {COA.Arg} this instance (for chainability)
81
+ ###
82
+ input: Opt::input
83
+
84
+ ###*
85
+ Make argument value outputing stream.
86
+ It's add useful validation and shortcut for STDOUT.
87
+ @returns {COA.Arg} this instance (for chainability)
88
+ ###
89
+ output: Opt::output
90
+
91
+ _parse: (arg, args) ->
92
+ @_saveVal(args, arg)
93
+
94
+ _saveVal: Opt::_saveVal
95
+
96
+ _checkParsed: (opts, args) -> not args.hasOwnProperty(@_name)
97
+
98
+ _usage: ->
99
+ res = []
100
+
101
+ res.push Color('lpurple', @_name.toUpperCase()), ' : ', @_title
102
+ if @_req then res.push ' ', Color('lred', '(required)')
103
+
104
+ res.join ''
105
+
106
+ _requiredText: -> 'Missing required argument:\n ' + @_usage()
107
+
108
+ ###*
109
+ Return rejected promise with error code.
110
+ Use in .val() for return with error.
111
+ @param {Object} reject reason
112
+ You can customize toString() method and exitCode property
113
+ of reason object.
114
+ @returns {Q.promise} rejected promise
115
+ ###
116
+ reject: Cmd::reject
117
+
118
+ ###*
119
+ Finish chain for current option and return parent command instance.
120
+ @returns {COA.Cmd} parent command
121
+ ###
122
+ end: Cmd::end
123
+
124
+ ###*
125
+ Apply function with arguments in context of arg instance.
126
+ @param {Function} fn
127
+ @param {Array} args
128
+ @returns {COA.Arg} this instance (for chainability)
129
+ ###
130
+ apply: Cmd::apply