@visulima/cerebro 3.0.0-alpha.9 → 3.0.1
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 +593 -0
- package/LICENSE.md +1295 -3950
- package/README.md +182 -2
- package/dist/commands/completion-command.d.ts +6 -5
- package/dist/commands/completion-command.js +5 -203
- package/dist/commands/help-command.d.ts +10 -9
- package/dist/commands/help-command.js +1 -3
- package/dist/commands/readme-command.d.ts +6 -5
- package/dist/commands/readme-command.js +32 -330
- package/dist/commands/version-command.d.ts +4 -3
- package/dist/commands/version-command.js +1 -18
- package/dist/index.d.ts +516 -95
- package/dist/index.js +1 -7
- package/dist/logger/create-pail-logger.d.ts +770 -8
- package/dist/logger/create-pail-logger.js +1 -34
- package/dist/packem_chunks/has-new-version.js +1 -259
- package/dist/packem_shared/Cerebro-Czc4t-75.js +4 -0
- package/dist/packem_shared/VERBOSITY_DEBUG-XPultrIA.js +1 -0
- package/dist/packem_shared/VisulimaError-C90oeIMu.js +76 -0
- package/dist/packem_shared/VisulimaError-DTMgXonA-CzaryRgZ.js +1 -0
- package/dist/packem_shared/cerebro-error-BjBcYVRO.js +1 -0
- package/dist/packem_shared/command.d-DbhtfXF4.d.ts +639 -0
- package/dist/packem_shared/index-DvVGK4kr.js +29 -0
- package/dist/packem_shared/index.d-BL4NtVR3.d.ts +127 -0
- package/dist/packem_shared/lazyNamed-DMUm8mZe.js +1 -0
- package/dist/packem_shared/renderError-B3ePOoBG-BmZlyMcr.js +25 -0
- package/dist/packem_shared/runtime-process-Dmz0vCJy.js +1 -0
- package/dist/packem_shared/split-by-case-Dbpgd7rf.js +1 -0
- package/dist/plugins/error-handler-plugin.d.ts +21 -19
- package/dist/plugins/error-handler-plugin.js +1 -636
- package/dist/plugins/runtime-version-check-plugin.d.ts +22 -20
- package/dist/plugins/runtime-version-check-plugin.js +1 -77
- package/dist/plugins/update-notifier/update-notifier-plugin.d.ts +28 -8
- package/dist/plugins/update-notifier/update-notifier-plugin.js +1 -517
- package/dist/util/general/compile-cache.d.ts +41 -0
- package/dist/util/general/compile-cache.js +1 -0
- package/dist/util/general/heap-tuning.d.ts +18 -0
- package/dist/util/general/heap-tuning.js +1 -0
- package/package.json +53 -48
- package/dist/cli.d.ts +0 -203
- package/dist/constants.d.ts +0 -29
- package/dist/default-env.d.ts +0 -7
- package/dist/default-options.d.ts +0 -3
- package/dist/empty-toolbox.d.ts +0 -15
- package/dist/errors/cerebro-error.d.ts +0 -10
- package/dist/errors/command-not-found-error.d.ts +0 -9
- package/dist/errors/command-validation-error.d.ts +0 -10
- package/dist/errors/completion-error.d.ts +0 -9
- package/dist/errors/conflicting-options-error.d.ts +0 -10
- package/dist/errors/plugin-error.d.ts +0 -9
- package/dist/errors/update-notifier-error.d.ts +0 -7
- package/dist/packem_shared/Cerebro-C2mnCyQf.js +0 -3313
- package/dist/packem_shared/VERBOSITY_QUIET-Dp46zlLW.js +0 -10
- package/dist/packem_shared/VisulimaError-DA7QsCxH.js +0 -34
- package/dist/packem_shared/cerebro-error-GmJ3jN7Q.js +0 -16
- package/dist/packem_shared/help-command-BY7rQUvM.js +0 -249
- package/dist/packem_shared/index-C2-8b3A4.js +0 -259
- package/dist/packem_shared/runtime-process-B6ZplyWn.js +0 -187
- package/dist/plugin-manager.d.ts +0 -53
- package/dist/plugins/update-notifier/cache.d.ts +0 -11
- package/dist/plugins/update-notifier/get-distribution-version.d.ts +0 -2
- package/dist/plugins/update-notifier/has-new-version.d.ts +0 -14
- package/dist/types/cli.d.ts +0 -102
- package/dist/types/command-line-usage.d.ts +0 -37
- package/dist/types/command.d.ts +0 -136
- package/dist/types/option-types.d.ts +0 -83
- package/dist/types/options.d.ts +0 -4
- package/dist/types/plugin.d.ts +0 -53
- package/dist/types/toolbox.d.ts +0 -96
- package/dist/util/arg-processing/get-boolean-values.d.ts +0 -7
- package/dist/util/arg-processing/get-parameter-option.d.ts +0 -7
- package/dist/util/arg-processing/map-option-type-label.d.ts +0 -3
- package/dist/util/arg-processing/option-is-boolean.d.ts +0 -9
- package/dist/util/arg-processing/remove-boolean-values.d.ts +0 -9
- package/dist/util/command-line-commands.d.ts +0 -10
- package/dist/util/command-line-usage/get-terminal-width.d.ts +0 -7
- package/dist/util/command-line-usage/index.d.ts +0 -3
- package/dist/util/command-line-usage/section/base-section.d.ts +0 -8
- package/dist/util/command-line-usage/section/content-section.d.ts +0 -65
- package/dist/util/command-line-usage/section/option-list-section.d.ts +0 -44
- package/dist/util/command-processing/command-processor.d.ts +0 -37
- package/dist/util/command-processing/command-validation.d.ts +0 -17
- package/dist/util/command-processing/nested-command-parser.d.ts +0 -25
- package/dist/util/command-processing/option-processor.d.ts +0 -44
- package/dist/util/data-processing/list-missing-arguments.d.ts +0 -15
- package/dist/util/data-processing/merge-arguments.d.ts +0 -7
- package/dist/util/general/find-alternatives.d.ts +0 -8
- package/dist/util/general/hide-bin.d.ts +0 -2
- package/dist/util/general/parse-raw-command.d.ts +0 -7
- package/dist/util/general/register-exception-handler.d.ts +0 -9
- package/dist/util/general/runtime-process.d.ts +0 -65
- package/dist/util/general/semver-gt.d.ts +0 -2
- package/dist/util/general/validate-input.d.ts +0 -24
- package/dist/util/process-env-variables.d.ts +0 -9
- package/dist/util/security.d.ts +0 -58
- package/dist/util/text-processing/template-format.d.ts +0 -5
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const OUTPUT_NORMAL = 1;
|
|
2
|
-
const OUTPUT_RAW = 2;
|
|
3
|
-
const OUTPUT_PLAIN = 4;
|
|
4
|
-
const VERBOSITY_QUIET = 16;
|
|
5
|
-
const VERBOSITY_NORMAL = 32;
|
|
6
|
-
const VERBOSITY_VERBOSE = 64;
|
|
7
|
-
const VERBOSITY_DEBUG = 128;
|
|
8
|
-
const POSITIONALS_KEY = "positionals";
|
|
9
|
-
|
|
10
|
-
export { OUTPUT_NORMAL, OUTPUT_PLAIN, OUTPUT_RAW, POSITIONALS_KEY, VERBOSITY_DEBUG, VERBOSITY_NORMAL, VERBOSITY_QUIET, VERBOSITY_VERBOSE };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const isVisulimaError = (error) => error instanceof Error && error.type === "VisulimaError";
|
|
2
|
-
class VisulimaError extends Error {
|
|
3
|
-
loc;
|
|
4
|
-
title;
|
|
5
|
-
/**
|
|
6
|
-
* A message that explains to the user how they can fix the error.
|
|
7
|
-
*/
|
|
8
|
-
hint;
|
|
9
|
-
type = "VisulimaError";
|
|
10
|
-
constructor({ cause, hint, location, message, name, stack, title }) {
|
|
11
|
-
super(message, {
|
|
12
|
-
cause
|
|
13
|
-
});
|
|
14
|
-
this.title = title;
|
|
15
|
-
this.name = name;
|
|
16
|
-
this.stack = stack ?? this.stack;
|
|
17
|
-
this.loc = location;
|
|
18
|
-
this.hint = hint;
|
|
19
|
-
}
|
|
20
|
-
setLocation(location) {
|
|
21
|
-
this.loc = location;
|
|
22
|
-
}
|
|
23
|
-
setName(name) {
|
|
24
|
-
this.name = name;
|
|
25
|
-
}
|
|
26
|
-
setMessage(message) {
|
|
27
|
-
this.message = message;
|
|
28
|
-
}
|
|
29
|
-
setHint(hint) {
|
|
30
|
-
this.hint = hint;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { VisulimaError, isVisulimaError };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { VisulimaError } from './VisulimaError-DA7QsCxH.js';
|
|
2
|
-
|
|
3
|
-
class CerebroError extends VisulimaError {
|
|
4
|
-
code;
|
|
5
|
-
context;
|
|
6
|
-
constructor(message, code, context) {
|
|
7
|
-
super({
|
|
8
|
-
message,
|
|
9
|
-
name: "CerebroError"
|
|
10
|
-
});
|
|
11
|
-
this.code = code;
|
|
12
|
-
this.context = context;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { CerebroError as C };
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { inverse, cyan, green, yellow } from '@visulima/colorize';
|
|
2
|
-
import { t as templateFormat, c as commandLineUsage } from './index-C2-8b3A4.js';
|
|
3
|
-
|
|
4
|
-
const defaultEnv = [
|
|
5
|
-
{
|
|
6
|
-
defaultValue: "32",
|
|
7
|
-
description: "Controls the verbosity level of output. Valid values: '16' (quiet), '32' (normal), '64' (verbose), '128' (debug)",
|
|
8
|
-
name: "CEREBRO_OUTPUT_LEVEL",
|
|
9
|
-
type: String
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
description: "Sets the minimum required Node.js version. Overrides the default minimum version check",
|
|
13
|
-
name: "CEREBRO_MIN_NODE_VERSION",
|
|
14
|
-
type: Number
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
defaultValue: false,
|
|
18
|
-
description: "When set, disables the update notifier check",
|
|
19
|
-
name: "NO_UPDATE_NOTIFIER",
|
|
20
|
-
type: Boolean
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
description: "Standard Node.js environment variable. When set to 'test', disables update notifier",
|
|
24
|
-
name: "NODE_ENV",
|
|
25
|
-
type: String
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
defaultValue: false,
|
|
29
|
-
description: "When set, enables debug output (same as --debug flag)",
|
|
30
|
-
name: "DEBUG",
|
|
31
|
-
type: Boolean
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
description: "Sets the terminal width for table rendering. Useful for testing and consistent output",
|
|
35
|
-
name: "CEREBRO_TERMINAL_WIDTH",
|
|
36
|
-
type: Number
|
|
37
|
-
}
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
const defaultOptions = [
|
|
41
|
-
{
|
|
42
|
-
description: "Turn on verbose output",
|
|
43
|
-
group: "global",
|
|
44
|
-
name: "verbose",
|
|
45
|
-
type: Boolean
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
description: "Turn on debugging output",
|
|
49
|
-
group: "global",
|
|
50
|
-
name: "debug",
|
|
51
|
-
type: Boolean
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
alias: "h",
|
|
55
|
-
description: "Print out helpful usage information",
|
|
56
|
-
group: "global",
|
|
57
|
-
name: "help",
|
|
58
|
-
type: Boolean
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
alias: "q",
|
|
62
|
-
description: "Silence output",
|
|
63
|
-
group: "global",
|
|
64
|
-
name: "quiet",
|
|
65
|
-
type: Boolean
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
alias: "V",
|
|
69
|
-
description: "Print version info",
|
|
70
|
-
group: "global",
|
|
71
|
-
name: "version",
|
|
72
|
-
type: Boolean
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
description: "Turn off colored output",
|
|
76
|
-
group: "global",
|
|
77
|
-
name: "no-color",
|
|
78
|
-
type: Boolean
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
description: "Force colored output",
|
|
82
|
-
group: "global",
|
|
83
|
-
name: "color",
|
|
84
|
-
type: Boolean
|
|
85
|
-
}
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
const EMPTY_GROUP_KEY = "__Other";
|
|
89
|
-
const upperFirstChar = (string_) => string_.charAt(0).toUpperCase() + string_.slice(1);
|
|
90
|
-
const printGeneralHelp = (logger, runtime, commands, groupOption) => {
|
|
91
|
-
logger.debug("no command given, printing general help...");
|
|
92
|
-
let filteredCommands = [...new Set(commands.values())].filter((command) => !command.hidden);
|
|
93
|
-
if (groupOption) {
|
|
94
|
-
filteredCommands = filteredCommands.filter((command) => command.group === groupOption);
|
|
95
|
-
}
|
|
96
|
-
const groupedCommands = filteredCommands.reduce((accumulator, command) => {
|
|
97
|
-
const group = command.group ?? EMPTY_GROUP_KEY;
|
|
98
|
-
if (!accumulator[group]) {
|
|
99
|
-
accumulator[group] = [];
|
|
100
|
-
}
|
|
101
|
-
accumulator[group].push(command);
|
|
102
|
-
return accumulator;
|
|
103
|
-
}, {});
|
|
104
|
-
const buildCommandList = (commandList) => commandList.map((command) => {
|
|
105
|
-
let aliases = "";
|
|
106
|
-
if (typeof command.alias === "string") {
|
|
107
|
-
aliases = command.alias;
|
|
108
|
-
} else if (Array.isArray(command.alias)) {
|
|
109
|
-
aliases = command.alias.join(", ");
|
|
110
|
-
}
|
|
111
|
-
if (aliases !== "") {
|
|
112
|
-
aliases = ` [${aliases}]`;
|
|
113
|
-
}
|
|
114
|
-
let commandDisplay = command.name;
|
|
115
|
-
if (command.commandPath && command.commandPath.length > 0) {
|
|
116
|
-
commandDisplay = `${command.commandPath.join(" ")} ${command.name}`;
|
|
117
|
-
}
|
|
118
|
-
return [`${green(commandDisplay)}${aliases}`, command.description ?? ""];
|
|
119
|
-
});
|
|
120
|
-
(logger?.raw ?? logger.log)(
|
|
121
|
-
commandLineUsage(
|
|
122
|
-
[
|
|
123
|
-
{
|
|
124
|
-
content: `${cyan(runtime.getCliName())} ${green("<command>")} [positional arguments] ${yellow("[options]")}`,
|
|
125
|
-
header: inverse.cyan(" Usage ")
|
|
126
|
-
},
|
|
127
|
-
...Object.keys(groupedCommands).map((key) => {
|
|
128
|
-
const groupOptionName = groupOption ? ` ${upperFirstChar(groupOption)}` : "";
|
|
129
|
-
return {
|
|
130
|
-
content: buildCommandList(groupedCommands[key]),
|
|
131
|
-
header: key === EMPTY_GROUP_KEY || groupOption ? inverse.green(` Available${groupOptionName} Commands `) : ` ${inverse.green(` ${upperFirstChar(key)} `)}`
|
|
132
|
-
};
|
|
133
|
-
}),
|
|
134
|
-
commands.has("help") ? {
|
|
135
|
-
header: inverse.yellow(" Command Options "),
|
|
136
|
-
optionList: commands.get("help").options?.filter((option) => !option.hidden)
|
|
137
|
-
} : void 0,
|
|
138
|
-
{ header: inverse.yellow(" Global Options "), optionList: defaultOptions },
|
|
139
|
-
{
|
|
140
|
-
content: defaultEnv.filter((envVariable) => !envVariable.hidden).map((envVariable) => [envVariable.name, envVariable.description ?? ""]),
|
|
141
|
-
header: inverse.magenta(" Environment Variables ")
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
content: `Run "${cyan(runtime.getCliName())} ${green("help <command>")}" or "${cyan(runtime.getCliName())} ${green("<command>")} ${yellow("--help")}" for help with a specific command.`,
|
|
145
|
-
raw: true
|
|
146
|
-
}
|
|
147
|
-
].filter(Boolean)
|
|
148
|
-
)
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
const printCommandHelp = (logger, runtime, commands, name) => {
|
|
152
|
-
let command = commands.get(name);
|
|
153
|
-
if (!command) {
|
|
154
|
-
for (const cmd of commands.values()) {
|
|
155
|
-
const fullPath = cmd.commandPath ? [...cmd.commandPath, cmd.name] : [cmd.name];
|
|
156
|
-
if (fullPath[fullPath.length - 1] === name || fullPath.join(" ") === name) {
|
|
157
|
-
command = cmd;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (!command) {
|
|
163
|
-
logger.error(`Command "${name}" not found`);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const usageGroups = [];
|
|
167
|
-
const fullCommandPath = command.commandPath ? [...command.commandPath, command.name] : [command.name];
|
|
168
|
-
const commandDisplay = fullCommandPath.join(" ");
|
|
169
|
-
usageGroups.push({
|
|
170
|
-
content: `${cyan(runtime.getCliName())} ${green(commandDisplay)}${command.argument ? " [positional arguments]" : ""}${command.options ? " [options]" : ""}`,
|
|
171
|
-
header: inverse.cyan(" Usage ")
|
|
172
|
-
});
|
|
173
|
-
if (command.description) {
|
|
174
|
-
usageGroups.push({ content: command.description, header: inverse.green(" Description ") });
|
|
175
|
-
}
|
|
176
|
-
if (command.argument) {
|
|
177
|
-
usageGroups.push({ header: "Command Positional Arguments", isArgument: true, optionList: [command.argument] });
|
|
178
|
-
}
|
|
179
|
-
if (Array.isArray(command.options) && command.options.length > 0) {
|
|
180
|
-
usageGroups.push({
|
|
181
|
-
header: inverse.yellow(" Command Options "),
|
|
182
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
183
|
-
optionList: command.options.filter((option) => !option.hidden)
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
usageGroups.push({ header: inverse.yellow(" Global Options "), optionList: defaultOptions });
|
|
187
|
-
if (Array.isArray(command.env) && command.env.length > 0) {
|
|
188
|
-
const visibleEnvVariables = command.env.filter((envVariable) => !envVariable.hidden);
|
|
189
|
-
if (visibleEnvVariables.length > 0) {
|
|
190
|
-
usageGroups.push({
|
|
191
|
-
content: visibleEnvVariables.map((envVariable) => [envVariable.name, envVariable.description ?? ""]),
|
|
192
|
-
header: inverse.magenta(" Environment Variables ")
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (command.alias !== void 0 && command.alias.length > 0) {
|
|
197
|
-
let alias = command.alias;
|
|
198
|
-
if (typeof command.alias === "string") {
|
|
199
|
-
alias = [command.alias];
|
|
200
|
-
}
|
|
201
|
-
usageGroups.splice(1, 0, {
|
|
202
|
-
content: alias,
|
|
203
|
-
header: "Alias(es)"
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
if (Array.isArray(command.examples) && command.examples.length > 0) {
|
|
207
|
-
usageGroups.push({
|
|
208
|
-
content: command.examples,
|
|
209
|
-
header: "Examples"
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
(logger?.raw ?? logger.log)(commandLineUsage(usageGroups));
|
|
213
|
-
};
|
|
214
|
-
class HelpCommand {
|
|
215
|
-
name = "help";
|
|
216
|
-
options = [
|
|
217
|
-
{
|
|
218
|
-
description: "Display only the specified group",
|
|
219
|
-
name: "group",
|
|
220
|
-
type: String
|
|
221
|
-
}
|
|
222
|
-
];
|
|
223
|
-
commands;
|
|
224
|
-
constructor(commands) {
|
|
225
|
-
this.commands = commands;
|
|
226
|
-
}
|
|
227
|
-
execute(toolbox) {
|
|
228
|
-
const { commandName, logger, options, runtime } = toolbox;
|
|
229
|
-
const { footer, header } = runtime.getCommandSection();
|
|
230
|
-
if (header) {
|
|
231
|
-
(logger?.raw ?? logger.log)(templateFormat(header));
|
|
232
|
-
}
|
|
233
|
-
if (commandName === "help") {
|
|
234
|
-
printGeneralHelp(
|
|
235
|
-
logger,
|
|
236
|
-
runtime,
|
|
237
|
-
this.commands,
|
|
238
|
-
typeof options?.group === "string" ? options.group : void 0
|
|
239
|
-
);
|
|
240
|
-
} else {
|
|
241
|
-
printCommandHelp(logger, runtime, this.commands, commandName);
|
|
242
|
-
}
|
|
243
|
-
if (footer) {
|
|
244
|
-
(logger?.raw ?? logger.log)(templateFormat(footer));
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export { HelpCommand as H, defaultOptions as d };
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
-
|
|
7
|
-
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
-
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
-
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
-
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
-
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
-
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
-
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Fallback to createRequire
|
|
17
|
-
return __cjs_require(module);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
import { createTable } from '@visulima/tabular';
|
|
21
|
-
import { NO_BORDER } from '@visulima/tabular/style';
|
|
22
|
-
import colorizeTemplate from '@visulima/colorize/template';
|
|
23
|
-
import { d as getEnv } from './runtime-process-B6ZplyWn.js';
|
|
24
|
-
const os = __cjs_getBuiltinModule("node:os");
|
|
25
|
-
import { bold } from '@visulima/colorize';
|
|
26
|
-
|
|
27
|
-
const formatCache = /* @__PURE__ */ new Map();
|
|
28
|
-
const MAX_CACHE_SIZE = 500;
|
|
29
|
-
const templateFormat = (string_) => {
|
|
30
|
-
if (!string_) {
|
|
31
|
-
return "";
|
|
32
|
-
}
|
|
33
|
-
if (string_ === "") {
|
|
34
|
-
return "";
|
|
35
|
-
}
|
|
36
|
-
const cached = formatCache.get(string_);
|
|
37
|
-
if (cached !== void 0) {
|
|
38
|
-
return cached;
|
|
39
|
-
}
|
|
40
|
-
const result = colorizeTemplate(Object.assign([], { raw: [string_] }));
|
|
41
|
-
if (formatCache.size >= MAX_CACHE_SIZE) {
|
|
42
|
-
const firstKey = formatCache.keys().next().value;
|
|
43
|
-
if (firstKey !== void 0) {
|
|
44
|
-
formatCache.delete(firstKey);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
formatCache.set(string_, result);
|
|
48
|
-
return result;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const getTerminalWidth = () => {
|
|
52
|
-
const env = getEnv();
|
|
53
|
-
const terminalWidth = env.CEREBRO_TERMINAL_WIDTH;
|
|
54
|
-
if (terminalWidth === void 0) {
|
|
55
|
-
return void 0;
|
|
56
|
-
}
|
|
57
|
-
const parsed = Number.parseInt(terminalWidth, 10);
|
|
58
|
-
if (Number.isNaN(parsed) || parsed <= 0) {
|
|
59
|
-
return void 0;
|
|
60
|
-
}
|
|
61
|
-
return parsed;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
class BaseSection {
|
|
65
|
-
lines;
|
|
66
|
-
constructor() {
|
|
67
|
-
this.lines = [];
|
|
68
|
-
}
|
|
69
|
-
add(line) {
|
|
70
|
-
this.lines.push(line);
|
|
71
|
-
}
|
|
72
|
-
toString() {
|
|
73
|
-
return this.lines.join(os.EOL);
|
|
74
|
-
}
|
|
75
|
-
header(text) {
|
|
76
|
-
this.add(bold(text));
|
|
77
|
-
this.lines.push("");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
class ContentSection extends BaseSection {
|
|
82
|
-
constructor(section) {
|
|
83
|
-
super();
|
|
84
|
-
if (section.header) {
|
|
85
|
-
this.header(templateFormat(section.header));
|
|
86
|
-
}
|
|
87
|
-
if (section.content) {
|
|
88
|
-
if (section.raw) {
|
|
89
|
-
if (Array.isArray(section.content) && section.content.every((value) => typeof value === "string")) {
|
|
90
|
-
section.content.forEach((row) => {
|
|
91
|
-
if (Array.isArray(row)) {
|
|
92
|
-
row.forEach((cell) => this.add(templateFormat(cell)));
|
|
93
|
-
} else {
|
|
94
|
-
this.add(templateFormat(row));
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
} else if (typeof section.content === "string") {
|
|
98
|
-
this.add(templateFormat(section.content));
|
|
99
|
-
} else {
|
|
100
|
-
throw new TypeError("Invalid raw content, must be a string or array of strings.");
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
this.add(this.getContentLines(section.content));
|
|
104
|
-
}
|
|
105
|
-
this.add("");
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
// eslint-disable-next-line class-methods-use-this
|
|
109
|
-
getContentLines(content) {
|
|
110
|
-
if (typeof content === "string") {
|
|
111
|
-
const table = createTable({
|
|
112
|
-
showHeader: false,
|
|
113
|
-
style: {
|
|
114
|
-
border: NO_BORDER,
|
|
115
|
-
paddingLeft: 4,
|
|
116
|
-
paddingRight: 1
|
|
117
|
-
},
|
|
118
|
-
terminalWidth: getTerminalWidth(),
|
|
119
|
-
truncateOverflow: false,
|
|
120
|
-
wordWrap: true
|
|
121
|
-
});
|
|
122
|
-
table.addRow([templateFormat(content)]);
|
|
123
|
-
return table.toString();
|
|
124
|
-
}
|
|
125
|
-
if (Array.isArray(content) && content.every((value) => typeof value === "string" || Array.isArray(value) && value.every((value2) => typeof value2 === "string"))) {
|
|
126
|
-
const table = createTable({
|
|
127
|
-
showHeader: false,
|
|
128
|
-
style: {
|
|
129
|
-
border: NO_BORDER,
|
|
130
|
-
paddingLeft: 4,
|
|
131
|
-
paddingRight: 1
|
|
132
|
-
},
|
|
133
|
-
terminalWidth: getTerminalWidth(),
|
|
134
|
-
truncateOverflow: false,
|
|
135
|
-
wordWrap: true
|
|
136
|
-
});
|
|
137
|
-
content.forEach((row) => {
|
|
138
|
-
if (Array.isArray(row)) {
|
|
139
|
-
table.addRow(row.map((cell) => templateFormat(cell)));
|
|
140
|
-
} else {
|
|
141
|
-
table.addRow([templateFormat(row)]);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
return table.toString();
|
|
145
|
-
}
|
|
146
|
-
if (typeof content === "object") {
|
|
147
|
-
const contentObject = content;
|
|
148
|
-
if (!contentObject.options || !contentObject.data) {
|
|
149
|
-
throw new Error(`Must have an "options" or "data" property
|
|
150
|
-
${JSON.stringify(content)}`);
|
|
151
|
-
}
|
|
152
|
-
const table = createTable({
|
|
153
|
-
showHeader: false,
|
|
154
|
-
style: {
|
|
155
|
-
border: NO_BORDER,
|
|
156
|
-
paddingLeft: 4,
|
|
157
|
-
paddingRight: 1
|
|
158
|
-
},
|
|
159
|
-
terminalWidth: getTerminalWidth(),
|
|
160
|
-
truncateOverflow: false,
|
|
161
|
-
wordWrap: true
|
|
162
|
-
});
|
|
163
|
-
contentObject.data.forEach((row) => {
|
|
164
|
-
if (Array.isArray(row)) {
|
|
165
|
-
table.addRow(row.map((cell) => templateFormat(cell)));
|
|
166
|
-
} else {
|
|
167
|
-
table.addRow([templateFormat(row)]);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
return table.toString();
|
|
171
|
-
}
|
|
172
|
-
throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
|
|
173
|
-
|
|
174
|
-
${JSON.stringify(content)}`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
class OptionListSection extends BaseSection {
|
|
179
|
-
constructor(data) {
|
|
180
|
-
super();
|
|
181
|
-
let definitions = data.optionList ?? [];
|
|
182
|
-
const hide = Array.isArray(data.hide) ? data.hide : [data.hide].filter(Boolean);
|
|
183
|
-
const groups = Array.isArray(data.group) ? data.group : [data.group].filter(Boolean);
|
|
184
|
-
if (hide.length > 0) {
|
|
185
|
-
definitions = definitions.filter((definition) => !hide.includes(definition.name));
|
|
186
|
-
}
|
|
187
|
-
if (data.header) {
|
|
188
|
-
this.header(templateFormat(data.header));
|
|
189
|
-
}
|
|
190
|
-
if (groups.length > 0) {
|
|
191
|
-
definitions = definitions.filter((definition) => {
|
|
192
|
-
const noGroupMatch = groups.includes("_none") && !definition.group;
|
|
193
|
-
const groupMatch = this.intersect(Array.isArray(definition.group) ? definition.group : [definition.group], groups);
|
|
194
|
-
return noGroupMatch || groupMatch ? definition : void 0;
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
const table = createTable({
|
|
198
|
-
showHeader: false,
|
|
199
|
-
style: {
|
|
200
|
-
border: NO_BORDER,
|
|
201
|
-
paddingLeft: 2,
|
|
202
|
-
paddingRight: 1,
|
|
203
|
-
...data.tableOptions?.style
|
|
204
|
-
},
|
|
205
|
-
terminalWidth: getTerminalWidth() ?? data.tableOptions?.terminalWidth,
|
|
206
|
-
truncateOverflow: false,
|
|
207
|
-
wordWrap: data.tableOptions?.wordWrap ?? true,
|
|
208
|
-
...data.tableOptions
|
|
209
|
-
});
|
|
210
|
-
definitions.forEach(
|
|
211
|
-
(definition) => table.addRow([this.getOptionNames(definition, data.reverseNameOrder ?? false, data.isArgument ?? false), templateFormat(definition.description)])
|
|
212
|
-
);
|
|
213
|
-
this.add(table.toString());
|
|
214
|
-
this.lines.push("");
|
|
215
|
-
}
|
|
216
|
-
// eslint-disable-next-line class-methods-use-this,sonarjs/cognitive-complexity,@typescript-eslint/no-explicit-any
|
|
217
|
-
getOptionNames(definition, reverseNameOrder, isArgument) {
|
|
218
|
-
if (!definition.name) {
|
|
219
|
-
throw new TypeError("Invalid option definition, name is required.");
|
|
220
|
-
}
|
|
221
|
-
let type = definition.type ? definition.type.name.toLowerCase() : "string";
|
|
222
|
-
const multiple = definition.multiple || definition.lazyMultiple ? "[]" : "";
|
|
223
|
-
type = templateFormat(definition.typeLabel ?? `{underline ${type}${multiple}}`);
|
|
224
|
-
let result;
|
|
225
|
-
if (definition.alias) {
|
|
226
|
-
if (definition.name) {
|
|
227
|
-
const name = isArgument ? definition.name : `{yellow --${definition.name}}`;
|
|
228
|
-
result = reverseNameOrder ? templateFormat(`{bold ${name}}, {bold -${definition.alias}} ${type}`) : templateFormat(`{bold -${definition.alias}}, {bold ${name}} ${type}`);
|
|
229
|
-
} else if (reverseNameOrder) {
|
|
230
|
-
result = templateFormat(`{bold -${definition.alias}} ${type}`);
|
|
231
|
-
} else {
|
|
232
|
-
result = templateFormat(`{bold -${definition.alias}} ${type}`);
|
|
233
|
-
}
|
|
234
|
-
} else {
|
|
235
|
-
result = templateFormat(`{bold ${isArgument ? definition.name : `{yellow --${definition.name}}`}} ${type}`);
|
|
236
|
-
}
|
|
237
|
-
return result;
|
|
238
|
-
}
|
|
239
|
-
// eslint-disable-next-line class-methods-use-this
|
|
240
|
-
intersect(array1, array2) {
|
|
241
|
-
return array1.some((item1) => array2.includes(item1));
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const commandLineUsage = (sections) => {
|
|
246
|
-
const lines = Array.isArray(sections) ? sections : [sections];
|
|
247
|
-
if (lines.length === 0) {
|
|
248
|
-
return "";
|
|
249
|
-
}
|
|
250
|
-
return `
|
|
251
|
-
${sections.map((section) => {
|
|
252
|
-
if (section.optionList) {
|
|
253
|
-
return new OptionListSection(section).toString();
|
|
254
|
-
}
|
|
255
|
-
return new ContentSection(section).toString();
|
|
256
|
-
}).join("\n")}`;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
export { commandLineUsage as c, templateFormat as t };
|