@vlandoss/clibuddy 0.0.9-git-9b7b388.0 → 0.0.9-git-bf8b1d1.0
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/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/run.ts +26 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vlandoss/clibuddy",
|
|
3
|
-
"version": "0.0.9-git-
|
|
3
|
+
"version": "0.0.9-git-bf8b1d1.0",
|
|
4
4
|
"description": "A helper library to create CLIs in Variable Land",
|
|
5
5
|
"homepage": "https://github.com/variableland/dx/tree/main/packages/clibuddy#readme",
|
|
6
6
|
"bugs": {
|
package/src/index.ts
CHANGED
package/src/run.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isProcessOutput } from "./services/shell/utils";
|
|
2
|
+
|
|
3
|
+
function hasMessage(error: unknown): error is { message: string } {
|
|
4
|
+
return (
|
|
5
|
+
typeof error === "object" &&
|
|
6
|
+
error !== null &&
|
|
7
|
+
"message" in error &&
|
|
8
|
+
typeof (error as { message: unknown }).message === "string"
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function formatError(error: unknown): string {
|
|
13
|
+
if (hasMessage(error)) return error.message;
|
|
14
|
+
return String(error);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function run(fn: () => Promise<void>, logger: { error: (...args: unknown[]) => void }) {
|
|
18
|
+
try {
|
|
19
|
+
await fn();
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (!isProcessOutput(error)) {
|
|
22
|
+
logger.error(formatError(error));
|
|
23
|
+
}
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
}
|