coa 2.0.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
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
- Color = require('./color');
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(Color('lpurple', this._name.toUpperCase()), ' : ', this._title);
48
+ res.push(chalk.magentaBright(this._name.toUpperCase()), ' : ', this._title);
49
49
 
50
- this._req && res.push(' ', Color('lred', '(required)'));
50
+ this._req && res.push(' ', chalk.redBright('(required)'));
51
51
 
52
52
  return res.join('');
53
53
  }
package/lib/cmd.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable class-methods-use-this */
1
2
  'use strict';
2
3
 
3
4
  const
@@ -6,9 +7,9 @@ const
6
7
  EOL = require('os').EOL,
7
8
 
8
9
  Q = require('q'),
10
+ chalk = require('chalk'),
9
11
 
10
12
  CoaObject = require('./coaobject'),
11
- Color = require('./color'),
12
13
  Opt = require('./opt'),
13
14
  Arg = require('./arg'),
14
15
  completion = require('./completion');
@@ -191,9 +192,9 @@ class Cmd extends CoaObject {
191
192
  }
192
193
 
193
194
  _exit(msg, code) {
194
- return process.once('exit', function() {
195
+ return process.once('exit', function(exitCode) {
195
196
  msg && console[code === 0 ? 'log' : 'error'](msg);
196
- process.exit(code || 0);
197
+ process.exit(code || exitCode || 0);
197
198
  });
198
199
  }
199
200
 
@@ -211,14 +212,14 @@ class Cmd extends CoaObject {
211
212
 
212
213
  this._cmds.length
213
214
  && res.push([
214
- '', '', Color('lred', this._fullName()), Color('lblue', 'COMMAND'),
215
- Color('lgreen', '[OPTIONS]'), Color('lpurple', '[ARGS]')
215
+ '', '', chalk.redBright(this._fullName()), chalk.blueBright('COMMAND'),
216
+ chalk.greenBright('[OPTIONS]'), chalk.magentaBright('[ARGS]')
216
217
  ].join(' '));
217
218
 
218
219
  (this._opts.length + this._args.length)
219
220
  && res.push([
220
- '', '', Color('lred', this._fullName()),
221
- Color('lgreen', '[OPTIONS]'), Color('lpurple', '[ARGS]')
221
+ '', '', chalk.redBright(this._fullName()),
222
+ chalk.greenBright('[OPTIONS]'), chalk.magentaBright('[ARGS]')
222
223
  ].join(' '));
223
224
 
224
225
  res.push(
@@ -231,7 +232,7 @@ class Cmd extends CoaObject {
231
232
  }
232
233
 
233
234
  _usage() {
234
- return Color('lblue', this._name) + ' : ' + this._title;
235
+ return chalk.blueBright(this._name) + ' : ' + this._title;
235
236
  }
236
237
 
237
238
  _usages(os, title) {
@@ -369,7 +370,7 @@ class Cmd extends CoaObject {
369
370
 
370
371
  _setDefaults(params, desc) {
371
372
  for(const item of desc)
372
- item._def &&
373
+ item._def !== undefined &&
373
374
  !params.hasOwnProperty(item._name) &&
374
375
  item._saveVal(params, item._def);
375
376
 
package/lib/coaobject.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable class-methods-use-this */
1
2
  'use strict';
2
3
 
3
4
  const Q = require('q');
package/lib/completion.js CHANGED
@@ -62,7 +62,7 @@ function dumpScript(name) {
62
62
 
63
63
  fs.readFile(path.resolve(__dirname, 'completion.sh'), 'utf8', function(err, d) {
64
64
  if(err) return defer.reject(err);
65
- d = d.replace(/{{cmd}}/g, path.basename(name)).replace(/^\#\!.*?\n/, '');
65
+ d = d.replace(/{{cmd}}/g, path.basename(name)).replace(/^#!.*?\n/, '');
66
66
 
67
67
  process.stdout.on('error', onError);
68
68
  process.stdout.write(d, () => defer.resolve());
package/lib/opt.js CHANGED
@@ -4,7 +4,7 @@ const
4
4
  Q = require('q'),
5
5
 
6
6
  CoaParam = require('./coaparam'),
7
- Color = require('./color');
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('-', Color('lgreen', this._short));
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('--', Color('green', this._long));
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(' ', Color('lred', '(required)'));
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.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,13 +25,15 @@
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": {
30
33
  "chai": "~1.7.2",
31
34
  "coveralls": "^2.11.16",
32
- "eslint": "^3.15.0",
33
- "eslint-config-pedant": "^0.8.0",
35
+ "eslint": "^4.15.0",
36
+ "eslint-config-pedant": "^1.0.0",
34
37
  "mocha": "~1.21.4",
35
38
  "nyc": "^10.1.2"
36
39
  },
@@ -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`;