@oclif/core 2.0.2-beta.6 → 2.0.2-beta.7
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 -5
- package/lib/help/command.js +1 -1
- package/lib/help/docopts.js +2 -1
- package/lib/util.d.ts +12 -0
- package/lib/util.js +14 -1
- package/package.json +1 -1
package/lib/config/config.js
CHANGED
|
@@ -698,12 +698,8 @@ async function toCached(c, plugin) {
|
|
|
698
698
|
}
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
|
-
// v1 commands have args as an array, so we need to normalize it to an object for backwards compatibility
|
|
702
|
-
const normalized = (Array.isArray(c.args) ? (c.args ?? []).reduce((x, y) => {
|
|
703
|
-
return { ...x, [y.name]: y };
|
|
704
|
-
}, {}) : c.args ?? {});
|
|
705
701
|
const args = {};
|
|
706
|
-
for (const [name, arg] of Object.entries(
|
|
702
|
+
for (const [name, arg] of Object.entries((0, util_3.ensureArgObject)(c.args))) {
|
|
707
703
|
args[name] = {
|
|
708
704
|
name,
|
|
709
705
|
description: arg.description,
|
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 = Object.values(cmd.args
|
|
34
|
+
const args = Object.values((0, util_1.ensureArgObject)(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 = Object.values(this.cmd.args
|
|
79
|
+
const a = Object.values((0, util_1.ensureArgObject)(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,5 @@
|
|
|
1
|
+
import { Command } from './command';
|
|
2
|
+
import { ArgInput } from './interfaces/parser';
|
|
1
3
|
export declare function pickBy<T extends {
|
|
2
4
|
[s: string]: T[keyof T];
|
|
3
5
|
} | ArrayLike<T[keyof T]>>(obj: T, fn: (i: T[keyof T]) => boolean): Partial<T>;
|
|
@@ -15,4 +17,14 @@ export declare const fileExists: (input: string) => Promise<string>;
|
|
|
15
17
|
export declare function isTruthy(input: string): boolean;
|
|
16
18
|
export declare function isNotFalsy(input: string): boolean;
|
|
17
19
|
export declare function requireJson<T>(...pathParts: string[]): T;
|
|
20
|
+
/**
|
|
21
|
+
* Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which
|
|
22
|
+
* defined args as an array.
|
|
23
|
+
*
|
|
24
|
+
* @param args Either an array of args or an object of args
|
|
25
|
+
* @returns ArgInput
|
|
26
|
+
*/
|
|
27
|
+
export declare function ensureArgObject(args?: any[] | ArgInput | {
|
|
28
|
+
[name: string]: Command.Arg.Cached;
|
|
29
|
+
}): ArgInput;
|
|
18
30
|
export {};
|
package/lib/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireJson = exports.isNotFalsy = exports.isTruthy = exports.fileExists = exports.dirExists = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = exports.pickBy = void 0;
|
|
3
|
+
exports.ensureArgObject = exports.requireJson = exports.isNotFalsy = exports.isTruthy = exports.fileExists = exports.dirExists = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = exports.pickBy = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
function pickBy(obj, fn) {
|
|
@@ -105,3 +105,16 @@ function requireJson(...pathParts) {
|
|
|
105
105
|
return JSON.parse(fs.readFileSync((0, path_1.join)(...pathParts), 'utf8'));
|
|
106
106
|
}
|
|
107
107
|
exports.requireJson = requireJson;
|
|
108
|
+
/**
|
|
109
|
+
* Ensure that the provided args are an object. This is for backwards compatibility with v1 commands which
|
|
110
|
+
* defined args as an array.
|
|
111
|
+
*
|
|
112
|
+
* @param args Either an array of args or an object of args
|
|
113
|
+
* @returns ArgInput
|
|
114
|
+
*/
|
|
115
|
+
function ensureArgObject(args) {
|
|
116
|
+
return (Array.isArray(args) ? (args ?? []).reduce((x, y) => {
|
|
117
|
+
return { ...x, [y.name]: y };
|
|
118
|
+
}, {}) : args ?? {});
|
|
119
|
+
}
|
|
120
|
+
exports.ensureArgObject = ensureArgObject;
|