coa 2.0.1 → 2.0.2
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.
- package/coa.d.ts +74 -0
- package/lib/arg.js +3 -3
- package/lib/cmd.js +7 -7
- package/lib/opt.js +4 -4
- package/package.json +5 -1
- package/lib/color.js +0 -22
package/coa.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/// <reference types="q"/>
|
|
2
|
+
|
|
3
|
+
export const Arg: undefined;
|
|
4
|
+
|
|
5
|
+
export const Opt: undefined;
|
|
6
|
+
|
|
7
|
+
export function Cmd(cmd?: classes.Cmd): classes.Cmd;
|
|
8
|
+
|
|
9
|
+
export namespace classes {
|
|
10
|
+
class Arg {
|
|
11
|
+
constructor(cmd: Cmd);
|
|
12
|
+
name(name: string): Arg;
|
|
13
|
+
title(title: string): Arg;
|
|
14
|
+
arr(): Arg;
|
|
15
|
+
req(): Arg;
|
|
16
|
+
val(validation: (this: Arg, value: any) => boolean): Arg;
|
|
17
|
+
def(def: any): Arg;
|
|
18
|
+
output(): Arg;
|
|
19
|
+
comp(fn: (opts: any) => any): Arg;
|
|
20
|
+
end(): Cmd;
|
|
21
|
+
apply(...args: any[]): Arg;
|
|
22
|
+
input(): Arg;
|
|
23
|
+
reject(...args: any[]): Arg;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class Cmd {
|
|
27
|
+
constructor(cmd?: Cmd);
|
|
28
|
+
static create(cmd?: Cmd): Cmd;
|
|
29
|
+
api(): any;
|
|
30
|
+
name(name: string): Cmd;
|
|
31
|
+
title(title: string): Cmd;
|
|
32
|
+
cmd(cmd?: Cmd): Cmd;
|
|
33
|
+
opt(): Opt;
|
|
34
|
+
arg(): Arg;
|
|
35
|
+
act(act: (opts: any, args: any[], res: any) => any, force?: boolean): Cmd;
|
|
36
|
+
apply(fn: Function, args?: any[]): Cmd;
|
|
37
|
+
comp(fs: (opts: any) => any): Cmd;
|
|
38
|
+
helpful(): Cmd;
|
|
39
|
+
completable(): Cmd;
|
|
40
|
+
usage(): string;
|
|
41
|
+
run(argv: string[]): Cmd;
|
|
42
|
+
invoke(cmds?: string|string[], opts?: any, args?: any): Q.Promise<any>;
|
|
43
|
+
reject(reason: any): Q.Promise<any>;
|
|
44
|
+
end(): Cmd;
|
|
45
|
+
do(argv: string[]): any;
|
|
46
|
+
extendable(pattern?: string): Cmd;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class Opt {
|
|
50
|
+
constructor(cmd?: Cmd);
|
|
51
|
+
name(name: string): Opt;
|
|
52
|
+
title(title: string): Opt;
|
|
53
|
+
short(short: string): Opt;
|
|
54
|
+
long(long: string): Opt;
|
|
55
|
+
flag(): Opt;
|
|
56
|
+
arr(): Opt;
|
|
57
|
+
req(): Opt;
|
|
58
|
+
only(): Opt;
|
|
59
|
+
val(validation: (this: Opt, value: any) => boolean): Opt;
|
|
60
|
+
def(def: any): Opt;
|
|
61
|
+
input(): Opt;
|
|
62
|
+
output(): Opt;
|
|
63
|
+
act(act: (opts: any, args: any[], res: any) => any): Opt;
|
|
64
|
+
comp(fn: (opts: any) => any): Opt;
|
|
65
|
+
end(): Cmd;
|
|
66
|
+
apply(...args: any[]): void;
|
|
67
|
+
reject(...args: any[]): void;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export namespace shell {
|
|
72
|
+
function escape(w: string): string;
|
|
73
|
+
function unescape(w: string): string;
|
|
74
|
+
}
|
package/lib/arg.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const
|
|
4
4
|
CoaParam = require('./coaparam'),
|
|
5
|
-
|
|
5
|
+
chalk = require('chalk');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Argument
|
|
@@ -45,9 +45,9 @@ module.exports = class Arg extends CoaParam {
|
|
|
45
45
|
_usage() {
|
|
46
46
|
const res = [];
|
|
47
47
|
|
|
48
|
-
res.push(
|
|
48
|
+
res.push(chalk.magentaBright(this._name.toUpperCase()), ' : ', this._title);
|
|
49
49
|
|
|
50
|
-
this._req && res.push(' ',
|
|
50
|
+
this._req && res.push(' ', chalk.redBright('(required)'));
|
|
51
51
|
|
|
52
52
|
return res.join('');
|
|
53
53
|
}
|
package/lib/cmd.js
CHANGED
|
@@ -7,9 +7,9 @@ const
|
|
|
7
7
|
EOL = require('os').EOL,
|
|
8
8
|
|
|
9
9
|
Q = require('q'),
|
|
10
|
+
chalk = require('chalk'),
|
|
10
11
|
|
|
11
12
|
CoaObject = require('./coaobject'),
|
|
12
|
-
Color = require('./color'),
|
|
13
13
|
Opt = require('./opt'),
|
|
14
14
|
Arg = require('./arg'),
|
|
15
15
|
completion = require('./completion');
|
|
@@ -212,14 +212,14 @@ class Cmd extends CoaObject {
|
|
|
212
212
|
|
|
213
213
|
this._cmds.length
|
|
214
214
|
&& res.push([
|
|
215
|
-
'', '',
|
|
216
|
-
|
|
215
|
+
'', '', chalk.redBright(this._fullName()), chalk.blueBright('COMMAND'),
|
|
216
|
+
chalk.greenBright('[OPTIONS]'), chalk.magentaBright('[ARGS]')
|
|
217
217
|
].join(' '));
|
|
218
218
|
|
|
219
219
|
(this._opts.length + this._args.length)
|
|
220
220
|
&& res.push([
|
|
221
|
-
'', '',
|
|
222
|
-
|
|
221
|
+
'', '', chalk.redBright(this._fullName()),
|
|
222
|
+
chalk.greenBright('[OPTIONS]'), chalk.magentaBright('[ARGS]')
|
|
223
223
|
].join(' '));
|
|
224
224
|
|
|
225
225
|
res.push(
|
|
@@ -232,7 +232,7 @@ class Cmd extends CoaObject {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
_usage() {
|
|
235
|
-
return
|
|
235
|
+
return chalk.blueBright(this._name) + ' : ' + this._title;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
_usages(os, title) {
|
|
@@ -370,7 +370,7 @@ class Cmd extends CoaObject {
|
|
|
370
370
|
|
|
371
371
|
_setDefaults(params, desc) {
|
|
372
372
|
for(const item of desc)
|
|
373
|
-
item._def &&
|
|
373
|
+
item._def !== undefined &&
|
|
374
374
|
!params.hasOwnProperty(item._name) &&
|
|
375
375
|
item._saveVal(params, item._def);
|
|
376
376
|
|
package/lib/opt.js
CHANGED
|
@@ -4,7 +4,7 @@ const
|
|
|
4
4
|
Q = require('q'),
|
|
5
5
|
|
|
6
6
|
CoaParam = require('./coaparam'),
|
|
7
|
-
|
|
7
|
+
chalk = require('chalk');
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Option
|
|
@@ -132,19 +132,19 @@ module.exports = class Opt extends CoaParam {
|
|
|
132
132
|
nameStr = this._name.toUpperCase();
|
|
133
133
|
|
|
134
134
|
if(this._short) {
|
|
135
|
-
res.push('-',
|
|
135
|
+
res.push('-', chalk.greenBright(this._short));
|
|
136
136
|
this._flag || res.push(' ' + nameStr);
|
|
137
137
|
res.push(', ');
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
if(this._long) {
|
|
141
|
-
res.push('--',
|
|
141
|
+
res.push('--', chalk.green(this._long));
|
|
142
142
|
this._flag || res.push('=' + nameStr);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
res.push(' : ', this._title);
|
|
146
146
|
|
|
147
|
-
this._req && res.push(' ',
|
|
147
|
+
this._req && res.push(' ', chalk.redBright('(required)'));
|
|
148
148
|
|
|
149
149
|
return res.join('');
|
|
150
150
|
}
|
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": "2.0.
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"homepage": "http://github.com/veged/coa",
|
|
6
6
|
"author": "Sergey Berezhnoy <veged@ya.ru> (http://github.com/veged)",
|
|
7
7
|
"maintainers": [
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"lib/",
|
|
16
16
|
"index.js",
|
|
17
|
+
"coa.d.ts",
|
|
17
18
|
"README.ru.md"
|
|
18
19
|
],
|
|
19
20
|
"repository": {
|
|
@@ -24,6 +25,8 @@
|
|
|
24
25
|
"lib": "./lib"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
28
|
+
"@types/q": "^1.5.1",
|
|
29
|
+
"chalk": "^2.4.1",
|
|
27
30
|
"q": "^1.1.2"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
@@ -45,5 +48,6 @@
|
|
|
45
48
|
"engines": {
|
|
46
49
|
"node": ">= 4.0"
|
|
47
50
|
},
|
|
51
|
+
"types": "./coa.d.ts",
|
|
48
52
|
"license": "MIT"
|
|
49
53
|
}
|
package/lib/color.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
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'
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
module.exports = (c, str) => `\x1B[${colors[c]}m${str}\x1B[m`;
|