@oclif/core 1.12.1 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/lib/cli-ux/list.js +1 -2
- package/lib/cli-ux/prompt.js +1 -2
- package/lib/cli-ux/styled/table.js +7 -10
- package/lib/command.d.ts +8 -8
- package/lib/command.js +3 -5
- package/lib/config/config.js +9 -11
- package/lib/config/plugin.js +1 -2
- package/lib/errors/errors/cli.js +1 -1
- package/lib/errors/handle.js +1 -2
- package/lib/errors/index.js +2 -4
- package/lib/help/docopts.js +3 -5
- package/lib/help/index.js +3 -6
- package/lib/help/util.js +2 -4
- package/lib/interfaces/parser.d.ts +8 -6
- package/lib/main.js +2 -4
- package/lib/module-loader.js +1 -2
- package/lib/parser/flags.d.ts +4 -1
- package/lib/parser/flags.js +16 -7
- package/lib/parser/index.d.ts +6 -3
- package/lib/parser/index.js +1 -2
- package/lib/parser/validate.d.ts +1 -1
- package/lib/parser/validate.js +1 -2
- package/lib/util.js +1 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.13.2](https://github.com/oclif/core/compare/v1.13.1...v1.13.2) (2022-08-05)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* flag types ([#454](https://github.com/oclif/core/issues/454)) ([2938ba4](https://github.com/oclif/core/commit/2938ba4082d1b0c603a55678fe47f5beed9acbb5))
|
|
11
|
+
|
|
12
|
+
### [1.13.1](https://github.com/oclif/core/compare/v1.13.0...v1.13.1) (2022-08-02)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* throw appropriate error in runCommand ([#455](https://github.com/oclif/core/issues/455)) ([66e9bbc](https://github.com/oclif/core/commit/66e9bbca08f9e1f4a08e1c8c144bf85c274b7f82))
|
|
18
|
+
|
|
19
|
+
## [1.13.0](https://github.com/oclif/core/compare/v1.12.1...v1.13.0) (2022-07-28)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* drop node12, use es2020 ([ac749e3](https://github.com/oclif/core/commit/ac749e32917400386f0ee4056aa5b66a52f3d0e0))
|
|
25
|
+
* min/max for integer flag ([7e05ef7](https://github.com/oclif/core/commit/7e05ef7195269012055f30095552e61359fad47e))
|
|
26
|
+
* node14/es2020 for bigint, pr feedback ([03a50b8](https://github.com/oclif/core/commit/03a50b874a8e7ef621c23d846e63864e3850ee4a))
|
|
27
|
+
|
|
5
28
|
### [1.12.1](https://github.com/oclif/core/compare/v1.12.0...v1.12.1) (2022-07-21)
|
|
6
29
|
|
|
7
30
|
|
package/lib/cli-ux/list.js
CHANGED
|
@@ -11,11 +11,10 @@ function linewrap(length, s) {
|
|
|
11
11
|
})(s).trim();
|
|
12
12
|
}
|
|
13
13
|
function renderList(items) {
|
|
14
|
-
var _a, _b;
|
|
15
14
|
if (items.length === 0) {
|
|
16
15
|
return '';
|
|
17
16
|
}
|
|
18
|
-
const maxLength = (
|
|
17
|
+
const maxLength = (0, util_1.maxBy)(items, item => item[0].length)?.[0].length ?? 0;
|
|
19
18
|
const lines = items.map(i => {
|
|
20
19
|
let left = i[0];
|
|
21
20
|
let right = i[1];
|
package/lib/cli-ux/prompt.js
CHANGED
|
@@ -46,11 +46,10 @@ function getPrompt(name, type, defaultValue) {
|
|
|
46
46
|
return prompt;
|
|
47
47
|
}
|
|
48
48
|
async function single(options) {
|
|
49
|
-
var _a;
|
|
50
49
|
const raw = process.stdin.isRaw;
|
|
51
50
|
if (process.stdin.setRawMode)
|
|
52
51
|
process.stdin.setRawMode(true);
|
|
53
|
-
options.required =
|
|
52
|
+
options.required = options.required ?? false;
|
|
54
53
|
const response = await normal(options);
|
|
55
54
|
if (process.stdin.setRawMode)
|
|
56
55
|
process.stdin.setRawMode(Boolean(raw));
|
|
@@ -11,17 +11,15 @@ const sw = require('string-width');
|
|
|
11
11
|
const { orderBy } = require('natural-orderby');
|
|
12
12
|
class Table {
|
|
13
13
|
constructor(data, columns, options = {}) {
|
|
14
|
-
var _a, _b;
|
|
15
14
|
this.data = data;
|
|
16
15
|
// assign columns
|
|
17
16
|
this.columns = Object.keys(columns).map((key) => {
|
|
18
|
-
var _a, _b, _c;
|
|
19
17
|
const col = columns[key];
|
|
20
|
-
const extended =
|
|
18
|
+
const extended = col.extended ?? false;
|
|
21
19
|
// turn null and undefined into empty strings by default
|
|
22
|
-
const get =
|
|
20
|
+
const get = col.get ?? ((row) => row[key] ?? '');
|
|
23
21
|
const header = typeof col.header === 'string' ? col.header : (0, util_1.capitalize)(key.replace(/_/g, ' '));
|
|
24
|
-
const minWidth = Math.max(
|
|
22
|
+
const minWidth = Math.max(col.minWidth ?? 0, sw(header) + 1);
|
|
25
23
|
return {
|
|
26
24
|
extended,
|
|
27
25
|
get,
|
|
@@ -37,9 +35,9 @@ class Table {
|
|
|
37
35
|
output: csv ? 'csv' : output,
|
|
38
36
|
extended,
|
|
39
37
|
filter,
|
|
40
|
-
'no-header':
|
|
41
|
-
'no-truncate':
|
|
42
|
-
printLine: printLine
|
|
38
|
+
'no-header': options['no-header'] ?? false,
|
|
39
|
+
'no-truncate': options['no-truncate'] ?? false,
|
|
40
|
+
printLine: printLine ?? ((s) => process.stdout.write(s + '\n')),
|
|
43
41
|
rowStart: ' ',
|
|
44
42
|
sort,
|
|
45
43
|
title,
|
|
@@ -133,10 +131,9 @@ class Table {
|
|
|
133
131
|
return data.map((d) => {
|
|
134
132
|
// eslint-disable-next-line unicorn/prefer-object-from-entries
|
|
135
133
|
return columns.reduce((obj, col) => {
|
|
136
|
-
var _a;
|
|
137
134
|
return {
|
|
138
135
|
...obj,
|
|
139
|
-
[col.key]:
|
|
136
|
+
[col.key]: d[col.key] ?? '',
|
|
140
137
|
};
|
|
141
138
|
}, {});
|
|
142
139
|
});
|
package/lib/command.d.ts
CHANGED
|
@@ -65,13 +65,13 @@ export default abstract class Command {
|
|
|
65
65
|
* @param {Interfaces.LoadOptions} opts options
|
|
66
66
|
*/
|
|
67
67
|
static run: Interfaces.Command.Class['run'];
|
|
68
|
-
protected static _globalFlags: Interfaces.FlagInput
|
|
69
|
-
static get globalFlags(): Interfaces.FlagInput
|
|
70
|
-
static set globalFlags(flags: Interfaces.FlagInput
|
|
68
|
+
protected static _globalFlags: Interfaces.FlagInput;
|
|
69
|
+
static get globalFlags(): Interfaces.FlagInput;
|
|
70
|
+
static set globalFlags(flags: Interfaces.FlagInput);
|
|
71
71
|
/** A hash of flags for the command */
|
|
72
|
-
protected static _flags: Interfaces.FlagInput
|
|
73
|
-
static get flags(): Interfaces.FlagInput
|
|
74
|
-
static set flags(flags: Interfaces.FlagInput
|
|
72
|
+
protected static _flags: Interfaces.FlagInput;
|
|
73
|
+
static get flags(): Interfaces.FlagInput;
|
|
74
|
+
static set flags(flags: Interfaces.FlagInput);
|
|
75
75
|
id: string | undefined;
|
|
76
76
|
protected debug: (...args: any[]) => void;
|
|
77
77
|
constructor(argv: string[], config: Config);
|
|
@@ -95,9 +95,9 @@ export default abstract class Command {
|
|
|
95
95
|
*/
|
|
96
96
|
abstract run(): PromiseLike<any>;
|
|
97
97
|
protected init(): Promise<any>;
|
|
98
|
-
protected parse<F, A extends {
|
|
98
|
+
protected parse<F, G, A extends {
|
|
99
99
|
[name: string]: any;
|
|
100
|
-
}>(options?: Interfaces.Input<F>, argv?: string[]): Promise<Interfaces.ParserOutput<F, A>>;
|
|
100
|
+
}>(options?: Interfaces.Input<F, G>, argv?: string[]): Promise<Interfaces.ParserOutput<F, G, A>>;
|
|
101
101
|
protected catch(err: Error & {
|
|
102
102
|
exitCode?: number;
|
|
103
103
|
}): Promise<any>;
|
package/lib/command.js
CHANGED
|
@@ -58,8 +58,7 @@ class Command {
|
|
|
58
58
|
return this._flags;
|
|
59
59
|
}
|
|
60
60
|
static set flags(flags) {
|
|
61
|
-
|
|
62
|
-
this._flags = Object.assign({}, (_a = this._flags) !== null && _a !== void 0 ? _a : {}, this.globalFlags, flags);
|
|
61
|
+
this._flags = Object.assign({}, this._flags ?? {}, this.globalFlags, flags);
|
|
63
62
|
}
|
|
64
63
|
get ctor() {
|
|
65
64
|
return this.constructor;
|
|
@@ -130,12 +129,11 @@ class Command {
|
|
|
130
129
|
options = this.constructor;
|
|
131
130
|
const opts = { context: this, ...options };
|
|
132
131
|
// the spread operator doesn't work with getters so we have to manually add it here
|
|
133
|
-
opts.flags =
|
|
132
|
+
opts.flags = options?.flags;
|
|
134
133
|
return Parser.parse(argv, opts);
|
|
135
134
|
}
|
|
136
135
|
async catch(err) {
|
|
137
|
-
|
|
138
|
-
process.exitCode = (_b = (_a = process.exitCode) !== null && _a !== void 0 ? _a : err.exitCode) !== null && _b !== void 0 ? _b : 1;
|
|
136
|
+
process.exitCode = process.exitCode ?? err.exitCode ?? 1;
|
|
139
137
|
if (this.jsonEnabled()) {
|
|
140
138
|
index_1.CliUx.ux.styledJSON(this.toErrorJson(err));
|
|
141
139
|
}
|
package/lib/config/config.js
CHANGED
|
@@ -40,8 +40,7 @@ class Permutations extends Map {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
get(key) {
|
|
43
|
-
|
|
44
|
-
return (_a = super.get(key)) !== null && _a !== void 0 ? _a : new Set();
|
|
43
|
+
return super.get(key) ?? new Set();
|
|
45
44
|
}
|
|
46
45
|
getValid(key) {
|
|
47
46
|
return this.validPermutations.get(key);
|
|
@@ -261,6 +260,9 @@ class Config {
|
|
|
261
260
|
const cmdResult = hookResult.successes[0].result;
|
|
262
261
|
return cmdResult;
|
|
263
262
|
}
|
|
263
|
+
if (hookResult.failures[0]) {
|
|
264
|
+
throw hookResult.failures[0].error;
|
|
265
|
+
}
|
|
264
266
|
throw new errors_1.CLIError(`command ${id} not found`);
|
|
265
267
|
}
|
|
266
268
|
const command = await c.load();
|
|
@@ -357,12 +359,11 @@ class Config {
|
|
|
357
359
|
return [...this._topics.values()];
|
|
358
360
|
}
|
|
359
361
|
s3Key(type, ext, options = {}) {
|
|
360
|
-
var _a;
|
|
361
362
|
if (typeof ext === 'object')
|
|
362
363
|
options = ext;
|
|
363
364
|
else if (ext)
|
|
364
365
|
options.ext = ext;
|
|
365
|
-
const template =
|
|
366
|
+
const template = this.pjson.oclif.update.s3.templates[options.platform ? 'target' : 'vanilla'][type] ?? '';
|
|
366
367
|
return ejs.render(template, { ...this, ...options });
|
|
367
368
|
}
|
|
368
369
|
s3Url(key) {
|
|
@@ -501,7 +502,6 @@ class Config {
|
|
|
501
502
|
return id;
|
|
502
503
|
}
|
|
503
504
|
loadCommands(plugin) {
|
|
504
|
-
var _a;
|
|
505
505
|
for (const command of plugin.commands) {
|
|
506
506
|
if (this._commands.has(command.id)) {
|
|
507
507
|
const prioritizedCommand = this.determinePriority([this._commands.get(command.id), command]);
|
|
@@ -514,7 +514,7 @@ class Config {
|
|
|
514
514
|
for (const permutation of permutations) {
|
|
515
515
|
this.commandPermutations.add(permutation, command.id);
|
|
516
516
|
}
|
|
517
|
-
for (const alias of
|
|
517
|
+
for (const alias of command.aliases ?? []) {
|
|
518
518
|
if (this._commands.has(alias)) {
|
|
519
519
|
const prioritizedCommand = this.determinePriority([this._commands.get(alias), command]);
|
|
520
520
|
this._commands.set(prioritizedCommand.id, { ...prioritizedCommand, id: alias });
|
|
@@ -576,12 +576,10 @@ class Config {
|
|
|
576
576
|
* @returns command instance {Command.Loadable} or undefined
|
|
577
577
|
*/
|
|
578
578
|
determinePriority(commands) {
|
|
579
|
-
|
|
580
|
-
const oclifPlugins = (_b = (_a = this.pjson.oclif) === null || _a === void 0 ? void 0 : _a.plugins) !== null && _b !== void 0 ? _b : [];
|
|
579
|
+
const oclifPlugins = this.pjson.oclif?.plugins ?? [];
|
|
581
580
|
const commandPlugins = commands.sort((a, b) => {
|
|
582
|
-
|
|
583
|
-
const
|
|
584
|
-
const pluginAliasB = (_b = b.pluginAlias) !== null && _b !== void 0 ? _b : 'B-Cannot-Find-This';
|
|
581
|
+
const pluginAliasA = a.pluginAlias ?? 'A-Cannot-Find-This';
|
|
582
|
+
const pluginAliasB = b.pluginAlias ?? 'B-Cannot-Find-This';
|
|
585
583
|
const aIndex = oclifPlugins.indexOf(pluginAliasA);
|
|
586
584
|
const bIndex = oclifPlugins.indexOf(pluginAliasB);
|
|
587
585
|
// When both plugin types are 'core' plugins sort based on index
|
package/lib/config/plugin.js
CHANGED
|
@@ -99,7 +99,6 @@ class Plugin {
|
|
|
99
99
|
this.warned = false;
|
|
100
100
|
}
|
|
101
101
|
async load() {
|
|
102
|
-
var _a;
|
|
103
102
|
this.type = this.options.type || 'core';
|
|
104
103
|
this.tag = this.options.tag;
|
|
105
104
|
const root = await findRoot(this.options.name, this.options.root);
|
|
@@ -109,7 +108,7 @@ class Plugin {
|
|
|
109
108
|
this._debug('reading %s plugin %s', this.type, root);
|
|
110
109
|
this.pjson = await (0, util_3.loadJSON)(path.join(root, 'package.json'));
|
|
111
110
|
this.name = this.pjson.name;
|
|
112
|
-
this.alias =
|
|
111
|
+
this.alias = this.options.name ?? this.pjson.name;
|
|
113
112
|
const pjsonPath = path.join(root, 'package.json');
|
|
114
113
|
if (!this.name)
|
|
115
114
|
throw new Error(`no name in ${pjsonPath}`);
|
package/lib/errors/errors/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ function addOclifExitCode(error, options) {
|
|
|
14
14
|
if (!('oclif' in error)) {
|
|
15
15
|
error.oclif = {};
|
|
16
16
|
}
|
|
17
|
-
error.oclif.exit =
|
|
17
|
+
error.oclif.exit = options?.exit === undefined ? 2 : options.exit;
|
|
18
18
|
return error;
|
|
19
19
|
}
|
|
20
20
|
exports.addOclifExitCode = addOclifExitCode;
|
package/lib/errors/handle.js
CHANGED
|
@@ -9,7 +9,6 @@ const _1 = require(".");
|
|
|
9
9
|
const clean = require("clean-stack");
|
|
10
10
|
const cli_1 = require("./errors/cli");
|
|
11
11
|
const handle = (err) => {
|
|
12
|
-
var _a, _b, _c;
|
|
13
12
|
try {
|
|
14
13
|
if (!err)
|
|
15
14
|
err = new cli_1.CLIError('no error?');
|
|
@@ -21,7 +20,7 @@ const handle = (err) => {
|
|
|
21
20
|
if (shouldPrint) {
|
|
22
21
|
console.error(pretty ? pretty : stack);
|
|
23
22
|
}
|
|
24
|
-
const exitCode =
|
|
23
|
+
const exitCode = err.oclif?.exit !== undefined && err.oclif?.exit !== false ? err.oclif?.exit : 1;
|
|
25
24
|
if (config_1.config.errorLogger && err.code !== 'EEXIT') {
|
|
26
25
|
if (stack) {
|
|
27
26
|
config_1.config.errorLogger.log(stack);
|
package/lib/errors/index.js
CHANGED
|
@@ -23,7 +23,6 @@ function exit(code = 0) {
|
|
|
23
23
|
}
|
|
24
24
|
exports.exit = exit;
|
|
25
25
|
function error(input, options = {}) {
|
|
26
|
-
var _a;
|
|
27
26
|
let err;
|
|
28
27
|
if (typeof input === 'string') {
|
|
29
28
|
err = new cli_2.CLIError(input, options);
|
|
@@ -39,14 +38,13 @@ function error(input, options = {}) {
|
|
|
39
38
|
const message = (0, pretty_print_1.default)(err);
|
|
40
39
|
console.error(message);
|
|
41
40
|
if (config_2.config.errorLogger)
|
|
42
|
-
config_2.config.errorLogger.log(
|
|
41
|
+
config_2.config.errorLogger.log(err?.stack ?? '');
|
|
43
42
|
}
|
|
44
43
|
else
|
|
45
44
|
throw err;
|
|
46
45
|
}
|
|
47
46
|
exports.error = error;
|
|
48
47
|
function warn(input) {
|
|
49
|
-
var _a;
|
|
50
48
|
let err;
|
|
51
49
|
if (typeof input === 'string') {
|
|
52
50
|
err = new cli_2.CLIError.Warn(input);
|
|
@@ -60,6 +58,6 @@ function warn(input) {
|
|
|
60
58
|
const message = (0, pretty_print_1.default)(err);
|
|
61
59
|
console.error(message);
|
|
62
60
|
if (config_2.config.errorLogger)
|
|
63
|
-
config_2.config.errorLogger.log(
|
|
61
|
+
config_2.config.errorLogger.log(err?.stack ?? '');
|
|
64
62
|
}
|
|
65
63
|
exports.warn = warn;
|
package/lib/help/docopts.js
CHANGED
|
@@ -73,10 +73,9 @@ class DocOpts {
|
|
|
73
73
|
return new DocOpts(cmd).toString();
|
|
74
74
|
}
|
|
75
75
|
toString() {
|
|
76
|
-
var _a;
|
|
77
76
|
const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
|
|
78
77
|
if (this.cmd.args) {
|
|
79
|
-
const a =
|
|
78
|
+
const a = this.cmd.args?.map(arg => `[${arg.name.toUpperCase()}]`) || [];
|
|
80
79
|
opts.push(...a);
|
|
81
80
|
}
|
|
82
81
|
try {
|
|
@@ -119,13 +118,12 @@ class DocOpts {
|
|
|
119
118
|
return elementMap;
|
|
120
119
|
}
|
|
121
120
|
combineElementsToFlag(elementMap, flagName, flagNames, unionString) {
|
|
122
|
-
var _a;
|
|
123
121
|
if (!this.flagMap[flagName]) {
|
|
124
122
|
return;
|
|
125
123
|
}
|
|
126
|
-
let isRequired =
|
|
124
|
+
let isRequired = this.flagMap[flagName]?.required;
|
|
127
125
|
if (typeof isRequired !== 'boolean' || !isRequired) {
|
|
128
|
-
isRequired = flagNames.reduce((required, toCombine) =>
|
|
126
|
+
isRequired = flagNames.reduce((required, toCombine) => required || this.flagMap[toCombine]?.required || false, false);
|
|
129
127
|
}
|
|
130
128
|
for (const toCombine of flagNames) {
|
|
131
129
|
elementMap[flagName] = `${elementMap[flagName] || ''}${unionString}${elementMap[toCombine] || ''}`;
|
package/lib/help/index.js
CHANGED
|
@@ -112,13 +112,12 @@ class Help extends HelpBase {
|
|
|
112
112
|
(0, errors_1.error)(`Command ${subject} not found.`);
|
|
113
113
|
}
|
|
114
114
|
async showCommandHelp(command) {
|
|
115
|
-
var _a, _b, _c, _d;
|
|
116
115
|
const name = command.id;
|
|
117
116
|
const depth = name.split(':').length;
|
|
118
117
|
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
119
118
|
const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
|
|
120
119
|
const plugin = this.config.plugins.find(p => p.name === command.pluginName);
|
|
121
|
-
const state =
|
|
120
|
+
const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
|
|
122
121
|
if (state)
|
|
123
122
|
this.log(`This command is in ${state}.\n`);
|
|
124
123
|
const summary = this.summary(command);
|
|
@@ -137,10 +136,9 @@ class Help extends HelpBase {
|
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
138
|
async showRootHelp() {
|
|
140
|
-
var _a, _b;
|
|
141
139
|
let rootTopics = this.sortedTopics;
|
|
142
140
|
let rootCommands = this.sortedCommands;
|
|
143
|
-
const state =
|
|
141
|
+
const state = this.config.pjson?.oclif?.state;
|
|
144
142
|
if (state)
|
|
145
143
|
this.log(`${this.config.bin} is in ${state}.\n`);
|
|
146
144
|
this.log(this.formatRoot());
|
|
@@ -160,12 +158,11 @@ class Help extends HelpBase {
|
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
160
|
async showTopicHelp(topic) {
|
|
163
|
-
var _a, _b;
|
|
164
161
|
const name = topic.name;
|
|
165
162
|
const depth = name.split(':').length;
|
|
166
163
|
const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
|
|
167
164
|
const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
|
|
168
|
-
const state =
|
|
165
|
+
const state = this.config.pjson?.oclif?.state;
|
|
169
166
|
if (state)
|
|
170
167
|
this.log(`This topic is in ${state}.\n`);
|
|
171
168
|
this.log(this.formatTopic(topic));
|
package/lib/help/util.js
CHANGED
|
@@ -41,12 +41,11 @@ function collateSpacedCmdIDFromArgs(argv, config) {
|
|
|
41
41
|
const isArgWithValue = (s) => s.includes('=');
|
|
42
42
|
const finalizeId = (s) => s ? [...final, s].join(':') : final.join(':');
|
|
43
43
|
const hasArgs = () => {
|
|
44
|
-
var _a;
|
|
45
44
|
const id = finalizeId();
|
|
46
45
|
if (!id)
|
|
47
46
|
return false;
|
|
48
47
|
const cmd = config.findCommand(id);
|
|
49
|
-
return Boolean(cmd && (cmd.strict === false ||
|
|
48
|
+
return Boolean(cmd && (cmd.strict === false || cmd.args?.length > 0));
|
|
50
49
|
};
|
|
51
50
|
for (const arg of argv) {
|
|
52
51
|
if (idPresent(finalizeId(arg)))
|
|
@@ -87,9 +86,8 @@ function standardizeIDFromArgv(argv, config) {
|
|
|
87
86
|
}
|
|
88
87
|
exports.standardizeIDFromArgv = standardizeIDFromArgv;
|
|
89
88
|
function getHelpFlagAdditions(config) {
|
|
90
|
-
var _a;
|
|
91
89
|
const helpFlags = ['--help'];
|
|
92
|
-
const additionalHelpFlags =
|
|
90
|
+
const additionalHelpFlags = config.pjson.oclif.additionalHelpFlags ?? [];
|
|
93
91
|
return [...new Set([...helpFlags, ...additionalHelpFlags]).values()];
|
|
94
92
|
}
|
|
95
93
|
exports.getHelpFlagAdditions = getHelpFlagAdditions;
|
|
@@ -37,7 +37,7 @@ export declare type ArgInput = Arg<any>[];
|
|
|
37
37
|
export interface CLIParseErrorOptions {
|
|
38
38
|
parse: {
|
|
39
39
|
input?: ParserInput;
|
|
40
|
-
output?: ParserOutput
|
|
40
|
+
output?: ParserOutput;
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
export declare type OutputArgs = {
|
|
@@ -46,8 +46,8 @@ export declare type OutputArgs = {
|
|
|
46
46
|
export declare type OutputFlags<T extends ParserInput['flags']> = {
|
|
47
47
|
[P in keyof T]: any;
|
|
48
48
|
};
|
|
49
|
-
export declare type ParserOutput<TFlags extends OutputFlags<any
|
|
50
|
-
flags: TFlags & {
|
|
49
|
+
export declare type ParserOutput<TFlags extends OutputFlags<any> = any, GFlags extends OutputFlags<any> = any, TArgs extends OutputArgs = any> = {
|
|
50
|
+
flags: TFlags & GFlags & {
|
|
51
51
|
json: boolean | undefined;
|
|
52
52
|
};
|
|
53
53
|
args: TArgs;
|
|
@@ -158,9 +158,9 @@ export declare type EnumFlagOptions<T> = Partial<OptionFlag<T>> & {
|
|
|
158
158
|
options: T[];
|
|
159
159
|
};
|
|
160
160
|
export declare type Flag<T> = BooleanFlag<T> | OptionFlag<T>;
|
|
161
|
-
export declare type Input<TFlags extends FlagOutput> = {
|
|
161
|
+
export declare type Input<TFlags extends FlagOutput, GFlags extends FlagOutput> = {
|
|
162
162
|
flags?: FlagInput<TFlags>;
|
|
163
|
-
globalFlags?: FlagInput<
|
|
163
|
+
globalFlags?: FlagInput<GFlags>;
|
|
164
164
|
args?: ArgInput;
|
|
165
165
|
strict?: boolean;
|
|
166
166
|
context?: any;
|
|
@@ -194,7 +194,9 @@ export declare type CompletableOptionFlag<T> = OptionFlag<T> & {
|
|
|
194
194
|
completion?: Completion;
|
|
195
195
|
};
|
|
196
196
|
export declare type CompletableFlag<T> = BooleanFlag<T> | CompletableOptionFlag<T>;
|
|
197
|
-
export declare type FlagInput<T extends FlagOutput
|
|
197
|
+
export declare type FlagInput<T extends FlagOutput = {
|
|
198
|
+
[flag: string]: unknown;
|
|
199
|
+
}> = {
|
|
198
200
|
[P in keyof T]: CompletableFlag<T[P]>;
|
|
199
201
|
};
|
|
200
202
|
export {};
|
package/lib/main.js
CHANGED
|
@@ -25,8 +25,7 @@ const helpAddition = (argv, config) => {
|
|
|
25
25
|
};
|
|
26
26
|
exports.helpAddition = helpAddition;
|
|
27
27
|
const versionAddition = (argv, config) => {
|
|
28
|
-
|
|
29
|
-
const additionalVersionFlags = (_a = config === null || config === void 0 ? void 0 : config.pjson.oclif.additionalVersionFlags) !== null && _a !== void 0 ? _a : [];
|
|
28
|
+
const additionalVersionFlags = config?.pjson.oclif.additionalVersionFlags ?? [];
|
|
30
29
|
const mergedVersionFlags = [...new Set(['--version', ...additionalVersionFlags]).values()];
|
|
31
30
|
if (mergedVersionFlags.includes(argv[0]))
|
|
32
31
|
return true;
|
|
@@ -35,14 +34,13 @@ const versionAddition = (argv, config) => {
|
|
|
35
34
|
exports.versionAddition = versionAddition;
|
|
36
35
|
// eslint-disable-next-line default-param-last
|
|
37
36
|
async function run(argv = process.argv.slice(2), options) {
|
|
38
|
-
var _a;
|
|
39
37
|
// Handle the case when a file URL string or URL is passed in such as 'import.meta.url'; covert to file path.
|
|
40
38
|
if (options && ((typeof options === 'string' && options.startsWith('file://')) || options instanceof url_2.URL)) {
|
|
41
39
|
options = (0, url_1.fileURLToPath)(options);
|
|
42
40
|
}
|
|
43
41
|
// return Main.run(argv, options)
|
|
44
42
|
const config = await config_1.Config.load(options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname);
|
|
45
|
-
if (config.topicSeparator !== ':' && !
|
|
43
|
+
if (config.topicSeparator !== ':' && !argv[0]?.includes(':'))
|
|
46
44
|
argv = (0, help_1.standardizeIDFromArgv)(argv, config);
|
|
47
45
|
let [id, ...argvSlice] = argv;
|
|
48
46
|
// run init hook
|
package/lib/module-loader.js
CHANGED
|
@@ -121,7 +121,6 @@ class ModuleLoader {
|
|
|
121
121
|
* @returns {{isESM: boolean, filePath: string}} An object including file path and whether the module is ESM.
|
|
122
122
|
*/
|
|
123
123
|
static resolvePath(config, modulePath) {
|
|
124
|
-
var _a, _b;
|
|
125
124
|
let isESM;
|
|
126
125
|
let filePath;
|
|
127
126
|
try {
|
|
@@ -135,7 +134,7 @@ class ModuleLoader {
|
|
|
135
134
|
if (fs.existsSync(filePath)) {
|
|
136
135
|
fileExists = true;
|
|
137
136
|
try {
|
|
138
|
-
if (
|
|
137
|
+
if (fs.lstatSync(filePath)?.isDirectory?.()) {
|
|
139
138
|
fileExists = false;
|
|
140
139
|
isDirectory = true;
|
|
141
140
|
}
|
package/lib/parser/flags.d.ts
CHANGED
|
@@ -6,7 +6,10 @@ export declare function build<T>(defaults: {
|
|
|
6
6
|
} & Partial<OptionFlag<T>>): Definition<T>;
|
|
7
7
|
export declare function build(defaults: Partial<OptionFlag<string>>): Definition<string>;
|
|
8
8
|
export declare function boolean<T = boolean>(options?: Partial<BooleanFlag<T>>): BooleanFlag<T>;
|
|
9
|
-
export declare const integer:
|
|
9
|
+
export declare const integer: (opts?: {
|
|
10
|
+
min?: number;
|
|
11
|
+
max?: number;
|
|
12
|
+
} & Partial<OptionFlag<number>>) => OptionFlag<number | undefined>;
|
|
10
13
|
export declare const directory: (opts?: {
|
|
11
14
|
exists?: boolean;
|
|
12
15
|
} & Partial<OptionFlag<string>>) => OptionFlag<string | undefined>;
|
package/lib/parser/flags.js
CHANGED
|
@@ -26,13 +26,22 @@ function boolean(options = {}) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
exports.boolean = boolean;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const integer = (opts = {}) => {
|
|
30
|
+
return build({
|
|
31
|
+
...opts,
|
|
32
|
+
parse: async (input) => {
|
|
33
|
+
if (!/^-?\d+$/.test(input))
|
|
34
|
+
throw new Error(`Expected an integer but received: ${input}`);
|
|
35
|
+
const num = Number.parseInt(input, 10);
|
|
36
|
+
if (opts.min !== undefined && num < opts.min)
|
|
37
|
+
throw new Error(`Expected an integer greater than or equal to ${opts.min} but received: ${input}`);
|
|
38
|
+
if (opts.max !== undefined && num > opts.max)
|
|
39
|
+
throw new Error(`Expected an integer less than or equal to ${opts.max} but received: ${input}`);
|
|
40
|
+
return num;
|
|
41
|
+
},
|
|
42
|
+
})();
|
|
43
|
+
};
|
|
44
|
+
exports.integer = integer;
|
|
36
45
|
const directory = (opts = {}) => {
|
|
37
46
|
return build({
|
|
38
47
|
...opts,
|
package/lib/parser/index.d.ts
CHANGED
|
@@ -5,10 +5,13 @@ import { Input, ParserOutput } from '../interfaces';
|
|
|
5
5
|
export { args };
|
|
6
6
|
export { flags };
|
|
7
7
|
export { flagUsages } from './help';
|
|
8
|
-
export declare function parse<TFlags, TArgs extends {
|
|
8
|
+
export declare function parse<TFlags, GFlags, TArgs extends {
|
|
9
9
|
[name: string]: string;
|
|
10
|
-
}>(argv: string[], options: Input<TFlags>): Promise<ParserOutput<TFlags, TArgs>>;
|
|
11
|
-
declare const boolean: typeof flags.boolean, integer:
|
|
10
|
+
}>(argv: string[], options: Input<TFlags, GFlags>): Promise<ParserOutput<TFlags, GFlags, TArgs>>;
|
|
11
|
+
declare const boolean: typeof flags.boolean, integer: (opts?: {
|
|
12
|
+
min?: number | undefined;
|
|
13
|
+
max?: number | undefined;
|
|
14
|
+
} & Partial<import("../interfaces").OptionFlag<number>>) => import("../interfaces").OptionFlag<number | undefined>, url: import("../interfaces").Definition<import("url").URL>, directory: (opts?: {
|
|
12
15
|
exists?: boolean | undefined;
|
|
13
16
|
} & Partial<import("../interfaces").OptionFlag<string>>) => import("../interfaces").OptionFlag<string | undefined>, file: (opts?: {
|
|
14
17
|
exists?: boolean | undefined;
|
package/lib/parser/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// tslint:disable interface-over-type-literal
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.file = exports.directory = exports.url = exports.integer = exports.boolean = exports.parse = exports.flagUsages = exports.flags = exports.args = void 0;
|
|
5
4
|
const args = require("./args");
|
|
@@ -22,7 +21,7 @@ async function parse(argv, options) {
|
|
|
22
21
|
'--': options['--'],
|
|
23
22
|
flags: {
|
|
24
23
|
color: flags.defaultFlags.color,
|
|
25
|
-
...
|
|
24
|
+
...options.flags,
|
|
26
25
|
},
|
|
27
26
|
strict: options.strict !== false,
|
|
28
27
|
};
|
package/lib/parser/validate.d.ts
CHANGED
package/lib/parser/validate.js
CHANGED
|
@@ -30,7 +30,6 @@ function validate(parse) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
function validateAcrossFlags(flag) {
|
|
33
|
-
var _a;
|
|
34
33
|
const intersection = Object.entries(parse.input.flags)
|
|
35
34
|
.map(entry => entry[0]) // array of flag names
|
|
36
35
|
.filter(flagName => parse.output.flags[flagName] !== undefined) // with values
|
|
@@ -38,7 +37,7 @@ function validate(parse) {
|
|
|
38
37
|
if (intersection.length === 0) {
|
|
39
38
|
// the command's exactlyOne may or may not include itself, so we'll use Set to add + de-dupe
|
|
40
39
|
throw new errors_1.CLIError(`Exactly one of the following must be provided: ${[
|
|
41
|
-
...new Set(
|
|
40
|
+
...new Set(flag.exactlyOne?.map(flag => `--${flag}`)),
|
|
42
41
|
].join(', ')}`);
|
|
43
42
|
}
|
|
44
43
|
}
|
package/lib/util.js
CHANGED
|
@@ -40,8 +40,7 @@ function castArray(input) {
|
|
|
40
40
|
}
|
|
41
41
|
exports.castArray = castArray;
|
|
42
42
|
function isProd() {
|
|
43
|
-
|
|
44
|
-
return !['development', 'test'].includes((_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : '');
|
|
43
|
+
return !['development', 'test'].includes(process.env.NODE_ENV ?? '');
|
|
45
44
|
}
|
|
46
45
|
exports.isProd = isProd;
|
|
47
46
|
function maxBy(arr, fn) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/core",
|
|
3
3
|
"description": "base library for oclif CLIs",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.13.2",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"typescript": "4.5.5"
|
|
78
78
|
},
|
|
79
79
|
"engines": {
|
|
80
|
-
"node": ">=
|
|
80
|
+
"node": ">=14.0.0"
|
|
81
81
|
},
|
|
82
82
|
"files": [
|
|
83
83
|
"/lib",
|