@oclif/core 1.24.2 → 1.24.3
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/config/config.js +1 -4
- package/lib/help/command.js +1 -1
- package/lib/help/docopts.js +2 -1
- package/lib/util.d.ts +11 -0
- package/lib/util.js +12 -1
- package/package.json +1 -1
package/lib/config/config.js
CHANGED
|
@@ -677,10 +677,7 @@ async function toCached(c, plugin) {
|
|
|
677
677
|
}
|
|
678
678
|
}
|
|
679
679
|
}
|
|
680
|
-
|
|
681
|
-
// @ts-ignore
|
|
682
|
-
const normalized = Array.isArray(c.args) ? c.args ?? [] : Object.entries(c.args ?? {}).map(([name, arg]) => ({ ...arg, name }));
|
|
683
|
-
const argsPromise = normalized.map(async (a) => ({
|
|
680
|
+
const argsPromise = (0, util_3.ensureArgArray)(c.args).map(async (a) => ({
|
|
684
681
|
name: a.name,
|
|
685
682
|
description: a.description,
|
|
686
683
|
required: a.required,
|
package/lib/help/command.js
CHANGED
|
@@ -31,7 +31,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
31
31
|
v.name = k;
|
|
32
32
|
return v;
|
|
33
33
|
}), f => [!f.char, f.char, f.name]);
|
|
34
|
-
const args = (cmd.args
|
|
34
|
+
const args = (0, util_1.ensureArgArray)(cmd.args).filter(a => !a.hidden);
|
|
35
35
|
const output = (0, util_1.compact)(this.sections().map(({ header, generate }) => {
|
|
36
36
|
const body = generate({ cmd, flags, args }, header);
|
|
37
37
|
// Generate can return a list of sections
|
package/lib/help/docopts.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DocOpts = void 0;
|
|
4
|
+
const util_1 = require("../util");
|
|
4
5
|
/**
|
|
5
6
|
* DocOpts - See http://docopt.org/.
|
|
6
7
|
*
|
|
@@ -75,7 +76,7 @@ class DocOpts {
|
|
|
75
76
|
toString() {
|
|
76
77
|
const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
|
|
77
78
|
if (this.cmd.args) {
|
|
78
|
-
const a = this.cmd.args
|
|
79
|
+
const a = (0, util_1.ensureArgArray)(this.cmd.args).map(arg => `[${arg.name.toUpperCase()}]`) || [];
|
|
79
80
|
opts.push(...a);
|
|
80
81
|
}
|
|
81
82
|
try {
|
package/lib/util.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ArgInput } from './interfaces';
|
|
1
2
|
export declare function compact<T>(a: (T | undefined)[]): T[];
|
|
2
3
|
export declare function uniqBy<T>(arr: T[], fn: (cur: T) => any): T[];
|
|
3
4
|
type SortTypes = string | number | undefined | boolean;
|
|
@@ -7,4 +8,14 @@ export declare function isProd(): boolean;
|
|
|
7
8
|
export declare function maxBy<T>(arr: T[], fn: (i: T) => number): T | undefined;
|
|
8
9
|
export declare function sumBy<T>(arr: T[], fn: (i: T) => number): number;
|
|
9
10
|
export declare function capitalize(s: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Ensure that the args are in an array instead of an object. This is required to ensure
|
|
13
|
+
* forwards compatibility with the new arg format in v2.
|
|
14
|
+
*
|
|
15
|
+
* @param args The args to ensure are in an array
|
|
16
|
+
* @returns ArgInput
|
|
17
|
+
*/
|
|
18
|
+
export declare function ensureArgArray(args?: ArgInput | {
|
|
19
|
+
[name: string]: any;
|
|
20
|
+
}): ArgInput;
|
|
10
21
|
export {};
|
package/lib/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = void 0;
|
|
3
|
+
exports.ensureArgArray = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = void 0;
|
|
4
4
|
function compact(a) {
|
|
5
5
|
return a.filter((a) => Boolean(a));
|
|
6
6
|
}
|
|
@@ -62,3 +62,14 @@ function capitalize(s) {
|
|
|
62
62
|
return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : '';
|
|
63
63
|
}
|
|
64
64
|
exports.capitalize = capitalize;
|
|
65
|
+
/**
|
|
66
|
+
* Ensure that the args are in an array instead of an object. This is required to ensure
|
|
67
|
+
* forwards compatibility with the new arg format in v2.
|
|
68
|
+
*
|
|
69
|
+
* @param args The args to ensure are in an array
|
|
70
|
+
* @returns ArgInput
|
|
71
|
+
*/
|
|
72
|
+
function ensureArgArray(args) {
|
|
73
|
+
return Array.isArray(args) ? args ?? [] : Object.entries(args ?? {}).map(([name, arg]) => ({ ...arg, name }));
|
|
74
|
+
}
|
|
75
|
+
exports.ensureArgArray = ensureArgArray;
|