@twin.org/cli-core 0.0.3-next.44 → 0.0.3-next.46
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/dist/es/cliDisplay.js
CHANGED
|
@@ -45,15 +45,35 @@ export class CLIDisplay {
|
|
|
45
45
|
* Display an error message.
|
|
46
46
|
* @param error The error to display.
|
|
47
47
|
* @param lineBreaks Whether to add a line break after the error.
|
|
48
|
+
* @param options Options for formatting the error.
|
|
49
|
+
* @param options.includeStack Whether to include the stack trace in the output, defaults to false.
|
|
50
|
+
* @param options.includeAdditional Whether to include additional error information in the output, defaults to false.
|
|
48
51
|
*/
|
|
49
|
-
static error(error, lineBreaks = true) {
|
|
52
|
+
static error(error, lineBreaks = true, options = {}) {
|
|
50
53
|
CLIDisplay.writeError("❗ ");
|
|
51
54
|
CLIDisplay.writeError(chalk.red(I18n.formatMessage("cli.progress.error")));
|
|
52
55
|
if (lineBreaks) {
|
|
53
56
|
CLIDisplay.writeError("\n");
|
|
54
57
|
}
|
|
55
|
-
const formatted = ErrorHelper.
|
|
56
|
-
CLIDisplay.writeError(chalk.red(formatted.map(e => `\t${e}`).join("\n")));
|
|
58
|
+
const formatted = ErrorHelper.localizeErrors(error);
|
|
59
|
+
CLIDisplay.writeError(chalk.red(formatted.map(e => `\t${e.message}`).join("\n")));
|
|
60
|
+
if (options.includeAdditional) {
|
|
61
|
+
for (const err of formatted) {
|
|
62
|
+
if (Is.arrayValue(err.additional)) {
|
|
63
|
+
CLIDisplay.writeError(chalk.red(`\n\t\t${err.additional.join("\n\t\t")}\n`));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (options.includeStack) {
|
|
68
|
+
CLIDisplay.writeError("\n");
|
|
69
|
+
CLIDisplay.writeError("\n-----DEBUG STACK START-----\n\n");
|
|
70
|
+
for (const err of formatted) {
|
|
71
|
+
if (Is.stringValue(err.stack)) {
|
|
72
|
+
CLIDisplay.writeError(`${err.stack}\n`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
CLIDisplay.writeError("\n-----DEBUG STACK END-----\n");
|
|
76
|
+
}
|
|
57
77
|
if (lineBreaks) {
|
|
58
78
|
CLIDisplay.writeError("\n");
|
|
59
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cliDisplay.js","sourceRoot":"","sources":["../../src/cliDisplay.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;GAEG;AACH,MAAM,OAAO,UAAU;IACtB;;;OAGG;IACK,MAAM,CAAC,kBAAkB,CAAsC;IAEvE;;;OAGG;IACI,MAAM,CAAC,KAAK,GAA0C,MAAM,CAAC,EAAE,CACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAE9B;;;OAGG;IACI,MAAM,CAAC,UAAU,GAA0C,MAAM,CAAC,EAAE,CAC1E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAE9B;;OAEG;IACI,MAAM,CAAC,SAAS,GAAe,GAAG,EAAE;QAC1C,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC7B,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAa,EAAE,OAAe,EAAE,IAAY;QAChE,MAAM,YAAY,GAAG,GAAG,KAAK,KAAK,OAAO,EAAE,CAAC;QAC5C,UAAU,CAAC,KAA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IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CACpG,CAAC;QACH,CAAC,EAAE,QAAQ,CAAC,CAAC;IACd,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,WAAW;QACxB,IAAI,UAAU,CAAC,kBAAkB,EAAE,CAAC;YACnC,aAAa,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;YAC7C,UAAU,CAAC,kBAAkB,GAAG,SAAS,CAAC;QAC3C,CAAC;QACD,UAAU,CAAC,SAAS,EAAE,CAAC;IACxB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { clearLine, cursorTo } from \"node:readline\";\nimport { inspect } from \"node:util\";\nimport { Coerce, ErrorHelper, I18n, Is } from \"@twin.org/core\";\nimport chalk from \"chalk\";\n\n/**\n * Display utilities for the CLI.\n */\nexport class CLIDisplay {\n\t/**\n\t * The interval ID for the spinner.\n\t * @internal\n\t */\n\tprivate static _spinnerIntervalId: NodeJS.Timeout | number | undefined;\n\n\t/**\n\t * The default output method for writing standard messages.\n\t * @param buffer The message to output.\n\t */\n\tpublic static write: (buffer: string | Uint8Array) => void = buffer =>\n\t\tprocess.stdout.write(buffer);\n\n\t/**\n\t * The default output method for writing error messages.\n\t * @param buffer The message to output.\n\t */\n\tpublic static writeError: (buffer: string | Uint8Array) => void = buffer =>\n\t\tprocess.stderr.write(buffer);\n\n\t/**\n\t * The default output method for clearing the current line.\n\t */\n\tpublic static clearLine: () => void = () => {\n\t\tclearLine(process.stdout, 0);\n\t\tcursorTo(process.stdout, 0);\n\t};\n\n\t/**\n\t * Display the header for the CLI.\n\t * @param title The title of the CLI.\n\t * @param version The version of the CLI.\n\t * @param icon The icon for the CLI.\n\t */\n\tpublic static header(title: string, version: string, icon: string): void {\n\t\tconst titleVersion = `${title} v${version}`;\n\t\tCLIDisplay.write(`${icon} ${chalk.underline.bold.blue(titleVersion)}\\n`);\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display an error message.\n\t * @param error The error to display.\n\t * @param lineBreaks Whether to add a line break after the error.\n\t */\n\tpublic static error(error: unknown, lineBreaks: boolean = true): void {\n\t\tCLIDisplay.writeError(\"❗ \");\n\t\tCLIDisplay.writeError(chalk.red(I18n.formatMessage(\"cli.progress.error\")));\n\t\tif (lineBreaks) {\n\t\t\tCLIDisplay.writeError(\"\\n\");\n\t\t}\n\n\t\tconst formatted = ErrorHelper.formatErrors(error, true);\n\t\tCLIDisplay.writeError(chalk.red(formatted.map(e => `\\t${e}`).join(\"\\n\")));\n\t\tif (lineBreaks) {\n\t\t\tCLIDisplay.writeError(\"\\n\");\n\t\t}\n\t}\n\n\t/**\n\t * Display an error message in simple form.\n\t * @param error The error to display.\n\t */\n\tpublic static errorMessage(error: string): void {\n\t\tCLIDisplay.writeError(\"❗ \");\n\t\tCLIDisplay.writeError(chalk.red(error));\n\t\tCLIDisplay.writeError(\"\\n\");\n\t}\n\n\t/**\n\t * Display a section.\n\t * @param label The label for the section.\n\t */\n\tpublic static section(label: string): void {\n\t\tCLIDisplay.write(chalk.hex(\"#FFA500\").bold.underline(label));\n\t\tCLIDisplay.write(\"\\n\\n\");\n\t}\n\n\t/**\n\t * Display a value with a label.\n\t * @param label The label for the value.\n\t * @param value The value to display.\n\t * @param indentLevel The level of indentation.\n\t */\n\tpublic static value(label: string, value: unknown, indentLevel: number = 0): void {\n\t\tCLIDisplay.write(\"\\t\".repeat(indentLevel));\n\t\tif (Is.stringValue(label)) {\n\t\t\tCLIDisplay.write(chalk.hex(\"#FFA500\").bold(`${label}: `));\n\t\t}\n\t\tCLIDisplay.write(Coerce.string(value) ?? \"\");\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display a task with a label.\n\t * @param label The label for the value.\n\t * @param task The task to display.\n\t */\n\tpublic static task(label: string, task?: string): void {\n\t\tCLIDisplay.write(\"➡️ \");\n\t\tif (Is.empty(task)) {\n\t\t\tCLIDisplay.write(chalk.cyan(label));\n\t\t} else {\n\t\t\tCLIDisplay.write(chalk.cyan(`${label}: `));\n\t\t\tCLIDisplay.write(task);\n\t\t}\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display a break.\n\t */\n\tpublic static break(): void {\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display formatted and colorized JSON.\n\t * @param obj The object to display.\n\t */\n\tpublic static json(obj: unknown): void {\n\t\tCLIDisplay.write(inspect(obj, false, null, true));\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display a warning.\n\t * @param label The label for the warning.\n\t */\n\tpublic static warning(label: string): void {\n\t\tCLIDisplay.write(\"⚠️ \");\n\t\tCLIDisplay.write(chalk.hex(\"#FFA500\").bold(label));\n\t\tCLIDisplay.write(\"\\n\\n\");\n\t}\n\n\t/**\n\t * Display the processing is done.\n\t */\n\tpublic static done(): void {\n\t\tCLIDisplay.write(\"🎉 \");\n\t\tCLIDisplay.write(chalk.greenBright.bold(I18n.formatMessage(\"cli.progress.done\")));\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Start the spinner.\n\t * @param i18nMessage The message to display with the spinner.\n\t * @param spinnerCharacters The characters to use in the spinner.\n\t * @param interval The interval for the spinner.\n\t */\n\tpublic static spinnerStart(\n\t\ti18nMessage: string = \"cli.progress.pleaseWait\",\n\t\tspinnerCharacters: string[] = [\"⠋\", \"⠙\", \"⠹\", \"⠸\", \"⠼\", \"⠴\", \"⠦\", \"⠧\", \"⠇\", \"⠏\"],\n\t\tinterval: number = 100\n\t): void {\n\t\tlet spinnerIndex = 0;\n\t\tif (CLIDisplay._spinnerIntervalId) {\n\t\t\tclearInterval(CLIDisplay._spinnerIntervalId);\n\t\t}\n\t\tCLIDisplay._spinnerIntervalId = setInterval(() => {\n\t\t\tCLIDisplay.clearLine();\n\t\t\tCLIDisplay.write(\n\t\t\t\t`${spinnerCharacters[spinnerIndex++ % spinnerCharacters.length]} ${I18n.formatMessage(i18nMessage)}`\n\t\t\t);\n\t\t}, interval);\n\t}\n\n\t/**\n\t * Stop the spinner.\n\t */\n\tpublic static spinnerStop(): void {\n\t\tif (CLIDisplay._spinnerIntervalId) {\n\t\t\tclearInterval(CLIDisplay._spinnerIntervalId);\n\t\t\tCLIDisplay._spinnerIntervalId = undefined;\n\t\t}\n\t\tCLIDisplay.clearLine();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cliDisplay.js","sourceRoot":"","sources":["../../src/cliDisplay.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;GAEG;AACH,MAAM,OAAO,UAAU;IACtB;;;OAGG;IACK,MAAM,CAAC,kBAAkB,CAAsC;IAEvE;;;OAGG;IACI,MAAM,CAAC,KAAK,GAA0C,MAAM,CAAC,EAAE,CACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAE9B;;;OAGG;IACI,MAAM,CAAC,UAAU,GAA0C,MAAM,CAAC,EAAE,CAC1E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAE9B;;OAEG;IACI,MAAM,CAAC,SAAS,GAAe,GAAG,EAAE;QAC1C,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC7B,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,KAAa,EAAE,OAAe,EAAE,IAAY;QAChE,MAAM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DX-License-Identifier: Apache-2.0.\nimport { clearLine, cursorTo } from \"node:readline\";\nimport { inspect } from \"node:util\";\nimport { Coerce, ErrorHelper, I18n, Is } from \"@twin.org/core\";\nimport chalk from \"chalk\";\n\n/**\n * Display utilities for the CLI.\n */\nexport class CLIDisplay {\n\t/**\n\t * The interval ID for the spinner.\n\t * @internal\n\t */\n\tprivate static _spinnerIntervalId: NodeJS.Timeout | number | undefined;\n\n\t/**\n\t * The default output method for writing standard messages.\n\t * @param buffer The message to output.\n\t */\n\tpublic static write: (buffer: string | Uint8Array) => void = buffer =>\n\t\tprocess.stdout.write(buffer);\n\n\t/**\n\t * The default output method for writing error messages.\n\t * @param buffer The message to output.\n\t */\n\tpublic static writeError: (buffer: string | Uint8Array) => void = buffer =>\n\t\tprocess.stderr.write(buffer);\n\n\t/**\n\t * The default output method for clearing the current line.\n\t */\n\tpublic static clearLine: () => void = () => {\n\t\tclearLine(process.stdout, 0);\n\t\tcursorTo(process.stdout, 0);\n\t};\n\n\t/**\n\t * Display the header for the CLI.\n\t * @param title The title of the CLI.\n\t * @param version The version of the CLI.\n\t * @param icon The icon for the CLI.\n\t */\n\tpublic static header(title: string, version: string, icon: string): void {\n\t\tconst titleVersion = `${title} v${version}`;\n\t\tCLIDisplay.write(`${icon} ${chalk.underline.bold.blue(titleVersion)}\\n`);\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display an error message.\n\t * @param error The error to display.\n\t * @param lineBreaks Whether to add a line break after the error.\n\t * @param options Options for formatting the error.\n\t * @param options.includeStack Whether to include the stack trace in the output, defaults to false.\n\t * @param options.includeAdditional Whether to include additional error information in the output, defaults to false.\n\t */\n\tpublic static error(\n\t\terror: unknown,\n\t\tlineBreaks: boolean = true,\n\t\toptions: { includeStack?: boolean; includeAdditional?: boolean } = {}\n\t): void {\n\t\tCLIDisplay.writeError(\"❗ \");\n\t\tCLIDisplay.writeError(chalk.red(I18n.formatMessage(\"cli.progress.error\")));\n\t\tif (lineBreaks) {\n\t\t\tCLIDisplay.writeError(\"\\n\");\n\t\t}\n\n\t\tconst formatted = ErrorHelper.localizeErrors(error);\n\t\tCLIDisplay.writeError(chalk.red(formatted.map(e => `\\t${e.message}`).join(\"\\n\")));\n\n\t\tif (options.includeAdditional) {\n\t\t\tfor (const err of formatted) {\n\t\t\t\tif (Is.arrayValue(err.additional)) {\n\t\t\t\t\tCLIDisplay.writeError(chalk.red(`\\n\\t\\t${err.additional.join(\"\\n\\t\\t\")}\\n`));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (options.includeStack) {\n\t\t\tCLIDisplay.writeError(\"\\n\");\n\t\t\tCLIDisplay.writeError(\"\\n-----DEBUG STACK START-----\\n\\n\");\n\t\t\tfor (const err of formatted) {\n\t\t\t\tif (Is.stringValue(err.stack)) {\n\t\t\t\t\tCLIDisplay.writeError(`${err.stack}\\n`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tCLIDisplay.writeError(\"\\n-----DEBUG STACK END-----\\n\");\n\t\t}\n\n\t\tif (lineBreaks) {\n\t\t\tCLIDisplay.writeError(\"\\n\");\n\t\t}\n\t}\n\n\t/**\n\t * Display an error message in simple form.\n\t * @param error The error to display.\n\t */\n\tpublic static errorMessage(error: string): void {\n\t\tCLIDisplay.writeError(\"❗ \");\n\t\tCLIDisplay.writeError(chalk.red(error));\n\t\tCLIDisplay.writeError(\"\\n\");\n\t}\n\n\t/**\n\t * Display a section.\n\t * @param label The label for the section.\n\t */\n\tpublic static section(label: string): void {\n\t\tCLIDisplay.write(chalk.hex(\"#FFA500\").bold.underline(label));\n\t\tCLIDisplay.write(\"\\n\\n\");\n\t}\n\n\t/**\n\t * Display a value with a label.\n\t * @param label The label for the value.\n\t * @param value The value to display.\n\t * @param indentLevel The level of indentation.\n\t */\n\tpublic static value(label: string, value: unknown, indentLevel: number = 0): void {\n\t\tCLIDisplay.write(\"\\t\".repeat(indentLevel));\n\t\tif (Is.stringValue(label)) {\n\t\t\tCLIDisplay.write(chalk.hex(\"#FFA500\").bold(`${label}: `));\n\t\t}\n\t\tCLIDisplay.write(Coerce.string(value) ?? \"\");\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display a task with a label.\n\t * @param label The label for the value.\n\t * @param task The task to display.\n\t */\n\tpublic static task(label: string, task?: string): void {\n\t\tCLIDisplay.write(\"➡️ \");\n\t\tif (Is.empty(task)) {\n\t\t\tCLIDisplay.write(chalk.cyan(label));\n\t\t} else {\n\t\t\tCLIDisplay.write(chalk.cyan(`${label}: `));\n\t\t\tCLIDisplay.write(task);\n\t\t}\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display a break.\n\t */\n\tpublic static break(): void {\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display formatted and colorized JSON.\n\t * @param obj The object to display.\n\t */\n\tpublic static json(obj: unknown): void {\n\t\tCLIDisplay.write(inspect(obj, false, null, true));\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Display a warning.\n\t * @param label The label for the warning.\n\t */\n\tpublic static warning(label: string): void {\n\t\tCLIDisplay.write(\"⚠️ \");\n\t\tCLIDisplay.write(chalk.hex(\"#FFA500\").bold(label));\n\t\tCLIDisplay.write(\"\\n\\n\");\n\t}\n\n\t/**\n\t * Display the processing is done.\n\t */\n\tpublic static done(): void {\n\t\tCLIDisplay.write(\"🎉 \");\n\t\tCLIDisplay.write(chalk.greenBright.bold(I18n.formatMessage(\"cli.progress.done\")));\n\t\tCLIDisplay.write(\"\\n\");\n\t}\n\n\t/**\n\t * Start the spinner.\n\t * @param i18nMessage The message to display with the spinner.\n\t * @param spinnerCharacters The characters to use in the spinner.\n\t * @param interval The interval for the spinner.\n\t */\n\tpublic static spinnerStart(\n\t\ti18nMessage: string = \"cli.progress.pleaseWait\",\n\t\tspinnerCharacters: string[] = [\"⠋\", \"⠙\", \"⠹\", \"⠸\", \"⠼\", \"⠴\", \"⠦\", \"⠧\", \"⠇\", \"⠏\"],\n\t\tinterval: number = 100\n\t): void {\n\t\tlet spinnerIndex = 0;\n\t\tif (CLIDisplay._spinnerIntervalId) {\n\t\t\tclearInterval(CLIDisplay._spinnerIntervalId);\n\t\t}\n\t\tCLIDisplay._spinnerIntervalId = setInterval(() => {\n\t\t\tCLIDisplay.clearLine();\n\t\t\tCLIDisplay.write(\n\t\t\t\t`${spinnerCharacters[spinnerIndex++ % spinnerCharacters.length]} ${I18n.formatMessage(i18nMessage)}`\n\t\t\t);\n\t\t}, interval);\n\t}\n\n\t/**\n\t * Stop the spinner.\n\t */\n\tpublic static spinnerStop(): void {\n\t\tif (CLIDisplay._spinnerIntervalId) {\n\t\t\tclearInterval(CLIDisplay._spinnerIntervalId);\n\t\t\tCLIDisplay._spinnerIntervalId = undefined;\n\t\t}\n\t\tCLIDisplay.clearLine();\n\t}\n}\n"]}
|
|
@@ -27,8 +27,14 @@ export declare class CLIDisplay {
|
|
|
27
27
|
* Display an error message.
|
|
28
28
|
* @param error The error to display.
|
|
29
29
|
* @param lineBreaks Whether to add a line break after the error.
|
|
30
|
+
* @param options Options for formatting the error.
|
|
31
|
+
* @param options.includeStack Whether to include the stack trace in the output, defaults to false.
|
|
32
|
+
* @param options.includeAdditional Whether to include additional error information in the output, defaults to false.
|
|
30
33
|
*/
|
|
31
|
-
static error(error: unknown, lineBreaks?: boolean
|
|
34
|
+
static error(error: unknown, lineBreaks?: boolean, options?: {
|
|
35
|
+
includeStack?: boolean;
|
|
36
|
+
includeAdditional?: boolean;
|
|
37
|
+
}): void;
|
|
32
38
|
/**
|
|
33
39
|
* Display an error message in simple form.
|
|
34
40
|
* @param error The error to display.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.46](https://github.com/iotaledger/twin-framework/compare/cli-core-v0.0.3-next.45...cli-core-v0.0.3-next.46) (2026-05-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* improve error formatting ([#313](https://github.com/iotaledger/twin-framework/issues/313)) ([5a19623](https://github.com/iotaledger/twin-framework/commit/5a196231bcbf088bf9ba92a93b7478d3b8c5593f))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/core bumped from 0.0.3-next.45 to 0.0.3-next.46
|
|
16
|
+
* @twin.org/nameof bumped from 0.0.3-next.45 to 0.0.3-next.46
|
|
17
|
+
* devDependencies
|
|
18
|
+
* @twin.org/nameof-transformer bumped from 0.0.3-next.45 to 0.0.3-next.46
|
|
19
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.45 to 0.0.3-next.46
|
|
20
|
+
|
|
21
|
+
## [0.0.3-next.45](https://github.com/iotaledger/twin-framework/compare/cli-core-v0.0.3-next.44...cli-core-v0.0.3-next.45) (2026-05-21)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Miscellaneous Chores
|
|
25
|
+
|
|
26
|
+
* **cli-core:** Synchronize repo versions
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Dependencies
|
|
30
|
+
|
|
31
|
+
* The following workspace dependencies were updated
|
|
32
|
+
* dependencies
|
|
33
|
+
* @twin.org/core bumped from 0.0.3-next.44 to 0.0.3-next.45
|
|
34
|
+
* @twin.org/nameof bumped from 0.0.3-next.44 to 0.0.3-next.45
|
|
35
|
+
* devDependencies
|
|
36
|
+
* @twin.org/nameof-transformer bumped from 0.0.3-next.44 to 0.0.3-next.45
|
|
37
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.44 to 0.0.3-next.45
|
|
38
|
+
|
|
3
39
|
## [0.0.3-next.44](https://github.com/iotaledger/twin-framework/compare/cli-core-v0.0.3-next.43...cli-core-v0.0.3-next.44) (2026-05-19)
|
|
4
40
|
|
|
5
41
|
|
|
@@ -100,7 +100,7 @@ The icon for the CLI.
|
|
|
100
100
|
|
|
101
101
|
### error() {#error}
|
|
102
102
|
|
|
103
|
-
> `static` **error**(`error`, `lineBreaks?`): `void`
|
|
103
|
+
> `static` **error**(`error`, `lineBreaks?`, `options?`): `void`
|
|
104
104
|
|
|
105
105
|
Display an error message.
|
|
106
106
|
|
|
@@ -118,6 +118,22 @@ The error to display.
|
|
|
118
118
|
|
|
119
119
|
Whether to add a line break after the error.
|
|
120
120
|
|
|
121
|
+
##### options?
|
|
122
|
+
|
|
123
|
+
Options for formatting the error.
|
|
124
|
+
|
|
125
|
+
###### includeStack?
|
|
126
|
+
|
|
127
|
+
`boolean`
|
|
128
|
+
|
|
129
|
+
Whether to include the stack trace in the output, defaults to false.
|
|
130
|
+
|
|
131
|
+
###### includeAdditional?
|
|
132
|
+
|
|
133
|
+
`boolean`
|
|
134
|
+
|
|
135
|
+
Whether to include additional error information in the output, defaults to false.
|
|
136
|
+
|
|
121
137
|
#### Returns
|
|
122
138
|
|
|
123
139
|
`void`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/cli-core",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.46",
|
|
4
4
|
"description": "Core classes for building a CLI",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/core": "0.0.3-next.
|
|
18
|
-
"@twin.org/nameof": "0.0.3-next.
|
|
17
|
+
"@twin.org/core": "0.0.3-next.46",
|
|
18
|
+
"@twin.org/nameof": "0.0.3-next.46",
|
|
19
19
|
"chalk": "5.6.2",
|
|
20
20
|
"commander": "14.0.3",
|
|
21
21
|
"dotenv": "17.4.2"
|