@oclif/core 3.0.0-beta.17 → 3.0.0-beta.18
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/lib/cli-ux/action/base.js +7 -7
- package/lib/cli-ux/action/simple.js +1 -4
- package/lib/cli-ux/action/spinner.js +5 -2
- package/lib/cli-ux/config.js +4 -6
- package/lib/cli-ux/exit.js +3 -0
- package/lib/cli-ux/flush.js +5 -4
- package/lib/cli-ux/index.js +1 -1
- package/lib/cli-ux/stream.js +1 -0
- package/lib/cli-ux/styled/json.js +5 -3
- package/lib/cli-ux/styled/table.js +3 -0
- package/lib/cli-ux/styled/tree.js +1 -3
- package/lib/command.d.ts +6 -14
- package/lib/command.js +81 -68
- package/lib/config/config.d.ts +0 -1
- package/lib/config/config.js +43 -163
- package/lib/config/index.d.ts +0 -1
- package/lib/config/index.js +1 -3
- package/lib/config/plugin-loader.js +5 -4
- package/lib/config/plugin.d.ts +1 -0
- package/lib/config/plugin.js +31 -14
- package/lib/config/ts-node.js +9 -3
- package/lib/config/util.d.ts +0 -6
- package/lib/config/util.js +1 -13
- package/lib/errors/errors/cli.js +3 -1
- package/lib/errors/errors/exit.js +1 -1
- package/lib/errors/errors/module-load.js +1 -1
- package/lib/errors/handle.js +2 -2
- package/lib/errors/logger.js +3 -2
- package/lib/flags.d.ts +2 -2
- package/lib/help/command.js +3 -0
- package/lib/help/docopts.js +3 -0
- package/lib/help/formatter.js +12 -1
- package/lib/help/index.d.ts +5 -1
- package/lib/help/index.js +32 -8
- package/lib/help/root.js +5 -2
- package/lib/help/util.d.ts +1 -7
- package/lib/help/util.js +1 -21
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -3
- package/lib/interfaces/parser.d.ts +8 -7
- package/lib/interfaces/plugin.d.ts +5 -0
- package/lib/module-loader.js +2 -2
- package/lib/parser/errors.js +6 -0
- package/lib/parser/parse.js +9 -2
- package/lib/performance.js +11 -3
- package/lib/util/aggregate-flags.d.ts +2 -0
- package/lib/util/aggregate-flags.js +15 -0
- package/lib/util/cache-command.d.ts +3 -0
- package/lib/util/cache-command.js +100 -0
- package/lib/util/cache-default-value.d.ts +2 -0
- package/lib/util/cache-default-value.js +28 -0
- package/lib/{util.d.ts → util/index.d.ts} +7 -2
- package/lib/{util.js → util/index.js} +13 -16
- package/package.json +9 -5
package/lib/help/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.loadHelpClass = exports.Help = exports.HelpBase = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.CommandHelp = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const util_1 = require("../util");
|
|
6
6
|
const util_2 = require("./util");
|
|
7
7
|
const command_1 = require("./command");
|
|
8
8
|
const formatter_1 = require("./formatter");
|
|
9
9
|
const root_1 = tslib_1.__importDefault(require("./root"));
|
|
10
|
+
const cache_default_value_1 = require("../util/cache-default-value");
|
|
10
11
|
const errors_1 = require("../errors");
|
|
11
12
|
const node_util_1 = require("node:util");
|
|
13
|
+
const module_loader_1 = require("../module-loader");
|
|
12
14
|
const stream_1 = require("../cli-ux/stream");
|
|
13
|
-
const
|
|
14
|
-
const stripAnsi = require("strip-ansi");
|
|
15
|
+
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
15
16
|
var command_2 = require("./command");
|
|
16
17
|
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return command_2.CommandHelp; } });
|
|
17
18
|
var util_3 = require("./util");
|
|
18
19
|
Object.defineProperty(exports, "standardizeIDFromArgv", { enumerable: true, get: function () { return util_3.standardizeIDFromArgv; } });
|
|
19
|
-
Object.defineProperty(exports, "loadHelpClass", { enumerable: true, get: function () { return util_3.loadHelpClass; } });
|
|
20
20
|
Object.defineProperty(exports, "getHelpFlagAdditions", { enumerable: true, get: function () { return util_3.getHelpFlagAdditions; } });
|
|
21
21
|
Object.defineProperty(exports, "normalizeArgv", { enumerable: true, get: function () { return util_3.normalizeArgv; } });
|
|
22
22
|
function getHelpSubject(args, config) {
|
|
@@ -41,6 +41,7 @@ class HelpBase extends formatter_1.HelpFormatter {
|
|
|
41
41
|
}
|
|
42
42
|
exports.HelpBase = HelpBase;
|
|
43
43
|
class Help extends HelpBase {
|
|
44
|
+
CommandHelpClass = command_1.CommandHelp;
|
|
44
45
|
/*
|
|
45
46
|
* _topics is to work around Interfaces.topics mistakenly including commands that do
|
|
46
47
|
* not have children, as well as topics. A topic has children, either commands or other topics. When
|
|
@@ -70,7 +71,6 @@ class Help extends HelpBase {
|
|
|
70
71
|
}
|
|
71
72
|
constructor(config, opts = {}) {
|
|
72
73
|
super(config, opts);
|
|
73
|
-
this.CommandHelpClass = command_1.CommandHelp;
|
|
74
74
|
}
|
|
75
75
|
async showHelp(argv) {
|
|
76
76
|
const originalArgv = argv.slice(1);
|
|
@@ -92,8 +92,14 @@ class Help extends HelpBase {
|
|
|
92
92
|
const command = this.config.findCommand(subject);
|
|
93
93
|
if (command) {
|
|
94
94
|
if (command.hasDynamicHelp && command.pluginType !== 'jit') {
|
|
95
|
-
const
|
|
96
|
-
|
|
95
|
+
const loaded = await command.load();
|
|
96
|
+
for (const [name, flag] of Object.entries(loaded.flags)) {
|
|
97
|
+
if (flag.type === 'boolean' || !command.flags[name].hasDynamicHelp)
|
|
98
|
+
continue;
|
|
99
|
+
// eslint-disable-next-line no-await-in-loop
|
|
100
|
+
command.flags[name].default = await (0, cache_default_value_1.cacheDefaultValue)(flag, false);
|
|
101
|
+
}
|
|
102
|
+
await this.showCommandHelp(command);
|
|
97
103
|
}
|
|
98
104
|
else {
|
|
99
105
|
await this.showCommandHelp(command);
|
|
@@ -251,7 +257,7 @@ class Help extends HelpBase {
|
|
|
251
257
|
description && this.section('DESCRIPTION', this.wrap(description)),
|
|
252
258
|
]).join('\n\n');
|
|
253
259
|
if (this.opts.stripAnsi)
|
|
254
|
-
output =
|
|
260
|
+
output = (0, strip_ansi_1.default)(output);
|
|
255
261
|
return output + '\n';
|
|
256
262
|
}
|
|
257
263
|
formatTopics(topics) {
|
|
@@ -279,3 +285,21 @@ class Help extends HelpBase {
|
|
|
279
285
|
}
|
|
280
286
|
}
|
|
281
287
|
exports.Help = Help;
|
|
288
|
+
function extractClass(exported) {
|
|
289
|
+
return exported && exported.default ? exported.default : exported;
|
|
290
|
+
}
|
|
291
|
+
async function loadHelpClass(config) {
|
|
292
|
+
const { pjson } = config;
|
|
293
|
+
const configuredClass = pjson.oclif?.helpClass;
|
|
294
|
+
if (configuredClass) {
|
|
295
|
+
try {
|
|
296
|
+
const exported = await (0, module_loader_1.load)(config, configuredClass);
|
|
297
|
+
return extractClass(exported);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
throw new Error(`Unable to load configured help class "${configuredClass}", failed with message:\n${error.message}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return Help;
|
|
304
|
+
}
|
|
305
|
+
exports.loadHelpClass = loadHelpClass;
|
package/lib/help/root.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
3
4
|
const formatter_1 = require("./formatter");
|
|
4
5
|
const util_1 = require("../util");
|
|
5
|
-
const
|
|
6
|
+
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
6
7
|
class RootHelp extends formatter_1.HelpFormatter {
|
|
8
|
+
config;
|
|
9
|
+
opts;
|
|
7
10
|
constructor(config, opts) {
|
|
8
11
|
super(config, opts);
|
|
9
12
|
this.config = config;
|
|
@@ -20,7 +23,7 @@ class RootHelp extends formatter_1.HelpFormatter {
|
|
|
20
23
|
this.description(),
|
|
21
24
|
]).join('\n\n');
|
|
22
25
|
if (this.opts.stripAnsi)
|
|
23
|
-
output =
|
|
26
|
+
output = (0, strip_ansi_1.default)(output);
|
|
24
27
|
return output;
|
|
25
28
|
}
|
|
26
29
|
usage() {
|
package/lib/help/util.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { Deprecation,
|
|
2
|
-
import { HelpBase } from '.';
|
|
3
|
-
interface HelpBaseDerived {
|
|
4
|
-
new (config: IConfig, opts?: Partial<HelpOptions>): HelpBase;
|
|
5
|
-
}
|
|
6
|
-
export declare function loadHelpClass(config: IConfig): Promise<HelpBaseDerived>;
|
|
1
|
+
import { Deprecation, Config as IConfig } from '../interfaces';
|
|
7
2
|
export declare function template(context: any): (t: string) => string;
|
|
8
3
|
export declare function toStandardizedId(commandID: string, config: IConfig): string;
|
|
9
4
|
export declare function toConfiguredId(commandID: string, config: IConfig): string;
|
|
@@ -12,4 +7,3 @@ export declare function getHelpFlagAdditions(config: IConfig): string[];
|
|
|
12
7
|
export declare function formatFlagDeprecationWarning(flag: string, opts: true | Deprecation): string;
|
|
13
8
|
export declare function formatCommandDeprecationWarning(command: string, opts?: Deprecation): string;
|
|
14
9
|
export declare function normalizeArgv(config: IConfig, argv?: string[]): string[];
|
|
15
|
-
export {};
|
package/lib/help/util.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeArgv = exports.formatCommandDeprecationWarning = exports.formatFlagDeprecationWarning = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.toConfiguredId = exports.toStandardizedId = exports.template =
|
|
3
|
+
exports.normalizeArgv = exports.formatCommandDeprecationWarning = exports.formatFlagDeprecationWarning = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.toConfiguredId = exports.toStandardizedId = exports.template = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ejs = tslib_1.__importStar(require("ejs"));
|
|
6
|
-
const _1 = require(".");
|
|
7
6
|
const util_1 = require("../config/util");
|
|
8
|
-
const module_loader_1 = require("../module-loader");
|
|
9
|
-
function extractClass(exported) {
|
|
10
|
-
return exported && exported.default ? exported.default : exported;
|
|
11
|
-
}
|
|
12
|
-
async function loadHelpClass(config) {
|
|
13
|
-
const { pjson } = config;
|
|
14
|
-
const configuredClass = pjson && pjson.oclif && pjson.oclif.helpClass;
|
|
15
|
-
if (configuredClass) {
|
|
16
|
-
try {
|
|
17
|
-
const exported = await (0, module_loader_1.load)(config, configuredClass);
|
|
18
|
-
return extractClass(exported);
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
throw new Error(`Unable to load configured help class "${configuredClass}", failed with message:\n${error.message}`);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return _1.Help;
|
|
25
|
-
}
|
|
26
|
-
exports.loadHelpClass = loadHelpClass;
|
|
27
7
|
function template(context) {
|
|
28
8
|
function render(t) {
|
|
29
9
|
return ejs.render(t, context);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export * as Args from './args';
|
|
2
2
|
export * as Errors from './errors';
|
|
3
|
-
export * as Flags from './flags';
|
|
4
3
|
export * as Interfaces from './interfaces';
|
|
4
|
+
export * as Flags from './flags';
|
|
5
5
|
export * as Parser from './parser';
|
|
6
6
|
export * as ux from './cli-ux';
|
|
7
7
|
export { CommandHelp, HelpBase, Help, loadHelpClass } from './help';
|
|
8
|
-
export { Config,
|
|
8
|
+
export { Config, Plugin, tsPath } from './config';
|
|
9
9
|
export { HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable } from './help/formatter';
|
|
10
10
|
export { Settings, settings } from './settings';
|
|
11
11
|
export { stdout, stderr } from './cli-ux/stream';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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.
|
|
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.Config = exports.loadHelpClass = exports.Help = exports.HelpBase = exports.CommandHelp = exports.ux = exports.Parser = exports.Flags = exports.Interfaces = exports.Errors = exports.Args = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const stream_1 = require("./cli-ux/stream");
|
|
6
6
|
function checkCWD() {
|
|
@@ -16,8 +16,8 @@ function checkCWD() {
|
|
|
16
16
|
checkCWD();
|
|
17
17
|
exports.Args = tslib_1.__importStar(require("./args"));
|
|
18
18
|
exports.Errors = tslib_1.__importStar(require("./errors"));
|
|
19
|
-
exports.Flags = tslib_1.__importStar(require("./flags"));
|
|
20
19
|
exports.Interfaces = tslib_1.__importStar(require("./interfaces"));
|
|
20
|
+
exports.Flags = tslib_1.__importStar(require("./flags"));
|
|
21
21
|
exports.Parser = tslib_1.__importStar(require("./parser"));
|
|
22
22
|
exports.ux = tslib_1.__importStar(require("./cli-ux"));
|
|
23
23
|
var help_1 = require("./help");
|
|
@@ -27,7 +27,6 @@ Object.defineProperty(exports, "Help", { enumerable: true, get: function () { re
|
|
|
27
27
|
Object.defineProperty(exports, "loadHelpClass", { enumerable: true, get: function () { return help_1.loadHelpClass; } });
|
|
28
28
|
var config_1 = require("./config");
|
|
29
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
30
|
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return config_1.Plugin; } });
|
|
32
31
|
Object.defineProperty(exports, "tsPath", { enumerable: true, get: function () { return config_1.tsPath; } });
|
|
33
32
|
var settings_1 = require("./settings");
|
|
@@ -161,12 +161,6 @@ export type FlagProps = {
|
|
|
161
161
|
* Emit deprecation warning when a flag alias is provided
|
|
162
162
|
*/
|
|
163
163
|
deprecateAliases?: boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Delimiter to separate the values for a multiple value flag.
|
|
166
|
-
* Only respected if multiple is set to true. Default behavior is to
|
|
167
|
-
* separate on spaces.
|
|
168
|
-
*/
|
|
169
|
-
delimiter?: ',';
|
|
170
164
|
/**
|
|
171
165
|
* If true, the value returned by defaultHelp will not be cached in the oclif.manifest.json.
|
|
172
166
|
* This is helpful if the default value contains sensitive data that shouldn't be published to npm.
|
|
@@ -206,6 +200,12 @@ export type OptionFlagProps = FlagProps & {
|
|
|
206
200
|
helpValue?: string;
|
|
207
201
|
options?: readonly string[];
|
|
208
202
|
multiple?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Delimiter to separate the values for a multiple value flag.
|
|
205
|
+
* Only respected if multiple is set to true. Default behavior is to
|
|
206
|
+
* separate on spaces.
|
|
207
|
+
*/
|
|
208
|
+
delimiter?: ',';
|
|
209
209
|
};
|
|
210
210
|
export type FlagParserContext = Command & {
|
|
211
211
|
token: FlagToken;
|
|
@@ -238,7 +238,7 @@ export type BooleanFlag<T> = FlagProps & BooleanFlagProps & {
|
|
|
238
238
|
parse: (input: boolean, context: FlagParserContext, opts: FlagProps & BooleanFlagProps) => Promise<T>;
|
|
239
239
|
};
|
|
240
240
|
export type OptionFlag<T, P = CustomOptions> = FlagProps & OptionFlagProps & {
|
|
241
|
-
parse: FlagParser<T, string, P>;
|
|
241
|
+
parse: FlagParser<T | undefined, string, P>;
|
|
242
242
|
defaultHelp?: FlagDefaultHelp<T, P>;
|
|
243
243
|
input: string[];
|
|
244
244
|
default?: FlagDefault<T | undefined, P>;
|
|
@@ -415,6 +415,7 @@ export type Flag<T> = BooleanFlag<T> | OptionFlag<T>;
|
|
|
415
415
|
export type Input<TFlags extends FlagOutput, BFlags extends FlagOutput, AFlags extends ArgOutput> = {
|
|
416
416
|
flags?: FlagInput<TFlags>;
|
|
417
417
|
baseFlags?: FlagInput<BFlags>;
|
|
418
|
+
enableJsonFlag?: true | false;
|
|
418
419
|
args?: ArgInput<AFlags>;
|
|
419
420
|
strict?: boolean;
|
|
420
421
|
context?: ParserContext;
|
|
@@ -12,6 +12,7 @@ export interface PluginOptions {
|
|
|
12
12
|
parent?: Plugin;
|
|
13
13
|
children?: Plugin[];
|
|
14
14
|
flexibleTaxonomy?: boolean;
|
|
15
|
+
isRoot?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export interface Options extends PluginOptions {
|
|
17
18
|
devPlugins?: boolean;
|
|
@@ -69,6 +70,10 @@ export interface Plugin {
|
|
|
69
70
|
* if it appears to be an npm package but does not look like it's really a CLI plugin, this is set to false
|
|
70
71
|
*/
|
|
71
72
|
valid: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* True if the plugin is the root plugin.
|
|
75
|
+
*/
|
|
76
|
+
isRoot: boolean;
|
|
72
77
|
commands: Command.Loadable[];
|
|
73
78
|
hooks: {
|
|
74
79
|
[k: string]: string[];
|
package/lib/module-loader.js
CHANGED
|
@@ -5,7 +5,7 @@ const node_fs_1 = require("node:fs");
|
|
|
5
5
|
const node_path_1 = require("node:path");
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
7
|
const node_url_1 = require("node:url");
|
|
8
|
-
const
|
|
8
|
+
const ts_node_1 = require("./config/ts-node");
|
|
9
9
|
const getPackageType = require('get-package-type');
|
|
10
10
|
/**
|
|
11
11
|
* Defines file extension resolution when source files do not have an extension.
|
|
@@ -160,7 +160,7 @@ function resolvePath(config, modulePath) {
|
|
|
160
160
|
isESM = isPathModule(filePath);
|
|
161
161
|
}
|
|
162
162
|
catch {
|
|
163
|
-
filePath = (isPlugin(config) ? (0,
|
|
163
|
+
filePath = (isPlugin(config) ? (0, ts_node_1.tsPath)(config.root, modulePath, config) : (0, ts_node_1.tsPath)(config.root, modulePath)) ?? modulePath;
|
|
164
164
|
let fileExists = false;
|
|
165
165
|
let isDirectory = false;
|
|
166
166
|
if ((0, node_fs_1.existsSync)(filePath)) {
|
package/lib/parser/errors.js
CHANGED
|
@@ -10,6 +10,7 @@ const util_1 = require("../util");
|
|
|
10
10
|
var errors_2 = require("../errors");
|
|
11
11
|
Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
|
|
12
12
|
class CLIParseError extends errors_1.CLIError {
|
|
13
|
+
parse;
|
|
13
14
|
constructor(options) {
|
|
14
15
|
options.message += '\nSee more help with --help';
|
|
15
16
|
super(options.message);
|
|
@@ -18,6 +19,7 @@ class CLIParseError extends errors_1.CLIError {
|
|
|
18
19
|
}
|
|
19
20
|
exports.CLIParseError = CLIParseError;
|
|
20
21
|
class InvalidArgsSpecError extends CLIParseError {
|
|
22
|
+
args;
|
|
21
23
|
constructor({ args, parse }) {
|
|
22
24
|
let message = 'Invalid argument spec';
|
|
23
25
|
const namedArgs = Object.values(args).filter(a => a.name);
|
|
@@ -31,6 +33,7 @@ class InvalidArgsSpecError extends CLIParseError {
|
|
|
31
33
|
}
|
|
32
34
|
exports.InvalidArgsSpecError = InvalidArgsSpecError;
|
|
33
35
|
class RequiredArgsError extends CLIParseError {
|
|
36
|
+
args;
|
|
34
37
|
constructor({ args, parse, flagsWithMultiple }) {
|
|
35
38
|
let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}`;
|
|
36
39
|
const namedArgs = args.filter(a => a.name);
|
|
@@ -49,6 +52,7 @@ class RequiredArgsError extends CLIParseError {
|
|
|
49
52
|
}
|
|
50
53
|
exports.RequiredArgsError = RequiredArgsError;
|
|
51
54
|
class RequiredFlagError extends CLIParseError {
|
|
55
|
+
flag;
|
|
52
56
|
constructor({ flag, parse }) {
|
|
53
57
|
const usage = (0, list_1.renderList)((0, help_1.flagUsages)([flag], { displayRequired: false }));
|
|
54
58
|
const message = `Missing required flag:\n${usage}`;
|
|
@@ -58,6 +62,7 @@ class RequiredFlagError extends CLIParseError {
|
|
|
58
62
|
}
|
|
59
63
|
exports.RequiredFlagError = RequiredFlagError;
|
|
60
64
|
class UnexpectedArgsError extends CLIParseError {
|
|
65
|
+
args;
|
|
61
66
|
constructor({ parse, args }) {
|
|
62
67
|
const message = `Unexpected argument${args.length === 1 ? '' : 's'}: ${args.join(', ')}`;
|
|
63
68
|
super({ parse, message });
|
|
@@ -66,6 +71,7 @@ class UnexpectedArgsError extends CLIParseError {
|
|
|
66
71
|
}
|
|
67
72
|
exports.UnexpectedArgsError = UnexpectedArgsError;
|
|
68
73
|
class NonExistentFlagsError extends CLIParseError {
|
|
74
|
+
flags;
|
|
69
75
|
constructor({ parse, flags }) {
|
|
70
76
|
const message = `Nonexistent flag${flags.length === 1 ? '' : 's'}: ${flags.join(', ')}`;
|
|
71
77
|
super({ parse, message });
|
package/lib/parser/parse.js
CHANGED
|
@@ -60,9 +60,15 @@ const validateOptions = (flag, input) => {
|
|
|
60
60
|
return input;
|
|
61
61
|
};
|
|
62
62
|
class Parser {
|
|
63
|
+
input;
|
|
64
|
+
argv;
|
|
65
|
+
raw = [];
|
|
66
|
+
booleanFlags;
|
|
67
|
+
flagAliases;
|
|
68
|
+
context;
|
|
69
|
+
currentFlag;
|
|
63
70
|
constructor(input) {
|
|
64
71
|
this.input = input;
|
|
65
|
-
this.raw = [];
|
|
66
72
|
this.context = input.context ?? {};
|
|
67
73
|
this.argv = [...input.argv];
|
|
68
74
|
this._setNames();
|
|
@@ -197,7 +203,8 @@ class Parser {
|
|
|
197
203
|
// multiple with custom delimiter
|
|
198
204
|
if (fws.inputFlag.flag.type === 'option' && fws.inputFlag.flag.delimiter && fws.inputFlag.flag.multiple) {
|
|
199
205
|
return {
|
|
200
|
-
...fws,
|
|
206
|
+
...fws,
|
|
207
|
+
valueFunction: async (i) => (await Promise.all(((i.tokens ?? []).flatMap(token => token.input.split(i.inputFlag.flag.delimiter ?? ',')))
|
|
201
208
|
// trim, and remove surrounding doubleQuotes (which would hav been needed if the elements contain spaces)
|
|
202
209
|
.map(v => v.trim().replace(/^"(.*)"$/, '$1').replace(/^'(.*)'$/, '$1'))
|
|
203
210
|
.map(async (v) => parseFlagOrThrowError(v, i.inputFlag.flag, this.context, { ...(0, util_1.last)(i.tokens), input: v })))).map(v => validateOptions(i.inputFlag.flag, v)),
|
package/lib/performance.js
CHANGED
|
@@ -4,10 +4,17 @@ exports.Performance = void 0;
|
|
|
4
4
|
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
5
5
|
const settings_1 = require("./settings");
|
|
6
6
|
class Marker {
|
|
7
|
+
name;
|
|
8
|
+
details;
|
|
9
|
+
module;
|
|
10
|
+
method;
|
|
11
|
+
scope;
|
|
12
|
+
stopped = false;
|
|
13
|
+
startMarker;
|
|
14
|
+
stopMarker;
|
|
7
15
|
constructor(name, details = {}) {
|
|
8
16
|
this.name = name;
|
|
9
17
|
this.details = details;
|
|
10
|
-
this.stopped = false;
|
|
11
18
|
this.startMarker = `${this.name}-start`;
|
|
12
19
|
this.stopMarker = `${this.name}-stop`;
|
|
13
20
|
const [caller, scope] = name.split('#');
|
|
@@ -29,6 +36,9 @@ class Marker {
|
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
38
|
class Performance {
|
|
39
|
+
static markers = {};
|
|
40
|
+
static _results = [];
|
|
41
|
+
static _highlights;
|
|
32
42
|
static get enabled() {
|
|
33
43
|
return settings_1.settings.performanceEnabled ?? false;
|
|
34
44
|
}
|
|
@@ -185,5 +195,3 @@ class Performance {
|
|
|
185
195
|
}
|
|
186
196
|
}
|
|
187
197
|
exports.Performance = Performance;
|
|
188
|
-
Performance.markers = {};
|
|
189
|
-
Performance._results = [];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aggregateFlags = void 0;
|
|
4
|
+
const flags_1 = require("../flags");
|
|
5
|
+
const json = (0, flags_1.boolean)({
|
|
6
|
+
description: 'Format output as json.',
|
|
7
|
+
helpGroup: 'GLOBAL',
|
|
8
|
+
});
|
|
9
|
+
function aggregateFlags(flags, baseFlags, enableJsonFlag) {
|
|
10
|
+
const combinedFlags = { ...baseFlags, ...flags };
|
|
11
|
+
return (enableJsonFlag
|
|
12
|
+
? { json, ...combinedFlags }
|
|
13
|
+
: combinedFlags);
|
|
14
|
+
}
|
|
15
|
+
exports.aggregateFlags = aggregateFlags;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cacheCommand = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const aggregate_flags_1 = require("./aggregate-flags");
|
|
6
|
+
const cache_default_value_1 = require("./cache-default-value");
|
|
7
|
+
// In order to collect static properties up the inheritance chain, we need to recursively
|
|
8
|
+
// access the prototypes until there's nothing left. This allows us to combine baseFlags
|
|
9
|
+
// and flags as well as add in the json flag if enableJsonFlag is enabled.
|
|
10
|
+
function mergePrototype(result, cmd) {
|
|
11
|
+
const proto = Object.getPrototypeOf(cmd);
|
|
12
|
+
const filteredProto = (0, index_1.pickBy)(proto, v => v !== undefined);
|
|
13
|
+
return Object.keys(proto).length > 0 ? mergePrototype({ ...filteredProto, ...result }, proto) : result;
|
|
14
|
+
}
|
|
15
|
+
async function cacheFlags(cmdFlags, respectNoCacheDefault) {
|
|
16
|
+
const promises = Object.entries(cmdFlags).map(async ([name, flag]) => ([name, {
|
|
17
|
+
name,
|
|
18
|
+
char: flag.char,
|
|
19
|
+
summary: flag.summary,
|
|
20
|
+
hidden: flag.hidden,
|
|
21
|
+
required: flag.required,
|
|
22
|
+
helpLabel: flag.helpLabel,
|
|
23
|
+
helpGroup: flag.helpGroup,
|
|
24
|
+
description: flag.description,
|
|
25
|
+
dependsOn: flag.dependsOn,
|
|
26
|
+
relationships: flag.relationships,
|
|
27
|
+
exclusive: flag.exclusive,
|
|
28
|
+
deprecated: flag.deprecated,
|
|
29
|
+
deprecateAliases: flag.deprecateAliases,
|
|
30
|
+
aliases: flag.aliases,
|
|
31
|
+
charAliases: flag.charAliases,
|
|
32
|
+
noCacheDefault: flag.noCacheDefault,
|
|
33
|
+
...flag.type === 'boolean' ? {
|
|
34
|
+
allowNo: flag.allowNo,
|
|
35
|
+
type: flag.type,
|
|
36
|
+
} : {
|
|
37
|
+
type: flag.type,
|
|
38
|
+
helpValue: flag.helpValue,
|
|
39
|
+
multiple: flag.multiple,
|
|
40
|
+
options: flag.options,
|
|
41
|
+
delimiter: flag.delimiter,
|
|
42
|
+
default: await (0, cache_default_value_1.cacheDefaultValue)(flag, respectNoCacheDefault),
|
|
43
|
+
hasDynamicHelp: typeof flag.defaultHelp === 'function',
|
|
44
|
+
},
|
|
45
|
+
}]));
|
|
46
|
+
return Object.fromEntries(await Promise.all(promises));
|
|
47
|
+
}
|
|
48
|
+
async function cacheArgs(cmdArgs, respectNoCacheDefault) {
|
|
49
|
+
const promises = Object.entries(cmdArgs).map(async ([name, arg]) => ([name, {
|
|
50
|
+
name,
|
|
51
|
+
description: arg.description,
|
|
52
|
+
required: arg.required,
|
|
53
|
+
options: arg.options,
|
|
54
|
+
default: await (0, cache_default_value_1.cacheDefaultValue)(arg, respectNoCacheDefault),
|
|
55
|
+
hidden: arg.hidden,
|
|
56
|
+
noCacheDefault: arg.noCacheDefault,
|
|
57
|
+
}]));
|
|
58
|
+
return Object.fromEntries(await Promise.all(promises));
|
|
59
|
+
}
|
|
60
|
+
async function cacheCommand(uncachedCmd, plugin, respectNoCacheDefault = false) {
|
|
61
|
+
const cmd = mergePrototype(uncachedCmd, uncachedCmd);
|
|
62
|
+
const flags = await cacheFlags((0, aggregate_flags_1.aggregateFlags)(cmd.flags, cmd.baseFlags, cmd.enableJsonFlag), respectNoCacheDefault);
|
|
63
|
+
const args = await cacheArgs((0, index_1.ensureArgObject)(cmd.args), respectNoCacheDefault);
|
|
64
|
+
const stdProperties = {
|
|
65
|
+
id: cmd.id,
|
|
66
|
+
summary: cmd.summary,
|
|
67
|
+
description: cmd.description,
|
|
68
|
+
strict: cmd.strict,
|
|
69
|
+
usage: cmd.usage,
|
|
70
|
+
pluginName: plugin && plugin.name,
|
|
71
|
+
pluginAlias: plugin && plugin.alias,
|
|
72
|
+
pluginType: plugin && plugin.type,
|
|
73
|
+
hidden: cmd.hidden,
|
|
74
|
+
state: cmd.state,
|
|
75
|
+
aliases: cmd.aliases || [],
|
|
76
|
+
examples: cmd.examples || cmd.example,
|
|
77
|
+
deprecationOptions: cmd.deprecationOptions,
|
|
78
|
+
deprecateAliases: cmd.deprecateAliases,
|
|
79
|
+
flags,
|
|
80
|
+
args,
|
|
81
|
+
hasDynamicHelp: Object.values(flags).some(f => f.hasDynamicHelp),
|
|
82
|
+
};
|
|
83
|
+
// do not include these properties in manifest
|
|
84
|
+
const ignoreCommandProperties = [
|
|
85
|
+
'plugin',
|
|
86
|
+
'_flags',
|
|
87
|
+
'_enableJsonFlag',
|
|
88
|
+
'_globalFlags',
|
|
89
|
+
'_baseFlags',
|
|
90
|
+
'baseFlags',
|
|
91
|
+
'_--',
|
|
92
|
+
'_base',
|
|
93
|
+
];
|
|
94
|
+
// Add in any additional properties that are not standard command properties.
|
|
95
|
+
const stdKeysAndIgnored = new Set([...Object.keys(stdProperties), ...ignoreCommandProperties]);
|
|
96
|
+
const keysToAdd = Object.keys(cmd).filter(property => !stdKeysAndIgnored.has(property));
|
|
97
|
+
const additionalProperties = Object.fromEntries(keysToAdd.map(key => [key, cmd[key]]));
|
|
98
|
+
return { ...stdProperties, ...additionalProperties };
|
|
99
|
+
}
|
|
100
|
+
exports.cacheCommand = cacheCommand;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cacheDefaultValue = void 0;
|
|
4
|
+
// when no manifest exists, the default is calculated. This may throw, so we need to catch it
|
|
5
|
+
const cacheDefaultValue = async (flagOrArg, respectNoCacheDefault) => {
|
|
6
|
+
if (respectNoCacheDefault && flagOrArg.noCacheDefault)
|
|
7
|
+
return;
|
|
8
|
+
// Prefer the defaultHelp function (returns a friendly string for complex types)
|
|
9
|
+
if (typeof flagOrArg.defaultHelp === 'function') {
|
|
10
|
+
try {
|
|
11
|
+
return await flagOrArg.defaultHelp({ options: flagOrArg, flags: {} });
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// if not specified, try the default function
|
|
18
|
+
if (typeof flagOrArg.default === 'function') {
|
|
19
|
+
try {
|
|
20
|
+
return await flagOrArg.default({ options: flagOrArg, flags: {} });
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return flagOrArg.default;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.cacheDefaultValue = cacheDefaultValue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ArgInput } from '
|
|
3
|
-
import { Command } from '
|
|
2
|
+
import { ArgInput } from '../interfaces/parser';
|
|
3
|
+
import { Command } from '../command';
|
|
4
4
|
export declare function pickBy<T extends {
|
|
5
5
|
[s: string]: T[keyof T];
|
|
6
6
|
} | ArrayLike<T[keyof T]>>(obj: T, fn: (i: T[keyof T]) => boolean): Partial<T>;
|
|
@@ -52,4 +52,9 @@ export declare function getPlatform(): NodeJS.Platform;
|
|
|
52
52
|
export declare function readJson<T = unknown>(path: string): Promise<T>;
|
|
53
53
|
export declare function readJsonSync(path: string, parse: false): string;
|
|
54
54
|
export declare function readJsonSync<T = unknown>(path: string, parse?: true): T;
|
|
55
|
+
export declare function mapValues<T extends Record<string, any>, TResult>(obj: {
|
|
56
|
+
[P in keyof T]: T[P];
|
|
57
|
+
}, fn: (i: T[keyof T], k: keyof T) => TResult): {
|
|
58
|
+
[P in keyof T]: TResult;
|
|
59
|
+
};
|
|
55
60
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readJsonSync = exports.readJson = exports.getPlatform = exports.getHomeDir = exports.uniq = exports.ensureArgObject = exports.requireJson = exports.isNotFalsy = exports.isTruthy = exports.fileExists = exports.dirExists = exports.exists = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.last = exports.uniqBy = exports.compact = exports.pickBy = void 0;
|
|
3
|
+
exports.mapValues = exports.readJsonSync = exports.readJson = exports.getPlatform = exports.getHomeDir = exports.uniq = exports.ensureArgObject = exports.requireJson = exports.isNotFalsy = exports.isTruthy = exports.fileExists = exports.dirExists = exports.exists = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.last = exports.uniqBy = exports.compact = exports.pickBy = void 0;
|
|
4
4
|
const promises_1 = require("node:fs/promises");
|
|
5
5
|
const node_os_1 = require("node:os");
|
|
6
|
-
const node_fs_1 = require("node:fs");
|
|
7
6
|
const node_path_1 = require("node:path");
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
8
|
const debug = require('debug');
|
|
9
9
|
function pickBy(obj, fn) {
|
|
10
10
|
return Object.entries(obj)
|
|
@@ -166,21 +166,10 @@ function getPlatform() {
|
|
|
166
166
|
return (0, node_os_1.platform)();
|
|
167
167
|
}
|
|
168
168
|
exports.getPlatform = getPlatform;
|
|
169
|
-
function readJson(path) {
|
|
169
|
+
async function readJson(path) {
|
|
170
170
|
debug('config')('readJson %s', path);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
if (err)
|
|
175
|
-
reject(err);
|
|
176
|
-
else
|
|
177
|
-
resolve(JSON.parse(d));
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
reject(error);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
});
|
|
171
|
+
const contents = await (0, promises_1.readFile)(path, 'utf8');
|
|
172
|
+
return JSON.parse(contents);
|
|
184
173
|
}
|
|
185
174
|
exports.readJson = readJson;
|
|
186
175
|
function readJsonSync(path, parse = true) {
|
|
@@ -188,3 +177,11 @@ function readJsonSync(path, parse = true) {
|
|
|
188
177
|
return parse ? JSON.parse(contents) : contents;
|
|
189
178
|
}
|
|
190
179
|
exports.readJsonSync = readJsonSync;
|
|
180
|
+
function mapValues(obj, fn) {
|
|
181
|
+
return Object.entries(obj)
|
|
182
|
+
.reduce((o, [k, v]) => {
|
|
183
|
+
o[k] = fn(v, k);
|
|
184
|
+
return o;
|
|
185
|
+
}, {});
|
|
186
|
+
}
|
|
187
|
+
exports.mapValues = mapValues;
|