@oclif/core 3.0.0-beta.13 → 3.0.0-beta.14
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/README.md +3 -1
- package/lib/args.d.ts +1 -1
- package/lib/args.js +13 -15
- package/lib/cli-ux/action/base.d.ts +1 -1
- package/lib/cli-ux/action/base.js +20 -15
- package/lib/cli-ux/action/simple.js +10 -8
- package/lib/cli-ux/action/spinner.js +11 -10
- package/lib/cli-ux/config.js +8 -7
- package/lib/cli-ux/flush.js +2 -3
- package/lib/cli-ux/index.d.ts +10 -28
- package/lib/cli-ux/index.js +26 -45
- package/lib/cli-ux/list.js +1 -1
- package/lib/cli-ux/prompt.js +24 -19
- package/lib/cli-ux/styled/index.d.ts +5 -6
- package/lib/cli-ux/styled/index.js +11 -11
- package/lib/cli-ux/styled/json.js +3 -2
- package/lib/cli-ux/styled/object.js +6 -8
- package/lib/cli-ux/styled/table.js +36 -45
- package/lib/cli-ux/wait.js +3 -5
- package/lib/command.d.ts +7 -5
- package/lib/command.js +35 -28
- package/lib/config/config.d.ts +2 -2
- package/lib/config/config.js +57 -43
- package/lib/config/plugin-loader.js +25 -11
- package/lib/config/plugin.d.ts +1 -1
- package/lib/config/plugin.js +66 -56
- package/lib/config/ts-node.d.ts +2 -1
- package/lib/config/ts-node.js +41 -34
- package/lib/config/util.d.ts +1 -5
- package/lib/config/util.js +5 -46
- package/lib/errors/config.js +1 -1
- package/lib/errors/errors/cli.d.ts +1 -1
- package/lib/errors/errors/cli.js +14 -13
- package/lib/errors/errors/exit.d.ts +0 -3
- package/lib/errors/errors/module-load.d.ts +0 -3
- package/lib/errors/errors/pretty-print.js +9 -8
- package/lib/errors/handle.d.ts +12 -2
- package/lib/errors/handle.js +23 -14
- package/lib/errors/index.d.ts +2 -2
- package/lib/errors/index.js +20 -19
- package/lib/errors/logger.js +4 -4
- package/lib/execute.d.ts +5 -5
- package/lib/execute.js +6 -5
- package/lib/flags.d.ts +102 -31
- package/lib/flags.js +75 -42
- package/lib/help/command.d.ts +2 -0
- package/lib/help/command.js +32 -32
- package/lib/help/docopts.js +2 -9
- package/lib/help/formatter.d.ts +1 -1
- package/lib/help/formatter.js +17 -17
- package/lib/help/index.d.ts +2 -2
- package/lib/help/index.js +22 -21
- package/lib/help/root.js +2 -2
- package/lib/help/util.d.ts +1 -1
- package/lib/help/util.js +9 -9
- package/lib/index.d.ts +19 -20
- package/lib/index.js +38 -42
- package/lib/interfaces/config.d.ts +5 -4
- package/lib/interfaces/errors.d.ts +1 -1
- package/lib/interfaces/parser.d.ts +168 -45
- package/lib/interfaces/plugin.d.ts +1 -0
- package/lib/main.d.ts +1 -1
- package/lib/main.js +16 -16
- package/lib/module-loader.d.ts +67 -77
- package/lib/module-loader.js +179 -149
- package/lib/parser/errors.d.ts +2 -2
- package/lib/parser/errors.js +4 -3
- package/lib/parser/help.js +3 -2
- package/lib/parser/parse.d.ts +3 -0
- package/lib/parser/parse.js +56 -52
- package/lib/parser/validate.js +9 -5
- package/lib/performance.d.ts +6 -2
- package/lib/performance.js +23 -12
- package/lib/util.d.ts +25 -1
- package/lib/util.js +93 -29
- package/package.json +10 -15
package/lib/help/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Help = exports.HelpBase = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.loadHelpClass = exports.standardizeIDFromArgv = exports.CommandHelp = void 0;
|
|
4
|
-
const
|
|
5
|
-
const util = require("util");
|
|
6
|
-
const errors_1 = require("../errors");
|
|
7
|
-
const command_1 = require("./command");
|
|
8
|
-
const root_1 = require("./root");
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
9
5
|
const util_1 = require("../util");
|
|
10
6
|
const util_2 = require("./util");
|
|
7
|
+
const command_1 = require("./command");
|
|
11
8
|
const formatter_1 = require("./formatter");
|
|
12
|
-
const
|
|
9
|
+
const root_1 = tslib_1.__importDefault(require("./root"));
|
|
10
|
+
const errors_1 = require("../errors");
|
|
11
|
+
const node_util_1 = require("node:util");
|
|
13
12
|
const stream_1 = require("../cli-ux/stream");
|
|
13
|
+
const config_1 = require("../config/config");
|
|
14
|
+
const stripAnsi = require("strip-ansi");
|
|
14
15
|
var command_2 = require("./command");
|
|
15
16
|
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return command_2.CommandHelp; } });
|
|
16
17
|
var util_3 = require("./util");
|
|
@@ -54,7 +55,7 @@ class Help extends HelpBase {
|
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
get sortedCommands() {
|
|
57
|
-
let commands = this.config
|
|
58
|
+
let { commands } = this.config;
|
|
58
59
|
commands = commands.filter(c => this.opts.all || !c.hidden);
|
|
59
60
|
commands = (0, util_1.sortBy)(commands, c => c.id);
|
|
60
61
|
commands = (0, util_1.uniqBy)(commands, c => c.id);
|
|
@@ -69,7 +70,7 @@ class Help extends HelpBase {
|
|
|
69
70
|
}
|
|
70
71
|
constructor(config, opts = {}) {
|
|
71
72
|
super(config, opts);
|
|
72
|
-
this.CommandHelpClass = command_1.
|
|
73
|
+
this.CommandHelpClass = command_1.CommandHelp;
|
|
73
74
|
}
|
|
74
75
|
async showHelp(argv) {
|
|
75
76
|
const originalArgv = argv.slice(1);
|
|
@@ -126,9 +127,9 @@ class Help extends HelpBase {
|
|
|
126
127
|
const plugin = this.config.plugins.get(command.pluginName);
|
|
127
128
|
const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
|
|
128
129
|
if (state) {
|
|
129
|
-
this.log(state === 'deprecated'
|
|
130
|
-
`${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), command.deprecationOptions)}`
|
|
131
|
-
`This command is in ${state}.\n`);
|
|
130
|
+
this.log(state === 'deprecated'
|
|
131
|
+
? `${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), command.deprecationOptions)}`
|
|
132
|
+
: `This command is in ${state}.\n`);
|
|
132
133
|
}
|
|
133
134
|
const summary = this.summary(command);
|
|
134
135
|
if (summary) {
|
|
@@ -155,9 +156,9 @@ class Help extends HelpBase {
|
|
|
155
156
|
let rootCommands = this.sortedCommands;
|
|
156
157
|
const state = this.config.pjson?.oclif?.state;
|
|
157
158
|
if (state) {
|
|
158
|
-
this.log(state === 'deprecated'
|
|
159
|
-
`${this.config.bin} is deprecated`
|
|
160
|
-
`${this.config.bin} is in ${state}.\n`);
|
|
159
|
+
this.log(state === 'deprecated'
|
|
160
|
+
? `${this.config.bin} is deprecated`
|
|
161
|
+
: `${this.config.bin} is in ${state}.\n`);
|
|
161
162
|
}
|
|
162
163
|
this.log(this.formatRoot());
|
|
163
164
|
this.log('');
|
|
@@ -176,7 +177,7 @@ class Help extends HelpBase {
|
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
async showTopicHelp(topic) {
|
|
179
|
-
const name = topic
|
|
180
|
+
const { name } = topic;
|
|
180
181
|
const depth = name.split(':').length;
|
|
181
182
|
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
182
183
|
const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
|
|
@@ -199,8 +200,8 @@ class Help extends HelpBase {
|
|
|
199
200
|
}
|
|
200
201
|
formatCommand(command) {
|
|
201
202
|
if (this.config.topicSeparator !== ':') {
|
|
202
|
-
command.id = command.id.
|
|
203
|
-
command.aliases = command.aliases && command.aliases.map(a => a.
|
|
203
|
+
command.id = command.id.replaceAll(':', this.config.topicSeparator);
|
|
204
|
+
command.aliases = command.aliases && command.aliases.map(a => a.replaceAll(':', this.config.topicSeparator));
|
|
204
205
|
}
|
|
205
206
|
const help = this.getCommandHelpClass(command);
|
|
206
207
|
return help.generate();
|
|
@@ -213,7 +214,7 @@ class Help extends HelpBase {
|
|
|
213
214
|
return '';
|
|
214
215
|
const body = this.renderList(commands.map(c => {
|
|
215
216
|
if (this.config.topicSeparator !== ':')
|
|
216
|
-
c.id = c.id.
|
|
217
|
+
c.id = c.id.replaceAll(':', this.config.topicSeparator);
|
|
217
218
|
return [
|
|
218
219
|
c.id,
|
|
219
220
|
this.summary(c),
|
|
@@ -243,7 +244,7 @@ class Help extends HelpBase {
|
|
|
243
244
|
description = description.split('\n').slice(1).join('\n');
|
|
244
245
|
let topicID = `${topic.name}:COMMAND`;
|
|
245
246
|
if (this.config.topicSeparator !== ':')
|
|
246
|
-
topicID = topicID.
|
|
247
|
+
topicID = topicID.replaceAll(':', this.config.topicSeparator);
|
|
247
248
|
let output = (0, util_1.compact)([
|
|
248
249
|
summary,
|
|
249
250
|
this.section(this.opts.usageHeader || 'USAGE', `$ ${this.config.bin} ${topicID}`),
|
|
@@ -258,7 +259,7 @@ class Help extends HelpBase {
|
|
|
258
259
|
return '';
|
|
259
260
|
const body = this.renderList(topics.map(c => {
|
|
260
261
|
if (this.config.topicSeparator !== ':')
|
|
261
|
-
c.name = c.name.
|
|
262
|
+
c.name = c.name.replaceAll(':', this.config.topicSeparator);
|
|
262
263
|
return [
|
|
263
264
|
c.name,
|
|
264
265
|
c.description && this.render(c.description.split('\n')[0]),
|
|
@@ -274,7 +275,7 @@ class Help extends HelpBase {
|
|
|
274
275
|
return this.formatCommand(command);
|
|
275
276
|
}
|
|
276
277
|
log(...args) {
|
|
277
|
-
stream_1.stdout.write(
|
|
278
|
+
stream_1.stdout.write(node_util_1.format.apply(this, args) + '\n');
|
|
278
279
|
}
|
|
279
280
|
}
|
|
280
281
|
exports.Help = Help;
|
package/lib/help/root.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const stripAnsi = require("strip-ansi");
|
|
4
|
-
const util_1 = require("../util");
|
|
5
3
|
const formatter_1 = require("./formatter");
|
|
4
|
+
const util_1 = require("../util");
|
|
5
|
+
const stripAnsi = require("strip-ansi");
|
|
6
6
|
class RootHelp extends formatter_1.HelpFormatter {
|
|
7
7
|
constructor(config, opts) {
|
|
8
8
|
super(config, opts);
|
package/lib/help/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config as IConfig
|
|
1
|
+
import { Deprecation, HelpOptions, Config as IConfig } from '../interfaces';
|
|
2
2
|
import { HelpBase } from '.';
|
|
3
3
|
interface HelpBaseDerived {
|
|
4
4
|
new (config: IConfig, opts?: Partial<HelpOptions>): HelpBase;
|
package/lib/help/util.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeArgv = exports.formatCommandDeprecationWarning = exports.formatFlagDeprecationWarning = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.toConfiguredId = exports.toStandardizedId = exports.template = exports.loadHelpClass = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ejs = tslib_1.__importStar(require("ejs"));
|
|
5
6
|
const _1 = require(".");
|
|
6
|
-
const module_loader_1 = require("../module-loader");
|
|
7
7
|
const util_1 = require("../config/util");
|
|
8
|
+
const module_loader_1 = require("../module-loader");
|
|
8
9
|
function extractClass(exported) {
|
|
9
10
|
return exported && exported.default ? exported.default : exported;
|
|
10
11
|
}
|
|
11
12
|
async function loadHelpClass(config) {
|
|
12
|
-
const pjson = config
|
|
13
|
+
const { pjson } = config;
|
|
13
14
|
const configuredClass = pjson && pjson.oclif && pjson.oclif.helpClass;
|
|
14
15
|
if (configuredClass) {
|
|
15
16
|
try {
|
|
16
|
-
const exported = await module_loader_1.
|
|
17
|
+
const exported = await (0, module_loader_1.load)(config, configuredClass);
|
|
17
18
|
return extractClass(exported);
|
|
18
19
|
}
|
|
19
20
|
catch (error) {
|
|
@@ -23,7 +24,6 @@ async function loadHelpClass(config) {
|
|
|
23
24
|
return _1.Help;
|
|
24
25
|
}
|
|
25
26
|
exports.loadHelpClass = loadHelpClass;
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
27
27
|
function template(context) {
|
|
28
28
|
function render(t) {
|
|
29
29
|
return ejs.render(t, context);
|
|
@@ -31,6 +31,8 @@ function template(context) {
|
|
|
31
31
|
return render;
|
|
32
32
|
}
|
|
33
33
|
exports.template = template;
|
|
34
|
+
const isFlag = (s) => s.startsWith('-');
|
|
35
|
+
const isArgWithValue = (s) => s.includes('=');
|
|
34
36
|
function collateSpacedCmdIDFromArgs(argv, config) {
|
|
35
37
|
if (argv.length === 1)
|
|
36
38
|
return argv;
|
|
@@ -38,8 +40,6 @@ function collateSpacedCmdIDFromArgs(argv, config) {
|
|
|
38
40
|
const ids = (0, util_1.collectUsableIds)(config.commandIDs);
|
|
39
41
|
const final = [];
|
|
40
42
|
const idPresent = (id) => ids.has(id);
|
|
41
|
-
const isFlag = (s) => s.startsWith('-');
|
|
42
|
-
const isArgWithValue = (s) => s.includes('=');
|
|
43
43
|
const finalizeId = (s) => s ? [...final, s].join(':') : final.join(':');
|
|
44
44
|
const hasArgs = () => {
|
|
45
45
|
const id = finalizeId();
|
|
@@ -68,12 +68,12 @@ function collateSpacedCmdIDFromArgs(argv, config) {
|
|
|
68
68
|
return argv; // ID is argv[0]
|
|
69
69
|
}
|
|
70
70
|
function toStandardizedId(commandID, config) {
|
|
71
|
-
return commandID.
|
|
71
|
+
return commandID.replaceAll(new RegExp(config.topicSeparator, 'g'), ':');
|
|
72
72
|
}
|
|
73
73
|
exports.toStandardizedId = toStandardizedId;
|
|
74
74
|
function toConfiguredId(commandID, config) {
|
|
75
75
|
const defaultTopicSeparator = ':';
|
|
76
|
-
return commandID.
|
|
76
|
+
return commandID.replaceAll(new RegExp(defaultTopicSeparator, 'g'), config.topicSeparator || defaultTopicSeparator);
|
|
77
77
|
}
|
|
78
78
|
exports.toConfiguredId = toConfiguredId;
|
|
79
79
|
function standardizeIDFromArgv(argv, config) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export { Args, Command, CommandHelp, Config, Errors, execute, Flags, flush, handle, Help, HelpBase, HelpSection, HelpSectionKeyValueTable, HelpSectionRenderer, Hook, Interfaces, loadHelpClass, Parser, Performance, Plugin, run, settings, Settings, stderr, stdout, toCached, toConfiguredId, toStandardizedId, tsPath, ux, };
|
|
1
|
+
export * as Args from './args';
|
|
2
|
+
export * as Errors from './errors';
|
|
3
|
+
export * as Flags from './flags';
|
|
4
|
+
export * as Interfaces from './interfaces';
|
|
5
|
+
export * as Parser from './parser';
|
|
6
|
+
export * as ux from './cli-ux';
|
|
7
|
+
export { CommandHelp, HelpBase, Help, loadHelpClass } from './help';
|
|
8
|
+
export { Config, toCached, Plugin, tsPath } from './config';
|
|
9
|
+
export { HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable } from './help/formatter';
|
|
10
|
+
export { Settings, settings } from './settings';
|
|
11
|
+
export { stdout, stderr } from './cli-ux/stream';
|
|
12
|
+
export { toConfiguredId, toStandardizedId } from './help/util';
|
|
13
|
+
export { Command } from './command';
|
|
14
|
+
export { Hook } from './interfaces/hooks';
|
|
15
|
+
export { Performance } from './performance';
|
|
16
|
+
export { execute } from './execute';
|
|
17
|
+
export { flush } from './cli-ux/flush';
|
|
18
|
+
export { handle } from './errors/handle';
|
|
19
|
+
export { run } from './main';
|
package/lib/index.js
CHANGED
|
@@ -1,48 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } });
|
|
6
|
-
const main_1 = require("./main");
|
|
7
|
-
exports.run = main_1.default;
|
|
8
|
-
const execute_1 = require("./execute");
|
|
9
|
-
exports.execute = execute_1.default;
|
|
10
|
-
const handle_1 = require("./errors/handle");
|
|
11
|
-
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
|
|
12
|
-
const config_1 = require("./config");
|
|
13
|
-
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
14
|
-
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return config_1.Plugin; } });
|
|
15
|
-
Object.defineProperty(exports, "tsPath", { enumerable: true, get: function () { return config_1.tsPath; } });
|
|
16
|
-
Object.defineProperty(exports, "toCached", { enumerable: true, get: function () { return config_1.toCached; } });
|
|
17
|
-
const Interfaces = require("./interfaces");
|
|
18
|
-
exports.Interfaces = Interfaces;
|
|
19
|
-
const Errors = require("./errors");
|
|
20
|
-
exports.Errors = Errors;
|
|
21
|
-
const Flags = require("./flags");
|
|
22
|
-
exports.Flags = Flags;
|
|
23
|
-
const Args = require("./args");
|
|
24
|
-
exports.Args = Args;
|
|
25
|
-
const help_1 = require("./help");
|
|
26
|
-
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return help_1.CommandHelp; } });
|
|
27
|
-
Object.defineProperty(exports, "HelpBase", { enumerable: true, get: function () { return help_1.HelpBase; } });
|
|
28
|
-
Object.defineProperty(exports, "Help", { enumerable: true, get: function () { return help_1.Help; } });
|
|
29
|
-
Object.defineProperty(exports, "loadHelpClass", { enumerable: true, get: function () { return help_1.loadHelpClass; } });
|
|
30
|
-
const util_1 = require("./help/util");
|
|
31
|
-
Object.defineProperty(exports, "toStandardizedId", { enumerable: true, get: function () { return util_1.toStandardizedId; } });
|
|
32
|
-
Object.defineProperty(exports, "toConfiguredId", { enumerable: true, get: function () { return util_1.toConfiguredId; } });
|
|
33
|
-
const Parser = require("./parser");
|
|
34
|
-
exports.Parser = Parser;
|
|
35
|
-
const settings_1 = require("./settings");
|
|
36
|
-
Object.defineProperty(exports, "settings", { enumerable: true, get: function () { return settings_1.settings; } });
|
|
37
|
-
const ux = require("./cli-ux");
|
|
38
|
-
exports.ux = ux;
|
|
3
|
+
exports.run = exports.handle = exports.flush = exports.execute = exports.Performance = exports.Command = exports.toStandardizedId = exports.toConfiguredId = exports.stderr = exports.stdout = exports.settings = exports.tsPath = exports.Plugin = exports.toCached = exports.Config = exports.loadHelpClass = exports.Help = exports.HelpBase = exports.CommandHelp = exports.ux = exports.Parser = exports.Interfaces = exports.Flags = exports.Errors = exports.Args = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
39
5
|
const stream_1 = require("./cli-ux/stream");
|
|
40
|
-
Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return stream_1.stderr; } });
|
|
41
|
-
Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return stream_1.stdout; } });
|
|
42
|
-
const performance_1 = require("./performance");
|
|
43
|
-
exports.Performance = performance_1.default;
|
|
44
|
-
const flush_1 = require("./cli-ux/flush");
|
|
45
|
-
Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return flush_1.flush; } });
|
|
46
6
|
function checkCWD() {
|
|
47
7
|
try {
|
|
48
8
|
process.cwd();
|
|
@@ -54,3 +14,39 @@ function checkCWD() {
|
|
|
54
14
|
}
|
|
55
15
|
}
|
|
56
16
|
checkCWD();
|
|
17
|
+
exports.Args = tslib_1.__importStar(require("./args"));
|
|
18
|
+
exports.Errors = tslib_1.__importStar(require("./errors"));
|
|
19
|
+
exports.Flags = tslib_1.__importStar(require("./flags"));
|
|
20
|
+
exports.Interfaces = tslib_1.__importStar(require("./interfaces"));
|
|
21
|
+
exports.Parser = tslib_1.__importStar(require("./parser"));
|
|
22
|
+
exports.ux = tslib_1.__importStar(require("./cli-ux"));
|
|
23
|
+
var help_1 = require("./help");
|
|
24
|
+
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return help_1.CommandHelp; } });
|
|
25
|
+
Object.defineProperty(exports, "HelpBase", { enumerable: true, get: function () { return help_1.HelpBase; } });
|
|
26
|
+
Object.defineProperty(exports, "Help", { enumerable: true, get: function () { return help_1.Help; } });
|
|
27
|
+
Object.defineProperty(exports, "loadHelpClass", { enumerable: true, get: function () { return help_1.loadHelpClass; } });
|
|
28
|
+
var config_1 = require("./config");
|
|
29
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
30
|
+
Object.defineProperty(exports, "toCached", { enumerable: true, get: function () { return config_1.toCached; } });
|
|
31
|
+
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return config_1.Plugin; } });
|
|
32
|
+
Object.defineProperty(exports, "tsPath", { enumerable: true, get: function () { return config_1.tsPath; } });
|
|
33
|
+
var settings_1 = require("./settings");
|
|
34
|
+
Object.defineProperty(exports, "settings", { enumerable: true, get: function () { return settings_1.settings; } });
|
|
35
|
+
var stream_2 = require("./cli-ux/stream");
|
|
36
|
+
Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return stream_2.stdout; } });
|
|
37
|
+
Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return stream_2.stderr; } });
|
|
38
|
+
var util_1 = require("./help/util");
|
|
39
|
+
Object.defineProperty(exports, "toConfiguredId", { enumerable: true, get: function () { return util_1.toConfiguredId; } });
|
|
40
|
+
Object.defineProperty(exports, "toStandardizedId", { enumerable: true, get: function () { return util_1.toStandardizedId; } });
|
|
41
|
+
var command_1 = require("./command");
|
|
42
|
+
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } });
|
|
43
|
+
var performance_1 = require("./performance");
|
|
44
|
+
Object.defineProperty(exports, "Performance", { enumerable: true, get: function () { return performance_1.Performance; } });
|
|
45
|
+
var execute_1 = require("./execute");
|
|
46
|
+
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return execute_1.execute; } });
|
|
47
|
+
var flush_1 = require("./cli-ux/flush");
|
|
48
|
+
Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return flush_1.flush; } });
|
|
49
|
+
var handle_1 = require("./errors/handle");
|
|
50
|
+
Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
|
|
51
|
+
var main_1 = require("./main");
|
|
52
|
+
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return main_1.run; } });
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Hook, Hooks } from './hooks';
|
|
3
|
+
import { Options, Plugin } from './plugin';
|
|
4
|
+
import { Command } from '../command';
|
|
1
5
|
import { PJSON } from './pjson';
|
|
2
|
-
import { Hooks, Hook } from './hooks';
|
|
3
|
-
import { Plugin, Options } from './plugin';
|
|
4
6
|
import { Topic } from './topic';
|
|
5
|
-
import { Command } from '../command';
|
|
6
7
|
export type LoadOptions = Options | string | Config | undefined;
|
|
7
|
-
export type PlatformTypes =
|
|
8
|
+
export type PlatformTypes = NodeJS.Platform | 'wsl';
|
|
8
9
|
export type ArchTypes = 'arm' | 'arm64' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'x86';
|
|
9
10
|
export type PluginVersionDetail = {
|
|
10
11
|
version: string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Command } from '../command';
|
|
2
1
|
import { AlphabetLowercase, AlphabetUppercase } from './alphabet';
|
|
3
|
-
import {
|
|
2
|
+
import { Command } from '../command';
|
|
4
3
|
export type FlagOutput = {
|
|
5
4
|
[name: string]: any;
|
|
6
5
|
};
|
|
@@ -154,6 +153,10 @@ export type FlagProps = {
|
|
|
154
153
|
* Alternate names that can be used for this flag.
|
|
155
154
|
*/
|
|
156
155
|
aliases?: string[];
|
|
156
|
+
/**
|
|
157
|
+
* Alternate short chars that can be used for this flag.
|
|
158
|
+
*/
|
|
159
|
+
charAliases?: (AlphabetLowercase | AlphabetUppercase)[];
|
|
157
160
|
/**
|
|
158
161
|
* Emit deprecation warning when a flag alias is provided
|
|
159
162
|
*/
|
|
@@ -201,13 +204,13 @@ export type BooleanFlagProps = FlagProps & {
|
|
|
201
204
|
export type OptionFlagProps = FlagProps & {
|
|
202
205
|
type: 'option';
|
|
203
206
|
helpValue?: string;
|
|
204
|
-
options?: string[];
|
|
207
|
+
options?: readonly string[];
|
|
205
208
|
multiple?: boolean;
|
|
206
209
|
};
|
|
207
210
|
export type FlagParserContext = Command & {
|
|
208
211
|
token: FlagToken;
|
|
209
212
|
};
|
|
210
|
-
export type FlagParser<T, I extends string | boolean, P = CustomOptions> = (input: I, context: FlagParserContext, opts: P & OptionFlag<T, P>) => Promise<T>;
|
|
213
|
+
export type FlagParser<T, I extends string | boolean, P = CustomOptions> = (input: I, context: FlagParserContext, opts: P & OptionFlag<T, P>) => T extends Array<infer U> ? Promise<U> : Promise<T>;
|
|
211
214
|
export type ArgParserContext = Command & {
|
|
212
215
|
token: ArgToken;
|
|
213
216
|
};
|
|
@@ -234,40 +237,179 @@ export type BooleanFlag<T> = FlagProps & BooleanFlagProps & {
|
|
|
234
237
|
default?: FlagDefault<boolean>;
|
|
235
238
|
parse: (input: boolean, context: FlagParserContext, opts: FlagProps & BooleanFlagProps) => Promise<T>;
|
|
236
239
|
};
|
|
237
|
-
export type OptionFlagDefaults<T, P = CustomOptions, M = false> = FlagProps & OptionFlagProps & {
|
|
238
|
-
parse: FlagParser<T, string, P>;
|
|
239
|
-
defaultHelp?: FlagDefaultHelp<T>;
|
|
240
|
-
input: string[];
|
|
241
|
-
default?: M extends true ? FlagDefault<T[] | undefined, P> : FlagDefault<T | undefined, P>;
|
|
242
|
-
};
|
|
243
240
|
export type OptionFlag<T, P = CustomOptions> = FlagProps & OptionFlagProps & {
|
|
244
241
|
parse: FlagParser<T, string, P>;
|
|
245
242
|
defaultHelp?: FlagDefaultHelp<T, P>;
|
|
246
243
|
input: string[];
|
|
247
|
-
} & ({
|
|
248
244
|
default?: FlagDefault<T | undefined, P>;
|
|
245
|
+
};
|
|
246
|
+
type ReturnTypeSwitches = {
|
|
247
|
+
multiple: boolean;
|
|
248
|
+
requiredOrDefaulted: boolean;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* The logic here is as follows:
|
|
252
|
+
* - If requiredOrDefaulted is true && multiple is true, then the return type is T[]
|
|
253
|
+
* - It's possible that T extends an Array, if so we want to return T so that the return isn't T[][]
|
|
254
|
+
* - If requiredOrDefaulted is true && multiple is false, then the return type is T
|
|
255
|
+
* - If requiredOrDefaulted is false && multiple is true, then the return type is T[] | undefined
|
|
256
|
+
* - It's possible that T extends an Array, if so we want to return T so that the return isn't T[][]
|
|
257
|
+
* - If requiredOrDefaulted is false && multiple is false, then the return type is T | undefined
|
|
258
|
+
*/
|
|
259
|
+
type FlagReturnType<T, R extends ReturnTypeSwitches> = R['requiredOrDefaulted'] extends true ? R['multiple'] extends true ? [
|
|
260
|
+
T
|
|
261
|
+
] extends [Array<unknown>] ? T : T[] : T : R['multiple'] extends true ? [
|
|
262
|
+
T
|
|
263
|
+
] extends [Array<unknown>] ? T | undefined : T[] | undefined : T | undefined;
|
|
264
|
+
/**
|
|
265
|
+
* FlagDefinition types a function that takes `options` and returns an OptionFlag<T>.
|
|
266
|
+
*
|
|
267
|
+
* This is returned by `Flags.custom()` and `Flags.option()`, which each take a `defaults` object
|
|
268
|
+
* that mirrors the OptionFlag interface.
|
|
269
|
+
*
|
|
270
|
+
* The `T` in the `OptionFlag<T>` return type is determined by a combination of the provided defaults for
|
|
271
|
+
* `multiple`, `required`, and `default` and the provided options for those same properties. If these properties
|
|
272
|
+
* are provided in the options, they override the defaults.
|
|
273
|
+
*
|
|
274
|
+
* no options or defaults -> T | undefined
|
|
275
|
+
* `required` -> T
|
|
276
|
+
* `default` -> T
|
|
277
|
+
* `multiple` -> T[] | undefined
|
|
278
|
+
* `required` + `multiple` -> T[]
|
|
279
|
+
* `default` + `multiple` -> T[]
|
|
280
|
+
*/
|
|
281
|
+
export type FlagDefinition<T, P = CustomOptions, R extends ReturnTypeSwitches = {
|
|
249
282
|
multiple: false;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
283
|
+
requiredOrDefaulted: false;
|
|
284
|
+
}> = {
|
|
285
|
+
(options: P & {
|
|
286
|
+
multiple: false;
|
|
287
|
+
required: true;
|
|
288
|
+
} & Partial<OptionFlag<FlagReturnType<T, {
|
|
289
|
+
multiple: false;
|
|
290
|
+
requiredOrDefaulted: true;
|
|
291
|
+
}>, P>>): OptionFlag<FlagReturnType<T, {
|
|
292
|
+
multiple: false;
|
|
293
|
+
requiredOrDefaulted: true;
|
|
294
|
+
}>>;
|
|
255
295
|
(options: P & {
|
|
256
296
|
multiple: true;
|
|
297
|
+
required: false;
|
|
298
|
+
} & Partial<OptionFlag<FlagReturnType<T, {
|
|
299
|
+
multiple: true;
|
|
300
|
+
requiredOrDefaulted: false;
|
|
301
|
+
}>, P>>): OptionFlag<FlagReturnType<T, {
|
|
302
|
+
multiple: true;
|
|
303
|
+
requiredOrDefaulted: false;
|
|
304
|
+
}>>;
|
|
305
|
+
(options: P & {
|
|
306
|
+
multiple: false;
|
|
307
|
+
required: false;
|
|
308
|
+
} & Partial<OptionFlag<FlagReturnType<T, {
|
|
309
|
+
multiple: false;
|
|
310
|
+
requiredOrDefaulted: false;
|
|
311
|
+
}>, P>>): OptionFlag<FlagReturnType<T, {
|
|
312
|
+
multiple: false;
|
|
313
|
+
requiredOrDefaulted: false;
|
|
314
|
+
}>>;
|
|
315
|
+
(options: R['multiple'] extends true ? P & ({
|
|
316
|
+
required: true;
|
|
317
|
+
} | {
|
|
318
|
+
default: OptionFlag<FlagReturnType<T, {
|
|
319
|
+
multiple: R['multiple'];
|
|
320
|
+
requiredOrDefaulted: true;
|
|
321
|
+
}>, P>['default'];
|
|
322
|
+
}) & Partial<OptionFlag<FlagReturnType<T, {
|
|
323
|
+
multiple: R['multiple'];
|
|
324
|
+
requiredOrDefaulted: true;
|
|
325
|
+
}>, P>> : P & {
|
|
326
|
+
multiple?: false | undefined;
|
|
257
327
|
} & ({
|
|
258
328
|
required: true;
|
|
259
329
|
} | {
|
|
260
|
-
default:
|
|
261
|
-
|
|
262
|
-
|
|
330
|
+
default: OptionFlag<FlagReturnType<T, {
|
|
331
|
+
multiple: R['multiple'];
|
|
332
|
+
requiredOrDefaulted: true;
|
|
333
|
+
}>, P>['default'];
|
|
334
|
+
}) & Partial<OptionFlag<FlagReturnType<T, {
|
|
335
|
+
multiple: R['multiple'];
|
|
336
|
+
requiredOrDefaulted: true;
|
|
337
|
+
}>, P>>): OptionFlag<FlagReturnType<T, {
|
|
338
|
+
multiple: R['multiple'];
|
|
339
|
+
requiredOrDefaulted: true;
|
|
340
|
+
}>>;
|
|
341
|
+
(options: R['multiple'] extends true ? P & ({
|
|
342
|
+
required: true;
|
|
343
|
+
} | {
|
|
344
|
+
default: OptionFlag<FlagReturnType<T, {
|
|
345
|
+
multiple: true;
|
|
346
|
+
requiredOrDefaulted: true;
|
|
347
|
+
}>, P>['default'];
|
|
348
|
+
}) & Partial<OptionFlag<FlagReturnType<T, {
|
|
263
349
|
multiple: true;
|
|
264
|
-
|
|
265
|
-
|
|
350
|
+
requiredOrDefaulted: true;
|
|
351
|
+
}>, P>> : P & {
|
|
352
|
+
multiple: true;
|
|
353
|
+
} & ({
|
|
354
|
+
required: true;
|
|
355
|
+
} | {
|
|
356
|
+
default: OptionFlag<FlagReturnType<T, {
|
|
357
|
+
multiple: true;
|
|
358
|
+
requiredOrDefaulted: true;
|
|
359
|
+
}>, P>['default'];
|
|
360
|
+
}) & Partial<OptionFlag<FlagReturnType<T, {
|
|
361
|
+
multiple: true;
|
|
362
|
+
requiredOrDefaulted: true;
|
|
363
|
+
}>, P>>): OptionFlag<FlagReturnType<T, {
|
|
364
|
+
multiple: true;
|
|
365
|
+
requiredOrDefaulted: true;
|
|
366
|
+
}>>;
|
|
367
|
+
(options: P & {
|
|
368
|
+
multiple?: false | undefined;
|
|
369
|
+
} & ({
|
|
266
370
|
required: true;
|
|
267
371
|
} | {
|
|
268
|
-
default:
|
|
269
|
-
|
|
270
|
-
|
|
372
|
+
default: OptionFlag<FlagReturnType<T, {
|
|
373
|
+
multiple: R['multiple'];
|
|
374
|
+
requiredOrDefaulted: true;
|
|
375
|
+
}>, P>['default'];
|
|
376
|
+
}) & Partial<OptionFlag<FlagReturnType<T, {
|
|
377
|
+
multiple: R['multiple'];
|
|
378
|
+
requiredOrDefaulted: true;
|
|
379
|
+
}>, P>>): OptionFlag<FlagReturnType<T, {
|
|
380
|
+
multiple: R['multiple'];
|
|
381
|
+
requiredOrDefaulted: true;
|
|
382
|
+
}>>;
|
|
383
|
+
(options: P & {
|
|
384
|
+
required: false;
|
|
385
|
+
} & Partial<OptionFlag<FlagReturnType<T, {
|
|
386
|
+
multiple: R['multiple'];
|
|
387
|
+
requiredOrDefaulted: false;
|
|
388
|
+
}>, P>>): OptionFlag<FlagReturnType<T, {
|
|
389
|
+
multiple: R['multiple'];
|
|
390
|
+
requiredOrDefaulted: false;
|
|
391
|
+
}>>;
|
|
392
|
+
(options: P & {
|
|
393
|
+
multiple: false;
|
|
394
|
+
} & Partial<OptionFlag<FlagReturnType<T, {
|
|
395
|
+
multiple: false;
|
|
396
|
+
requiredOrDefaulted: R['requiredOrDefaulted'];
|
|
397
|
+
}>, P>>): OptionFlag<FlagReturnType<T, {
|
|
398
|
+
multiple: false;
|
|
399
|
+
requiredOrDefaulted: R['requiredOrDefaulted'];
|
|
400
|
+
}>>;
|
|
401
|
+
(options?: P & {
|
|
402
|
+
multiple?: false | undefined;
|
|
403
|
+
} & Partial<OptionFlag<FlagReturnType<T, R>, P>>): OptionFlag<FlagReturnType<T, R>>;
|
|
404
|
+
(options: P & {
|
|
405
|
+
multiple: true;
|
|
406
|
+
} & Partial<OptionFlag<FlagReturnType<T, {
|
|
407
|
+
multiple: true;
|
|
408
|
+
requiredOrDefaulted: R['requiredOrDefaulted'];
|
|
409
|
+
}>, P>>): OptionFlag<FlagReturnType<T, {
|
|
410
|
+
multiple: true;
|
|
411
|
+
requiredOrDefaulted: R['requiredOrDefaulted'];
|
|
412
|
+
}>>;
|
|
271
413
|
};
|
|
272
414
|
export type Flag<T> = BooleanFlag<T> | OptionFlag<T>;
|
|
273
415
|
export type Input<TFlags extends FlagOutput, BFlags extends FlagOutput, AFlags extends ArgOutput> = {
|
|
@@ -289,33 +431,14 @@ export type ParserInput = {
|
|
|
289
431
|
export type ParserContext = Command & {
|
|
290
432
|
token?: FlagToken | ArgToken;
|
|
291
433
|
};
|
|
292
|
-
export type CompletionContext = {
|
|
293
|
-
args?: {
|
|
294
|
-
[name: string]: string;
|
|
295
|
-
};
|
|
296
|
-
flags?: {
|
|
297
|
-
[name: string]: string;
|
|
298
|
-
};
|
|
299
|
-
argv?: string[];
|
|
300
|
-
config: Config;
|
|
301
|
-
};
|
|
302
|
-
export type Completion = {
|
|
303
|
-
skipCache?: boolean;
|
|
304
|
-
cacheDuration?: number;
|
|
305
|
-
cacheKey?(ctx: CompletionContext): Promise<string>;
|
|
306
|
-
options(ctx: CompletionContext): Promise<string[]>;
|
|
307
|
-
};
|
|
308
|
-
export type CompletableOptionFlag<T> = OptionFlag<T> & {
|
|
309
|
-
completion?: Completion;
|
|
310
|
-
};
|
|
311
|
-
export type CompletableFlag<T> = BooleanFlag<T> | CompletableOptionFlag<T>;
|
|
312
434
|
export type FlagInput<T extends FlagOutput = {
|
|
313
435
|
[flag: string]: any;
|
|
314
436
|
}> = {
|
|
315
|
-
[P in keyof T]:
|
|
437
|
+
[P in keyof T]: Flag<T[P]>;
|
|
316
438
|
};
|
|
317
439
|
export type ArgInput<T extends ArgOutput = {
|
|
318
440
|
[arg: string]: any;
|
|
319
441
|
}> = {
|
|
320
442
|
[P in keyof T]: Arg<T[P]>;
|
|
321
443
|
};
|
|
444
|
+
export {};
|
package/lib/main.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import * as Interfaces from './interfaces';
|
|
|
2
2
|
import { Config } from './config';
|
|
3
3
|
export declare const helpAddition: (argv: string[], config: Interfaces.Config) => boolean;
|
|
4
4
|
export declare const versionAddition: (argv: string[], config?: Interfaces.Config) => boolean;
|
|
5
|
-
export
|
|
5
|
+
export declare function run(argv?: string[], options?: Interfaces.LoadOptions): Promise<unknown>;
|