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/coaparam.js
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
const fs = require('fs');
|
4
|
-
|
5
|
-
const CoaObject = require('./coaobject');
|
6
|
-
|
7
|
-
/**
|
8
|
-
* COA Parameter
|
9
|
-
*
|
10
|
-
* Base class for options and arguments
|
11
|
-
*
|
12
|
-
* --------|-----|-----|-----
|
13
|
-
* | Cmd | Opt | Arg
|
14
|
-
* --------|-----|-----|-----
|
15
|
-
* arr | | ✓ | ✓
|
16
|
-
* req | | ✓ | ✓
|
17
|
-
* val | | ✓ | ✓
|
18
|
-
* def | | ✓ | ✓
|
19
|
-
* input | | ✓ | ✓
|
20
|
-
* output | | ✓ | ✓
|
21
|
-
*
|
22
|
-
* @class CoaParam
|
23
|
-
* @extends CoaObject
|
24
|
-
*/
|
25
|
-
module.exports = class CoaParam extends CoaObject {
|
26
|
-
constructor(cmd) {
|
27
|
-
super(cmd);
|
28
|
-
|
29
|
-
this._arr = false;
|
30
|
-
this._req = false;
|
31
|
-
this._val = undefined;
|
32
|
-
this._def = undefined;
|
33
|
-
}
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Makes a param accepts multiple values.
|
37
|
-
* Otherwise, the value will be used by the latter passed.
|
38
|
-
*
|
39
|
-
* @returns {COA.CoaParam} - this instance (for chainability)
|
40
|
-
*/
|
41
|
-
arr() {
|
42
|
-
this._arr = true;
|
43
|
-
return this;
|
44
|
-
}
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Makes a param required.
|
48
|
-
*
|
49
|
-
* @returns {COA.CoaParam} - this instance (for chainability)
|
50
|
-
*/
|
51
|
-
req() {
|
52
|
-
this._req = true;
|
53
|
-
return this;
|
54
|
-
}
|
55
|
-
|
56
|
-
/**
|
57
|
-
* Set a validation (or value) function for param.
|
58
|
-
* Value from command line passes through before becoming available from API.
|
59
|
-
* Using for validation and convertion simple types to any values.
|
60
|
-
*
|
61
|
-
* @param {Function} val - validating function,
|
62
|
-
* invoked in the context of option instance
|
63
|
-
* and has one parameter with value from command line.
|
64
|
-
* @returns {COA.CoaParam} - this instance (for chainability)
|
65
|
-
*/
|
66
|
-
val(val) {
|
67
|
-
this._val = val;
|
68
|
-
return this;
|
69
|
-
}
|
70
|
-
|
71
|
-
/**
|
72
|
-
* Set a default value for param.
|
73
|
-
* Default value passed through validation function as ordinary value.
|
74
|
-
*
|
75
|
-
* @param {*} def - default value of function generator
|
76
|
-
* @returns {COA.CoaParam} - this instance (for chainability)
|
77
|
-
*/
|
78
|
-
def(def) {
|
79
|
-
this._def = def;
|
80
|
-
return this;
|
81
|
-
}
|
82
|
-
|
83
|
-
/**
|
84
|
-
* Make option value inputting stream.
|
85
|
-
* It's add useful validation and shortcut for STDIN.
|
86
|
-
*
|
87
|
-
* @returns {COA.CoaParam} - this instance (for chainability)
|
88
|
-
*/
|
89
|
-
input() {
|
90
|
-
process.stdin.pause();
|
91
|
-
return this
|
92
|
-
.def(process.stdin)
|
93
|
-
.val(function(v) {
|
94
|
-
if(typeof v !== 'string')
|
95
|
-
return v;
|
96
|
-
|
97
|
-
if(v === '-')
|
98
|
-
return process.stdin;
|
99
|
-
|
100
|
-
const s = fs.createReadStream(v, { encoding : 'utf8' });
|
101
|
-
s.pause();
|
102
|
-
return s;
|
103
|
-
});
|
104
|
-
}
|
105
|
-
|
106
|
-
/**
|
107
|
-
* Make option value outputing stream.
|
108
|
-
* It's add useful validation and shortcut for STDOUT.
|
109
|
-
*
|
110
|
-
* @returns {COA.CoaParam} - this instance (for chainability)
|
111
|
-
*/
|
112
|
-
output() {
|
113
|
-
return this
|
114
|
-
.def(process.stdout)
|
115
|
-
.val(function(v) {
|
116
|
-
if(typeof v !== 'string')
|
117
|
-
return v;
|
118
|
-
|
119
|
-
if(v === '-')
|
120
|
-
return process.stdout;
|
121
|
-
|
122
|
-
return fs.createWriteStream(v, { encoding : 'utf8' });
|
123
|
-
});
|
124
|
-
}
|
125
|
-
};
|