@oclif/core 2.0.1 → 2.0.2-beta.10

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 (91) hide show
  1. package/README.md +5 -5
  2. package/lib/args.d.ts +39 -0
  3. package/lib/args.js +62 -0
  4. package/lib/cli-ux/action/base.d.ts +1 -1
  5. package/lib/cli-ux/action/pride-spinner.js +0 -1
  6. package/lib/cli-ux/action/spinner.js +10 -11
  7. package/lib/cli-ux/action/spinners.d.ts +251 -0
  8. package/lib/cli-ux/action/spinners.js +2 -1
  9. package/lib/cli-ux/config.d.ts +1 -1
  10. package/lib/cli-ux/config.js +7 -5
  11. package/lib/cli-ux/index.d.ts +51 -29
  12. package/lib/cli-ux/index.js +111 -69
  13. package/lib/cli-ux/list.js +3 -4
  14. package/lib/cli-ux/prompt.js +9 -8
  15. package/lib/cli-ux/styled/header.js +1 -1
  16. package/lib/cli-ux/styled/index.d.ts +7 -0
  17. package/lib/cli-ux/styled/index.js +15 -0
  18. package/lib/cli-ux/styled/json.d.ts +1 -1
  19. package/lib/cli-ux/styled/json.js +2 -3
  20. package/lib/cli-ux/styled/object.js +1 -1
  21. package/lib/cli-ux/styled/progress.d.ts +2 -1
  22. package/lib/cli-ux/styled/progress.js +3 -7
  23. package/lib/cli-ux/styled/table.js +1 -3
  24. package/lib/cli-ux/styled/tree.js +0 -1
  25. package/lib/cli-ux/wait.d.ts +1 -1
  26. package/lib/cli-ux/wait.js +0 -1
  27. package/lib/command.d.ts +78 -27
  28. package/lib/command.js +51 -43
  29. package/lib/config/config.d.ts +20 -17
  30. package/lib/config/config.js +86 -28
  31. package/lib/config/index.js +0 -5
  32. package/lib/config/plugin.d.ts +3 -2
  33. package/lib/config/plugin.js +10 -14
  34. package/lib/config/util.js +2 -2
  35. package/lib/errors/index.js +0 -1
  36. package/lib/errors/logger.js +2 -4
  37. package/lib/flags.d.ts +46 -18
  38. package/lib/flags.js +71 -29
  39. package/lib/help/command.d.ts +12 -12
  40. package/lib/help/command.js +6 -6
  41. package/lib/help/docopts.d.ts +3 -3
  42. package/lib/help/docopts.js +3 -3
  43. package/lib/help/formatter.d.ts +4 -3
  44. package/lib/help/index.d.ts +10 -14
  45. package/lib/help/index.js +0 -5
  46. package/lib/help/util.d.ts +1 -2
  47. package/lib/help/util.js +2 -1
  48. package/lib/index.d.ts +6 -5
  49. package/lib/index.js +10 -8
  50. package/lib/interfaces/args.d.ts +22 -0
  51. package/lib/interfaces/{command.js → args.js} +0 -0
  52. package/lib/interfaces/config.d.ts +1 -2
  53. package/lib/interfaces/flags.d.ts +2 -2
  54. package/lib/interfaces/hooks.d.ts +12 -1
  55. package/lib/interfaces/index.d.ts +2 -2
  56. package/lib/interfaces/manifest.d.ts +2 -2
  57. package/lib/interfaces/parser.d.ts +97 -82
  58. package/lib/interfaces/pjson.d.ts +2 -0
  59. package/lib/interfaces/plugin.d.ts +2 -1
  60. package/lib/main.d.ts +54 -1
  61. package/lib/main.js +71 -7
  62. package/lib/parser/errors.d.ts +15 -8
  63. package/lib/parser/errors.js +17 -14
  64. package/lib/parser/help.d.ts +1 -1
  65. package/lib/parser/help.js +4 -9
  66. package/lib/parser/index.d.ts +2 -9
  67. package/lib/parser/index.js +5 -26
  68. package/lib/parser/parse.d.ts +4 -11
  69. package/lib/parser/parse.js +107 -72
  70. package/lib/parser/validate.d.ts +1 -1
  71. package/lib/parser/validate.js +6 -3
  72. package/lib/util.d.ts +20 -0
  73. package/lib/util.js +57 -1
  74. package/package.json +8 -8
  75. package/lib/cli-ux/deps.d.ts +0 -22
  76. package/lib/cli-ux/deps.js +0 -47
  77. package/lib/cli-ux/open.d.ts +0 -6
  78. package/lib/cli-ux/open.js +0 -69
  79. package/lib/help/_test-help-class.d.ts +0 -6
  80. package/lib/help/_test-help-class.js +0 -19
  81. package/lib/interfaces/command.d.ts +0 -110
  82. package/lib/parser/args.d.ts +0 -5
  83. package/lib/parser/args.js +0 -11
  84. package/lib/parser/deps.d.ts +0 -4
  85. package/lib/parser/deps.js +0 -17
  86. package/lib/parser/flags.d.ts +0 -60
  87. package/lib/parser/flags.js +0 -107
  88. package/lib/parser/list.d.ts +0 -2
  89. package/lib/parser/list.js +0 -29
  90. package/lib/parser/util.d.ts +0 -7
  91. package/lib/parser/util.js +0 -50
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Table = exports.ExitError = exports.Config = exports.ActionBase = exports.config = exports.ux = void 0;
3
+ exports.warn = exports.wait = exports.url = exports.tree = exports.trace = exports.Table = exports.table = exports.styledObject = exports.styledJSON = exports.styledHeader = exports.prompt = exports.progress = exports.prideAction = exports.log = exports.info = exports.flush = exports.ExitError = exports.exit = exports.error = exports.done = exports.debug = exports.confirm = exports.Config = exports.config = exports.anykey = exports.annotation = exports.ActionBase = exports.action = exports.ux = void 0;
4
4
  const Errors = require("../errors");
5
5
  const util = require("util");
6
6
  const base_1 = require("./action/base");
@@ -8,11 +8,13 @@ Object.defineProperty(exports, "ActionBase", { enumerable: true, get: function (
8
8
  const config_1 = require("./config");
9
9
  Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
10
10
  Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
11
- const deps_1 = require("./deps");
12
11
  const exit_1 = require("./exit");
13
12
  Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
14
- const Table = require("./styled/table");
15
- exports.Table = Table;
13
+ const styled = require("./styled");
14
+ const styled_1 = require("./styled");
15
+ Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return styled_1.Table; } });
16
+ const uxPrompt = require("./prompt");
17
+ const wait_1 = require("./wait");
16
18
  const hyperlinker = require('hyperlinker');
17
19
  function timeout(p, ms) {
18
20
  function wait(ms, unref = false) {
@@ -22,9 +24,9 @@ function timeout(p, ms) {
22
24
  t.unref();
23
25
  });
24
26
  }
25
- return Promise.race([p, wait(ms, true).then(() => exports.ux.error('timed out'))]);
27
+ return Promise.race([p, wait(ms, true).then(() => Errors.error('timed out'))]);
26
28
  }
27
- async function flush() {
29
+ async function _flush() {
28
30
  const p = new Promise(resolve => {
29
31
  process.stdout.once('drain', () => resolve(null));
30
32
  });
@@ -34,74 +36,67 @@ async function flush() {
34
36
  }
35
37
  return p;
36
38
  }
37
- exports.ux = {
38
- config: config_1.config,
39
- warn: Errors.warn,
40
- error: Errors.error,
41
- exit: Errors.exit,
42
- get prompt() {
43
- return deps_1.default.prompt.prompt;
44
- },
39
+ class ux {
40
+ static get prompt() {
41
+ return uxPrompt.prompt;
42
+ }
45
43
  /**
46
44
  * "press anykey to continue"
47
45
  */
48
- get anykey() {
49
- return deps_1.default.prompt.anykey;
50
- },
51
- get confirm() {
52
- return deps_1.default.prompt.confirm;
53
- },
54
- get action() {
46
+ static get anykey() {
47
+ return uxPrompt.anykey;
48
+ }
49
+ static get confirm() {
50
+ return uxPrompt.confirm;
51
+ }
52
+ static get action() {
55
53
  return config_1.config.action;
56
- },
57
- get prideAction() {
54
+ }
55
+ static get prideAction() {
58
56
  return config_1.config.prideAction;
59
- },
60
- styledObject(obj, keys) {
61
- exports.ux.info(deps_1.default.styledObject(obj, keys));
62
- },
63
- get styledHeader() {
64
- return deps_1.default.styledHeader;
65
- },
66
- get styledJSON() {
67
- return deps_1.default.styledJSON;
68
- },
69
- get table() {
70
- return deps_1.default.table;
71
- },
72
- get tree() {
73
- return deps_1.default.tree;
74
- },
75
- get open() {
76
- return deps_1.default.open;
77
- },
78
- get wait() {
79
- return deps_1.default.wait;
80
- },
81
- get progress() {
82
- return deps_1.default.progress;
83
- },
84
- async done() {
57
+ }
58
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
59
+ static styledObject(obj, keys) {
60
+ this.info(styled.styledObject(obj, keys));
61
+ }
62
+ static get styledHeader() {
63
+ return styled.styledHeader;
64
+ }
65
+ static get styledJSON() {
66
+ return styled.styledJSON;
67
+ }
68
+ static get table() {
69
+ return styled.Table.table;
70
+ }
71
+ static get tree() {
72
+ return styled.tree;
73
+ }
74
+ static get wait() {
75
+ return wait_1.default;
76
+ }
77
+ static get progress() {
78
+ return styled.progress;
79
+ }
80
+ static async done() {
85
81
  config_1.config.action.stop();
86
- // await flushStdout()
87
- },
88
- trace(format, ...args) {
82
+ }
83
+ static trace(format, ...args) {
89
84
  if (this.config.outputLevel === 'trace') {
90
85
  process.stdout.write(util.format(format, ...args) + '\n');
91
86
  }
92
- },
93
- debug(format, ...args) {
87
+ }
88
+ static debug(format, ...args) {
94
89
  if (['trace', 'debug'].includes(this.config.outputLevel)) {
95
90
  process.stdout.write(util.format(format, ...args) + '\n');
96
91
  }
97
- },
98
- info(format, ...args) {
92
+ }
93
+ static info(format, ...args) {
99
94
  process.stdout.write(util.format(format, ...args) + '\n');
100
- },
101
- log(format, ...args) {
95
+ }
96
+ static log(format, ...args) {
102
97
  this.info(format || '', ...args);
103
- },
104
- url(text, uri, params = {}) {
98
+ }
99
+ static url(text, uri, params = {}) {
105
100
  const supports = require('supports-hyperlinks');
106
101
  if (supports.stdout) {
107
102
  this.log(hyperlinker(text, uri, params));
@@ -109,8 +104,8 @@ exports.ux = {
109
104
  else {
110
105
  this.log(uri);
111
106
  }
112
- },
113
- annotation(text, annotation) {
107
+ }
108
+ static annotation(text, annotation) {
114
109
  const supports = require('supports-hyperlinks');
115
110
  if (supports.stdout) {
116
111
  // \u001b]8;;https://google.com\u0007sometext\u001b]8;;\u0007
@@ -119,17 +114,64 @@ exports.ux = {
119
114
  else {
120
115
  this.log(text);
121
116
  }
122
- },
123
- async flush(ms = 10000) {
124
- await timeout(flush(), ms);
125
- },
126
- };
117
+ }
118
+ static async flush(ms = 10000) {
119
+ await timeout(_flush(), ms);
120
+ }
121
+ }
122
+ exports.ux = ux;
123
+ ux.config = config_1.config;
124
+ const action = ux.action;
125
+ exports.action = action;
126
+ const annotation = ux.annotation;
127
+ exports.annotation = annotation;
128
+ const anykey = ux.anykey;
129
+ exports.anykey = anykey;
130
+ const confirm = ux.confirm;
131
+ exports.confirm = confirm;
132
+ const debug = ux.debug;
133
+ exports.debug = debug;
134
+ const done = ux.done;
135
+ exports.done = done;
136
+ const error = Errors.error;
137
+ exports.error = error;
138
+ const exit = Errors.exit;
139
+ exports.exit = exit;
140
+ const flush = ux.flush;
141
+ exports.flush = flush;
142
+ const info = ux.info;
143
+ exports.info = info;
144
+ const log = ux.log;
145
+ exports.log = log;
146
+ const prideAction = ux.prideAction;
147
+ exports.prideAction = prideAction;
148
+ const progress = ux.progress;
149
+ exports.progress = progress;
150
+ const prompt = ux.prompt;
151
+ exports.prompt = prompt;
152
+ const styledHeader = ux.styledHeader;
153
+ exports.styledHeader = styledHeader;
154
+ const styledJSON = ux.styledJSON;
155
+ exports.styledJSON = styledJSON;
156
+ const styledObject = ux.styledObject;
157
+ exports.styledObject = styledObject;
158
+ const table = ux.table;
159
+ exports.table = table;
160
+ const trace = ux.trace;
161
+ exports.trace = trace;
162
+ const tree = ux.tree;
163
+ exports.tree = tree;
164
+ const url = ux.url;
165
+ exports.url = url;
166
+ const wait = ux.wait;
167
+ exports.wait = wait;
168
+ const warn = Errors.warn;
169
+ exports.warn = warn;
127
170
  const cliuxProcessExitHandler = async () => {
128
171
  try {
129
- await exports.ux.done();
172
+ await ux.done();
130
173
  }
131
174
  catch (error) {
132
- // tslint:disable no-console
133
175
  console.error(error);
134
176
  process.exitCode = 1;
135
177
  }
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
- // tslint:disable
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.renderList = void 0;
4
+ const screen_1 = require("../screen");
5
5
  const util_1 = require("../util");
6
- const deps_1 = require("./deps");
6
+ const wordwrap = require('wordwrap');
7
7
  function linewrap(length, s) {
8
- const lw = require('@oclif/linewrap');
9
- return lw(length, deps_1.default.screen.stdtermwidth, {
8
+ return wordwrap(length, screen_1.stdtermwidth, {
10
9
  skipScheme: 'ansi-color',
11
10
  })(s).trim();
12
11
  }
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.anykey = exports.confirm = exports.prompt = void 0;
4
4
  const Errors = require("../errors");
5
- const chalk = require("chalk");
6
5
  const config_1 = require("./config");
7
- const deps_1 = require("./deps");
6
+ const chalk = require("chalk");
7
+ const ansiEscapes = require('ansi-escapes');
8
+ const passwordPrompt = require('password-prompt');
8
9
  function normal(options, retries = 100) {
9
10
  if (retries < 0)
10
11
  throw new Error('no input');
@@ -56,10 +57,10 @@ async function single(options) {
56
57
  return response;
57
58
  }
58
59
  function replacePrompt(prompt) {
59
- process.stderr.write(deps_1.default.ansiEscapes.cursorHide + deps_1.default.ansiEscapes.cursorUp(1) + deps_1.default.ansiEscapes.cursorLeft + prompt +
60
- deps_1.default.ansiEscapes.cursorDown(1) + deps_1.default.ansiEscapes.cursorLeft + deps_1.default.ansiEscapes.cursorShow);
60
+ process.stderr.write(ansiEscapes.cursorHide + ansiEscapes.cursorUp(1) + ansiEscapes.cursorLeft + prompt +
61
+ ansiEscapes.cursorDown(1) + ansiEscapes.cursorLeft + ansiEscapes.cursorShow);
61
62
  }
62
- function _prompt(name, inputOptions = {}) {
63
+ async function _prompt(name, inputOptions = {}) {
63
64
  const prompt = getPrompt(name, inputOptions.type, inputOptions.default);
64
65
  const options = {
65
66
  isTTY: Boolean(process.env.TERM !== 'dumb' && process.stdin.isTTY),
@@ -76,7 +77,7 @@ function _prompt(name, inputOptions = {}) {
76
77
  case 'single':
77
78
  return single(options);
78
79
  case 'mask':
79
- return deps_1.default.passwordPrompt(options.prompt, {
80
+ return passwordPrompt(options.prompt, {
80
81
  method: options.type,
81
82
  required: options.required,
82
83
  default: options.default,
@@ -85,7 +86,7 @@ function _prompt(name, inputOptions = {}) {
85
86
  return value;
86
87
  });
87
88
  case 'hide':
88
- return deps_1.default.passwordPrompt(options.prompt, {
89
+ return passwordPrompt(options.prompt, {
89
90
  method: options.type,
90
91
  required: options.required,
91
92
  default: options.default,
@@ -100,7 +101,7 @@ function _prompt(name, inputOptions = {}) {
100
101
  * @param options - @see IPromptOptions
101
102
  * @returns Promise<string>
102
103
  */
103
- function prompt(name, options = {}) {
104
+ async function prompt(name, options = {}) {
104
105
  return config_1.default.action.pauseAsync(() => {
105
106
  return _prompt(name, options);
106
107
  }, chalk.cyan('?'));
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const chalk = require("chalk");
4
4
  const index_1 = require("../../index");
5
5
  function styledHeader(header) {
6
- index_1.CliUx.ux.info(chalk.dim('=== ') + chalk.bold(header) + '\n');
6
+ index_1.ux.info(chalk.dim('=== ') + chalk.bold(header) + '\n');
7
7
  }
8
8
  exports.default = styledHeader;
@@ -0,0 +1,7 @@
1
+ import styledHeader from './header';
2
+ import styledJSON from './json';
3
+ import styledObject from './object';
4
+ import * as Table from './table';
5
+ import tree from './tree';
6
+ import progress from './progress';
7
+ export { styledHeader, styledJSON, styledObject, Table, tree, progress, };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.progress = exports.tree = exports.Table = exports.styledObject = exports.styledJSON = exports.styledHeader = void 0;
4
+ const header_1 = require("./header");
5
+ exports.styledHeader = header_1.default;
6
+ const json_1 = require("./json");
7
+ exports.styledJSON = json_1.default;
8
+ const object_1 = require("./object");
9
+ exports.styledObject = object_1.default;
10
+ const Table = require("./table");
11
+ exports.Table = Table;
12
+ const tree_1 = require("./tree");
13
+ exports.tree = tree_1.default;
14
+ const progress_1 = require("./progress");
15
+ exports.progress = progress_1.default;
@@ -1 +1 @@
1
- export default function styledJSON(obj: any): void;
1
+ export default function styledJSON(obj: unknown): void;
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
- // tslint:disable restrict-plus-operands
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  const chalk = require("chalk");
5
4
  const index_1 = require("../../index");
6
5
  function styledJSON(obj) {
7
6
  const json = JSON.stringify(obj, null, 2);
8
7
  if (!chalk.level) {
9
- index_1.CliUx.ux.info(json);
8
+ index_1.ux.info(json);
10
9
  return;
11
10
  }
12
11
  const cardinal = require('cardinal');
13
12
  const theme = require('cardinal/themes/jq');
14
- index_1.CliUx.ux.info(cardinal.highlight(json, { json: true, theme }));
13
+ index_1.ux.info(cardinal.highlight(json, { json: true, theme }));
15
14
  }
16
15
  exports.default = styledJSON;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
- // tslint:disable
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  const chalk = require("chalk");
5
4
  const util = require("util");
5
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
6
6
  function styledObject(obj, keys) {
7
7
  const output = [];
8
8
  const keyLengths = Object.keys(obj).map(key => key.toString().length);
@@ -1 +1,2 @@
1
- export default function progress(options?: any): any;
1
+ import { Options, SingleBar } from 'cli-progress';
2
+ export default function progress(options?: Options): SingleBar;
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // 3pp
4
- const cliProgress = require("cli-progress");
5
- function progress(options) {
6
- // if no options passed, create empty options
7
- if (!options) {
8
- options = {};
9
- }
4
+ const cli_progress_1 = require("cli-progress");
5
+ function progress(options = {}) {
10
6
  // set noTTYOutput for options
11
7
  options.noTTYOutput = Boolean(process.env.TERM === 'dumb' || !process.stdin.isTTY);
12
- return new cliProgress.SingleBar(options);
8
+ return new cli_progress_1.SingleBar(options);
13
9
  }
14
10
  exports.default = progress;
@@ -126,7 +126,6 @@ class Table {
126
126
  return values.map(e => lineToBeEscaped ? `"${e.replace('"', '""')}"` : e);
127
127
  }
128
128
  resolveColumnsToObjectArray() {
129
- // tslint:disable-next-line:no-this-assignment
130
129
  const { data, columns } = this;
131
130
  return data.map((d) => {
132
131
  // eslint-disable-next-line unicorn/prefer-object-from-entries
@@ -145,7 +144,6 @@ class Table {
145
144
  this.options.printLine((0, js_yaml_1.safeDump)(this.resolveColumnsToObjectArray()));
146
145
  }
147
146
  outputCSV() {
148
- // tslint:disable-next-line:no-this-assignment
149
147
  const { data, columns, options } = this;
150
148
  if (!options['no-header']) {
151
149
  options.printLine(columns.map(c => c.header).join(','));
@@ -156,7 +154,6 @@ class Table {
156
154
  }
157
155
  }
158
156
  outputTable() {
159
- // tslint:disable-next-line:no-this-assignment
160
157
  const { data, options } = this;
161
158
  // column truncation
162
159
  //
@@ -288,6 +285,7 @@ exports.table = table;
288
285
  'no-truncate': F.boolean({ exclusive: ['csv'], description: 'do not truncate output to fit screen' }),
289
286
  'no-header': F.boolean({ exclusive: ['csv'], description: 'hide table header from output' }),
290
287
  };
288
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
291
289
  function flags(opts) {
292
290
  if (opts) {
293
291
  const f = {};
@@ -20,7 +20,6 @@ class Tree {
20
20
  return c;
21
21
  }
22
22
  }
23
- // tslint:disable-next-line:no-console
24
23
  display(logger = console.log) {
25
24
  const addNodes = function (nodes) {
26
25
  const tree = {};
@@ -1,2 +1,2 @@
1
- declare const _default: (ms?: number) => Promise<unknown>;
1
+ declare const _default: (ms?: number) => Promise<void>;
2
2
  export default _default;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // tslint:disable no-string-based-set-timeout
4
3
  exports.default = (ms = 1000) => {
5
4
  return new Promise(resolve => {
6
5
  setTimeout(resolve, ms);
package/lib/command.d.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  import { Config } from './config';
2
- import * as Interfaces from './interfaces';
3
2
  import { PrettyPrintableError } from './errors';
4
- import { Deprecation } from './interfaces/parser';
3
+ import { BooleanFlagProps, CompletableFlag, Deprecation, Arg as IArg, ArgInput, FlagInput, FlagOutput, Input, ArgProps, OptionFlagProps, ParserOutput, ArgOutput } from './interfaces/parser';
4
+ import { Plugin } from './interfaces/plugin';
5
+ import { LoadOptions } from './interfaces/config';
6
+ import { CommandError } from './interfaces/errors';
5
7
  /**
6
8
  * An abstract class which acts as the base for each command
7
9
  * in your project.
8
10
  */
9
- export default abstract class Command {
11
+ export declare abstract class Command {
10
12
  argv: string[];
11
13
  config: Config;
12
- static _base: string;
14
+ private static readonly _base;
13
15
  /** A command ID, used mostly in error or verbose reporting. */
14
16
  static id: string;
15
17
  /**
@@ -41,10 +43,12 @@ export default abstract class Command {
41
43
  static aliases: string[];
42
44
  /** When set to false, allows a variable amount of arguments */
43
45
  static strict: boolean;
44
- static parse: boolean;
45
- /** An order-dependent array of arguments for the command */
46
- static args?: Interfaces.ArgInput;
47
- static plugin: Interfaces.Plugin | undefined;
46
+ /** An order-dependent object of arguments for the command */
47
+ static args: ArgInput;
48
+ static plugin: Plugin | undefined;
49
+ static readonly pluginName?: string;
50
+ static readonly pluginType?: string;
51
+ static readonly pluginAlias?: string;
48
52
  /**
49
53
  * An array of examples to show at the end of the command's help.
50
54
  *
@@ -59,30 +63,32 @@ export default abstract class Command {
59
63
  * $ <%= config.bin => command flags
60
64
  * ```
61
65
  */
62
- static examples: Interfaces.Example[];
63
- static parserOptions: {};
64
- static _enableJsonFlag: boolean;
66
+ static examples: Command.Example[];
67
+ static hasDynamicHelp: boolean;
68
+ protected static _enableJsonFlag: boolean;
65
69
  static get enableJsonFlag(): boolean;
66
70
  static set enableJsonFlag(value: boolean);
67
71
  /**
68
72
  * instantiate and run the command
69
- * @param {Interfaces.Command.Class} this Class
73
+ *
74
+ * @param {Command.Class} this - the command class
70
75
  * @param {string[]} argv argv
71
- * @param {Interfaces.LoadOptions} opts options
76
+ * @param {LoadOptions} opts options
77
+ * @returns {Promise<unknown>} result
72
78
  */
73
- static run: Interfaces.Command.Class['run'];
74
- protected static _globalFlags: Interfaces.FlagInput;
75
- static get globalFlags(): Interfaces.FlagInput;
76
- static set globalFlags(flags: Interfaces.FlagInput);
79
+ static run<T extends Command>(this: new (argv: string[], config: Config) => T, argv?: string[], opts?: LoadOptions): Promise<unknown>;
80
+ protected static _baseFlags: FlagInput;
81
+ static get baseFlags(): FlagInput;
82
+ static set baseFlags(flags: FlagInput);
77
83
  /** A hash of flags for the command */
78
- protected static _flags: Interfaces.FlagInput;
79
- static get flags(): Interfaces.FlagInput;
80
- static set flags(flags: Interfaces.FlagInput);
84
+ protected static _flags: FlagInput;
85
+ static get flags(): FlagInput;
86
+ static set flags(flags: FlagInput);
81
87
  id: string | undefined;
82
88
  protected debug: (...args: any[]) => void;
83
89
  constructor(argv: string[], config: Config);
84
- get ctor(): typeof Command;
85
- _run<T>(): Promise<T | undefined>;
90
+ protected get ctor(): typeof Command;
91
+ protected _run<T>(): Promise<T | undefined>;
86
92
  exit(code?: number): void;
87
93
  warn(input: string | Error): string | Error;
88
94
  error(input: string | Error, options: {
@@ -99,15 +105,60 @@ export default abstract class Command {
99
105
  /**
100
106
  * actual command run code goes here
101
107
  */
102
- abstract run(): PromiseLike<any>;
108
+ abstract run(): Promise<any>;
103
109
  protected init(): Promise<any>;
104
110
  protected warnIfFlagDeprecated(flags: Record<string, unknown>): void;
105
111
  protected warnIfCommandDeprecated(): void;
106
- protected parse<F extends Interfaces.FlagOutput, G extends Interfaces.FlagOutput, A extends {
107
- [name: string]: any;
108
- }>(options?: Interfaces.Input<F, G>, argv?: string[]): Promise<Interfaces.ParserOutput<F, G, A>>;
109
- protected catch(err: Interfaces.CommandError): Promise<any>;
112
+ protected parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F, B, A>>;
113
+ protected catch(err: CommandError): Promise<any>;
110
114
  protected finally(_: Error | undefined): Promise<any>;
111
115
  protected toSuccessJson(result: unknown): any;
112
116
  protected toErrorJson(err: unknown): any;
113
117
  }
118
+ export declare namespace Command {
119
+ type Class = typeof Command & {
120
+ id: string;
121
+ run(argv?: string[], config?: LoadOptions): Promise<any>;
122
+ };
123
+ interface Loadable extends Cached {
124
+ load(): Promise<Command.Class>;
125
+ }
126
+ type Cached = {
127
+ [key: string]: unknown;
128
+ id: string;
129
+ hidden: boolean;
130
+ state?: 'beta' | 'deprecated' | string;
131
+ deprecationOptions?: Deprecation;
132
+ aliases: string[];
133
+ summary?: string;
134
+ description?: string;
135
+ usage?: string | string[];
136
+ examples?: Example[];
137
+ strict?: boolean;
138
+ type?: string;
139
+ pluginName?: string;
140
+ pluginType?: string;
141
+ pluginAlias?: string;
142
+ flags: {
143
+ [name: string]: Flag.Cached;
144
+ };
145
+ args: {
146
+ [name: string]: Arg.Cached;
147
+ };
148
+ hasDynamicHelp?: boolean;
149
+ };
150
+ type Flag = CompletableFlag<any>;
151
+ namespace Flag {
152
+ type Cached = Omit<Flag, 'parse' | 'input'> & (BooleanFlagProps | OptionFlagProps);
153
+ type Any = Flag | Cached;
154
+ }
155
+ type Arg = IArg<any>;
156
+ namespace Arg {
157
+ type Cached = Omit<Arg, 'parse' | 'input'> & ArgProps;
158
+ type Any = Arg | Cached;
159
+ }
160
+ type Example = string | {
161
+ description: string;
162
+ command: string;
163
+ };
164
+ }