@oclif/core 4.0.26 → 4.0.28
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/help/command.js
CHANGED
|
@@ -169,7 +169,8 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
169
169
|
if (noChar)
|
|
170
170
|
left = left.replace(' ', '');
|
|
171
171
|
let right = flag.summary || flag.description || '';
|
|
172
|
-
|
|
172
|
+
const canBeCached = !(this.opts.respectNoCacheDefault === true && flag.noCacheDefault === true);
|
|
173
|
+
if (flag.type === 'option' && flag.default && canBeCached) {
|
|
173
174
|
right = `${(0, theme_1.colorize)(this.config?.theme?.flagDefaultValue, `[default: ${flag.default}]`)} ${right}`;
|
|
174
175
|
}
|
|
175
176
|
if (flag.required)
|
package/lib/interfaces/help.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export interface HelpOptions {
|
|
|
24
24
|
*/
|
|
25
25
|
hideCommandSummaryInDescription?: boolean;
|
|
26
26
|
maxWidth: number;
|
|
27
|
+
/**
|
|
28
|
+
* Respect the `noCacheDefault` property on flags. Defaults to false.
|
|
29
|
+
*/
|
|
30
|
+
respectNoCacheDefault?: boolean;
|
|
27
31
|
/**
|
|
28
32
|
* Only show the help for the specified sections. Defaults to all sections.
|
|
29
33
|
*/
|
|
@@ -2,6 +2,7 @@ type Options = {
|
|
|
2
2
|
pretty?: boolean | undefined;
|
|
3
3
|
theme?: Record<string, string> | undefined;
|
|
4
4
|
};
|
|
5
|
+
export declare function removeCycles(object: unknown): unknown;
|
|
5
6
|
export declare function tokenize(json?: unknown, options?: Options): {
|
|
6
7
|
type: string;
|
|
7
8
|
value: string;
|
package/lib/ux/colorize-json.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeCycles = removeCycles;
|
|
3
4
|
exports.tokenize = tokenize;
|
|
4
5
|
exports.default = colorizeJson;
|
|
5
6
|
const theme_1 = require("./theme");
|
|
@@ -15,6 +16,37 @@ const tokenTypes = [
|
|
|
15
16
|
{ regex: /^true|^false/, tokenType: 'boolean' },
|
|
16
17
|
{ regex: /^null/, tokenType: 'null' },
|
|
17
18
|
];
|
|
19
|
+
function removeCycles(object) {
|
|
20
|
+
// Keep track of seen objects.
|
|
21
|
+
const seenObjects = new WeakMap();
|
|
22
|
+
const _removeCycles = (obj) => {
|
|
23
|
+
// Use object prototype to get around type and null checks
|
|
24
|
+
if (Object.prototype.toString.call(obj) === '[object Object]') {
|
|
25
|
+
// We know it is a "Record<string, unknown>" because of the conditional
|
|
26
|
+
const dictionary = obj;
|
|
27
|
+
// Seen, return undefined to remove.
|
|
28
|
+
if (seenObjects.has(dictionary))
|
|
29
|
+
return;
|
|
30
|
+
seenObjects.set(dictionary, undefined);
|
|
31
|
+
for (const key in dictionary) {
|
|
32
|
+
// Delete the duplicate object if cycle found.
|
|
33
|
+
if (_removeCycles(dictionary[key]) === undefined) {
|
|
34
|
+
delete dictionary[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (Array.isArray(obj)) {
|
|
39
|
+
for (const i in obj) {
|
|
40
|
+
if (_removeCycles(obj[i]) === undefined) {
|
|
41
|
+
// We don't want to delete the array, but we can replace the element with null.
|
|
42
|
+
obj[i] = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return obj;
|
|
47
|
+
};
|
|
48
|
+
return _removeCycles(object);
|
|
49
|
+
}
|
|
18
50
|
function formatInput(json, options) {
|
|
19
51
|
return options?.pretty
|
|
20
52
|
? JSON.stringify(typeof json === 'string' ? JSON.parse(json) : json, null, 2)
|
|
@@ -23,7 +55,7 @@ function formatInput(json, options) {
|
|
|
23
55
|
: JSON.stringify(json);
|
|
24
56
|
}
|
|
25
57
|
function tokenize(json, options) {
|
|
26
|
-
let input = formatInput(json, options);
|
|
58
|
+
let input = formatInput(removeCycles(json), options);
|
|
27
59
|
const tokens = [];
|
|
28
60
|
let foundToken = false;
|
|
29
61
|
do {
|