@studiometa/forge-cli 0.0.1 → 0.1.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/README.md +236 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +2746 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/backups/command.d.ts +2 -0
- package/dist/commands/backups/command.d.ts.map +1 -0
- package/dist/commands/backups/handlers.d.ts +6 -0
- package/dist/commands/backups/handlers.d.ts.map +1 -0
- package/dist/commands/backups/help.d.ts +2 -0
- package/dist/commands/backups/help.d.ts.map +1 -0
- package/dist/commands/backups/index.d.ts +3 -0
- package/dist/commands/backups/index.d.ts.map +1 -0
- package/dist/commands/certificates/command.d.ts +2 -0
- package/dist/commands/certificates/command.d.ts.map +1 -0
- package/dist/commands/certificates/handlers.d.ts +5 -0
- package/dist/commands/certificates/handlers.d.ts.map +1 -0
- package/dist/commands/certificates/help.d.ts +2 -0
- package/dist/commands/certificates/help.d.ts.map +1 -0
- package/dist/commands/certificates/index.d.ts +3 -0
- package/dist/commands/certificates/index.d.ts.map +1 -0
- package/dist/commands/commands/command.d.ts +2 -0
- package/dist/commands/commands/command.d.ts.map +1 -0
- package/dist/commands/commands/handlers.d.ts +5 -0
- package/dist/commands/commands/handlers.d.ts.map +1 -0
- package/dist/commands/commands/help.d.ts +2 -0
- package/dist/commands/commands/help.d.ts.map +1 -0
- package/dist/commands/commands/index.d.ts +3 -0
- package/dist/commands/commands/index.d.ts.map +1 -0
- package/dist/commands/config.d.ts +6 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/daemons/command.d.ts +2 -0
- package/dist/commands/daemons/command.d.ts.map +1 -0
- package/dist/commands/daemons/handlers.d.ts +5 -0
- package/dist/commands/daemons/handlers.d.ts.map +1 -0
- package/dist/commands/daemons/help.d.ts +2 -0
- package/dist/commands/daemons/help.d.ts.map +1 -0
- package/dist/commands/daemons/index.d.ts +3 -0
- package/dist/commands/daemons/index.d.ts.map +1 -0
- package/dist/commands/database-users/command.d.ts +2 -0
- package/dist/commands/database-users/command.d.ts.map +1 -0
- package/dist/commands/database-users/handlers.d.ts +6 -0
- package/dist/commands/database-users/handlers.d.ts.map +1 -0
- package/dist/commands/database-users/help.d.ts +2 -0
- package/dist/commands/database-users/help.d.ts.map +1 -0
- package/dist/commands/database-users/index.d.ts +3 -0
- package/dist/commands/database-users/index.d.ts.map +1 -0
- package/dist/commands/databases/command.d.ts +2 -0
- package/dist/commands/databases/command.d.ts.map +1 -0
- package/dist/commands/databases/handlers.d.ts +4 -0
- package/dist/commands/databases/handlers.d.ts.map +1 -0
- package/dist/commands/databases/help.d.ts +2 -0
- package/dist/commands/databases/help.d.ts.map +1 -0
- package/dist/commands/databases/index.d.ts +3 -0
- package/dist/commands/databases/index.d.ts.map +1 -0
- package/dist/commands/deployments/command.d.ts +2 -0
- package/dist/commands/deployments/command.d.ts.map +1 -0
- package/dist/commands/deployments/handlers.d.ts +4 -0
- package/dist/commands/deployments/handlers.d.ts.map +1 -0
- package/dist/commands/deployments/help.d.ts +2 -0
- package/dist/commands/deployments/help.d.ts.map +1 -0
- package/dist/commands/deployments/index.d.ts +3 -0
- package/dist/commands/deployments/index.d.ts.map +1 -0
- package/dist/commands/env/command.d.ts +2 -0
- package/dist/commands/env/command.d.ts.map +1 -0
- package/dist/commands/env/handlers.d.ts +4 -0
- package/dist/commands/env/handlers.d.ts.map +1 -0
- package/dist/commands/env/help.d.ts +2 -0
- package/dist/commands/env/help.d.ts.map +1 -0
- package/dist/commands/env/index.d.ts +3 -0
- package/dist/commands/env/index.d.ts.map +1 -0
- package/dist/commands/firewall-rules/command.d.ts +2 -0
- package/dist/commands/firewall-rules/command.d.ts.map +1 -0
- package/dist/commands/firewall-rules/handlers.d.ts +4 -0
- package/dist/commands/firewall-rules/handlers.d.ts.map +1 -0
- package/dist/commands/firewall-rules/help.d.ts +2 -0
- package/dist/commands/firewall-rules/help.d.ts.map +1 -0
- package/dist/commands/firewall-rules/index.d.ts +3 -0
- package/dist/commands/firewall-rules/index.d.ts.map +1 -0
- package/dist/commands/monitors/command.d.ts +2 -0
- package/dist/commands/monitors/command.d.ts.map +1 -0
- package/dist/commands/monitors/handlers.d.ts +6 -0
- package/dist/commands/monitors/handlers.d.ts.map +1 -0
- package/dist/commands/monitors/help.d.ts +2 -0
- package/dist/commands/monitors/help.d.ts.map +1 -0
- package/dist/commands/monitors/index.d.ts +3 -0
- package/dist/commands/monitors/index.d.ts.map +1 -0
- package/dist/commands/nginx/command.d.ts +2 -0
- package/dist/commands/nginx/command.d.ts.map +1 -0
- package/dist/commands/nginx/handlers.d.ts +4 -0
- package/dist/commands/nginx/handlers.d.ts.map +1 -0
- package/dist/commands/nginx/help.d.ts +2 -0
- package/dist/commands/nginx/help.d.ts.map +1 -0
- package/dist/commands/nginx/index.d.ts +3 -0
- package/dist/commands/nginx/index.d.ts.map +1 -0
- package/dist/commands/nginx-templates/command.d.ts +2 -0
- package/dist/commands/nginx-templates/command.d.ts.map +1 -0
- package/dist/commands/nginx-templates/handlers.d.ts +7 -0
- package/dist/commands/nginx-templates/handlers.d.ts.map +1 -0
- package/dist/commands/nginx-templates/help.d.ts +2 -0
- package/dist/commands/nginx-templates/help.d.ts.map +1 -0
- package/dist/commands/nginx-templates/index.d.ts +3 -0
- package/dist/commands/nginx-templates/index.d.ts.map +1 -0
- package/dist/commands/recipes/command.d.ts +2 -0
- package/dist/commands/recipes/command.d.ts.map +1 -0
- package/dist/commands/recipes/handlers.d.ts +5 -0
- package/dist/commands/recipes/handlers.d.ts.map +1 -0
- package/dist/commands/recipes/help.d.ts +2 -0
- package/dist/commands/recipes/help.d.ts.map +1 -0
- package/dist/commands/recipes/index.d.ts +3 -0
- package/dist/commands/recipes/index.d.ts.map +1 -0
- package/dist/commands/redirect-rules/command.d.ts +2 -0
- package/dist/commands/redirect-rules/command.d.ts.map +1 -0
- package/dist/commands/redirect-rules/handlers.d.ts +6 -0
- package/dist/commands/redirect-rules/handlers.d.ts.map +1 -0
- package/dist/commands/redirect-rules/help.d.ts +2 -0
- package/dist/commands/redirect-rules/help.d.ts.map +1 -0
- package/dist/commands/redirect-rules/index.d.ts +3 -0
- package/dist/commands/redirect-rules/index.d.ts.map +1 -0
- package/dist/commands/scheduled-jobs/command.d.ts +2 -0
- package/dist/commands/scheduled-jobs/command.d.ts.map +1 -0
- package/dist/commands/scheduled-jobs/handlers.d.ts +6 -0
- package/dist/commands/scheduled-jobs/handlers.d.ts.map +1 -0
- package/dist/commands/scheduled-jobs/help.d.ts +2 -0
- package/dist/commands/scheduled-jobs/help.d.ts.map +1 -0
- package/dist/commands/scheduled-jobs/index.d.ts +3 -0
- package/dist/commands/scheduled-jobs/index.d.ts.map +1 -0
- package/dist/commands/security-rules/command.d.ts +2 -0
- package/dist/commands/security-rules/command.d.ts.map +1 -0
- package/dist/commands/security-rules/handlers.d.ts +6 -0
- package/dist/commands/security-rules/handlers.d.ts.map +1 -0
- package/dist/commands/security-rules/help.d.ts +2 -0
- package/dist/commands/security-rules/help.d.ts.map +1 -0
- package/dist/commands/security-rules/index.d.ts +3 -0
- package/dist/commands/security-rules/index.d.ts.map +1 -0
- package/dist/commands/servers/command.d.ts +2 -0
- package/dist/commands/servers/command.d.ts.map +1 -0
- package/dist/commands/servers/handlers.d.ts +18 -0
- package/dist/commands/servers/handlers.d.ts.map +1 -0
- package/dist/commands/servers/help.d.ts +2 -0
- package/dist/commands/servers/help.d.ts.map +1 -0
- package/dist/commands/servers/index.d.ts +3 -0
- package/dist/commands/servers/index.d.ts.map +1 -0
- package/dist/commands/sites/command.d.ts +2 -0
- package/dist/commands/sites/command.d.ts.map +1 -0
- package/dist/commands/sites/handlers.d.ts +4 -0
- package/dist/commands/sites/handlers.d.ts.map +1 -0
- package/dist/commands/sites/help.d.ts +2 -0
- package/dist/commands/sites/help.d.ts.map +1 -0
- package/dist/commands/sites/index.d.ts +3 -0
- package/dist/commands/sites/index.d.ts.map +1 -0
- package/dist/commands/ssh-keys/command.d.ts +2 -0
- package/dist/commands/ssh-keys/command.d.ts.map +1 -0
- package/dist/commands/ssh-keys/handlers.d.ts +4 -0
- package/dist/commands/ssh-keys/handlers.d.ts.map +1 -0
- package/dist/commands/ssh-keys/help.d.ts +2 -0
- package/dist/commands/ssh-keys/help.d.ts.map +1 -0
- package/dist/commands/ssh-keys/index.d.ts +3 -0
- package/dist/commands/ssh-keys/index.d.ts.map +1 -0
- package/dist/commands/user/command.d.ts +2 -0
- package/dist/commands/user/command.d.ts.map +1 -0
- package/dist/commands/user/handlers.d.ts +3 -0
- package/dist/commands/user/handlers.d.ts.map +1 -0
- package/dist/commands/user/help.d.ts +2 -0
- package/dist/commands/user/help.d.ts.map +1 -0
- package/dist/commands/user/index.d.ts +3 -0
- package/dist/commands/user/index.d.ts.map +1 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/context.d.ts +50 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/error-handler-BahHMt6t.js +396 -0
- package/dist/error-handler-BahHMt6t.js.map +1 -0
- package/dist/error-handler.d.ts +39 -0
- package/dist/error-handler.d.ts.map +1 -0
- package/dist/errors.d.ts +45 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/output.d.ts +47 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/args.d.ts +14 -0
- package/dist/utils/args.d.ts.map +1 -0
- package/dist/utils/colors.d.ts +17 -0
- package/dist/utils/colors.d.ts.map +1 -0
- package/dist/utils/command-router.d.ts +47 -0
- package/dist/utils/command-router.d.ts.map +1 -0
- package/dist/utils/resolve.d.ts +25 -0
- package/dist/utils/resolve.d.ts.map +1 -0
- package/package.json +41 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/ssh-keys/command.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,6GAO/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../src/commands/ssh-keys/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAKvD,wBAAsB,WAAW,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBpE;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../../src/commands/ssh-keys/help.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAiCzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/ssh-keys/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/user/command.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,iBAAiB,6GAK5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../../src/commands/user/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD,wBAAsB,OAAO,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAOhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../../src/commands/user/help.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CA2BtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/user/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config loading for forge-cli.
|
|
3
|
+
*
|
|
4
|
+
* Resolution priority (highest to lowest):
|
|
5
|
+
* 1. CLI arguments (--token)
|
|
6
|
+
* 2. Environment variable (FORGE_API_TOKEN)
|
|
7
|
+
* 3. Config file (XDG-compliant)
|
|
8
|
+
*/
|
|
9
|
+
export interface ForgeCliConfig {
|
|
10
|
+
/** Forge API token */
|
|
11
|
+
apiToken: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolve config from multiple sources with priority order.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getConfig(cliOptions?: Record<string, string | boolean | string[]>): ForgeCliConfig;
|
|
17
|
+
export { createConfigStore, getToken, setToken, deleteToken } from "@studiometa/forge-api";
|
|
18
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,WAAW,cAAc;IAC7B,sBAAsB;IACtB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,CAAC,GACvD,cAAc,CAUhB;AAED,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI execution context with dependency injection.
|
|
3
|
+
*
|
|
4
|
+
* Instead of hidden dependencies in command handlers, this module provides
|
|
5
|
+
* explicit dependency passing for testability and transparency.
|
|
6
|
+
*/
|
|
7
|
+
import type { HttpClient } from "@studiometa/forge-api";
|
|
8
|
+
import type { ExecutorContext } from "@studiometa/forge-core";
|
|
9
|
+
import { OutputFormatter } from "./output.ts";
|
|
10
|
+
export interface CommandOptions {
|
|
11
|
+
[key: string]: string | boolean | string[] | undefined;
|
|
12
|
+
format?: string;
|
|
13
|
+
f?: string;
|
|
14
|
+
token?: string;
|
|
15
|
+
"no-color"?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Context containing all dependencies needed by command handlers.
|
|
19
|
+
*/
|
|
20
|
+
export interface CommandContext {
|
|
21
|
+
/** Output formatter for the current format */
|
|
22
|
+
readonly formatter: OutputFormatter;
|
|
23
|
+
/** Raw CLI options */
|
|
24
|
+
readonly options: CommandOptions;
|
|
25
|
+
/** Create an ExecutorContext from this command context */
|
|
26
|
+
createExecutorContext(token: string): ExecutorContext;
|
|
27
|
+
/** Resolve the API token or throw ConfigError */
|
|
28
|
+
getToken(): string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a command context from CLI options.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createContext(options?: CommandOptions): CommandContext;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a test context for unit tests.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const ctx = createTestContext({
|
|
40
|
+
* mockClient: { get: async () => ({ servers: [] }) } as never,
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createTestContext(overrides: {
|
|
45
|
+
options?: CommandOptions;
|
|
46
|
+
formatter?: OutputFormatter;
|
|
47
|
+
token?: string;
|
|
48
|
+
mockClient?: HttpClient;
|
|
49
|
+
}): CommandContext;
|
|
50
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAO9D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,QAAQ,CAAC,SAAS,EAAE,eAAe,CAAC;IACpC,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,0DAA0D;IAC1D,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,CAAC;IACtD,iDAAiD;IACjD,QAAQ,IAAI,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,cAAc,CA4B1E;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE;IAC3C,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,GAAG,cAAc,CAyBjB"}
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { HttpClient, createConfigStore, createConfigStore as createConfigStore$1, deleteToken, getToken, getToken as getToken$1, setToken } from "@studiometa/forge-api";
|
|
2
|
+
/**
|
|
3
|
+
* Error types for forge-cli.
|
|
4
|
+
*
|
|
5
|
+
* Provides specific error types for different failure scenarios with
|
|
6
|
+
* recovery hints for both humans and AI agents.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Base error class for all CLI errors.
|
|
10
|
+
*/
|
|
11
|
+
var CliError = class extends Error {
|
|
12
|
+
constructor(message, hints, cause) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.hints = hints;
|
|
15
|
+
this.cause = cause;
|
|
16
|
+
this.name = this.constructor.name;
|
|
17
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
18
|
+
}
|
|
19
|
+
toJSON() {
|
|
20
|
+
return {
|
|
21
|
+
error: this.code,
|
|
22
|
+
name: this.name,
|
|
23
|
+
message: this.message,
|
|
24
|
+
isRecoverable: this.isRecoverable,
|
|
25
|
+
...this.hints && this.hints.length > 0 ? { hints: this.hints } : {},
|
|
26
|
+
...this.cause instanceof Error ? { cause: { message: this.cause.message } } : {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
toFormattedMessage() {
|
|
30
|
+
let msg = this.message;
|
|
31
|
+
if (this.hints && this.hints.length > 0) msg += "\n\nHints:\n" + this.hints.map((h) => ` • ${h}`).join("\n");
|
|
32
|
+
return msg;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var ConfigError = class ConfigError extends CliError {
|
|
36
|
+
code = "CONFIG_ERROR";
|
|
37
|
+
isRecoverable = true;
|
|
38
|
+
static missingToken() {
|
|
39
|
+
return new ConfigError("API token not configured", [
|
|
40
|
+
"Set via CLI flag: --token <token>",
|
|
41
|
+
"Set via environment: export FORGE_API_TOKEN=<token>",
|
|
42
|
+
"Set via config: forge-cli config set YOUR_TOKEN"
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var ValidationError = class ValidationError extends CliError {
|
|
47
|
+
code = "VALIDATION_ERROR";
|
|
48
|
+
isRecoverable = true;
|
|
49
|
+
constructor(message, field, hints, cause) {
|
|
50
|
+
super(message, hints, cause);
|
|
51
|
+
this.field = field;
|
|
52
|
+
}
|
|
53
|
+
toJSON() {
|
|
54
|
+
return {
|
|
55
|
+
...super.toJSON(),
|
|
56
|
+
field: this.field
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
static required(field, hints) {
|
|
60
|
+
return new ValidationError(`${field} is required`, field, hints);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var ApiError = class ApiError extends CliError {
|
|
64
|
+
code = "API_ERROR";
|
|
65
|
+
isRecoverable;
|
|
66
|
+
constructor(message, statusCode, hints, cause) {
|
|
67
|
+
super(message, hints ?? getApiErrorHints(statusCode), cause);
|
|
68
|
+
this.statusCode = statusCode;
|
|
69
|
+
this.isRecoverable = statusCode === void 0 || statusCode >= 500 && statusCode < 600;
|
|
70
|
+
}
|
|
71
|
+
toJSON() {
|
|
72
|
+
return {
|
|
73
|
+
...super.toJSON(),
|
|
74
|
+
statusCode: this.statusCode
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
static fromForgeError(error) {
|
|
78
|
+
if (error instanceof Error && "statusCode" in error) {
|
|
79
|
+
const e = error;
|
|
80
|
+
return new ApiError(e.message, e.statusCode, void 0, e);
|
|
81
|
+
}
|
|
82
|
+
if (error instanceof Error) return new ApiError(error.message, void 0, void 0, error);
|
|
83
|
+
return new ApiError(String(error));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
function getApiErrorHints(statusCode) {
|
|
87
|
+
if (statusCode === 401) return ["Check that your API token is valid", "Set via: export FORGE_API_TOKEN=<token>"];
|
|
88
|
+
if (statusCode === 403) return ["You may not have permission to access this resource"];
|
|
89
|
+
if (statusCode === 404) return [
|
|
90
|
+
"The resource may not exist",
|
|
91
|
+
"Verify the ID is correct",
|
|
92
|
+
"Use the list command to find valid IDs"
|
|
93
|
+
];
|
|
94
|
+
if (statusCode === 429) return ["Too many requests — wait before retrying"];
|
|
95
|
+
if (statusCode !== void 0 && statusCode >= 500) return ["Server error — try again later"];
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
function isCliError(error) {
|
|
99
|
+
return error instanceof CliError;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Config loading for forge-cli.
|
|
103
|
+
*
|
|
104
|
+
* Resolution priority (highest to lowest):
|
|
105
|
+
* 1. CLI arguments (--token)
|
|
106
|
+
* 2. Environment variable (FORGE_API_TOKEN)
|
|
107
|
+
* 3. Config file (XDG-compliant)
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Resolve config from multiple sources with priority order.
|
|
111
|
+
*/
|
|
112
|
+
function getConfig(cliOptions) {
|
|
113
|
+
const cliToken = cliOptions?.token;
|
|
114
|
+
const storedToken = getToken(createConfigStore());
|
|
115
|
+
return { apiToken: typeof cliToken === "string" ? cliToken : storedToken ?? void 0 };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* ANSI color utilities using native Node.js.
|
|
119
|
+
* Provides terminal colors without external dependencies.
|
|
120
|
+
*/
|
|
121
|
+
var RESET = "\x1B[0m";
|
|
122
|
+
var BOLD = "\x1B[1m";
|
|
123
|
+
var DIM = "\x1B[2m";
|
|
124
|
+
var FG_RED = "\x1B[31m";
|
|
125
|
+
var FG_GREEN = "\x1B[32m";
|
|
126
|
+
var FG_YELLOW = "\x1B[33m";
|
|
127
|
+
var FG_CYAN = "\x1B[36m";
|
|
128
|
+
var FG_GRAY = "\x1B[90m";
|
|
129
|
+
var colorEnabled = process.env.NO_COLOR === void 0;
|
|
130
|
+
function setColorEnabled(enabled) {
|
|
131
|
+
colorEnabled = enabled;
|
|
132
|
+
}
|
|
133
|
+
function colorize(text, code) {
|
|
134
|
+
if (!colorEnabled) return text;
|
|
135
|
+
return `${code}${text}${RESET}`;
|
|
136
|
+
}
|
|
137
|
+
const colors = {
|
|
138
|
+
reset: (text) => colorEnabled ? `${RESET}${text}` : text,
|
|
139
|
+
bold: (text) => colorize(text, BOLD),
|
|
140
|
+
dim: (text) => colorize(text, DIM),
|
|
141
|
+
red: (text) => colorize(text, FG_RED),
|
|
142
|
+
green: (text) => colorize(text, FG_GREEN),
|
|
143
|
+
yellow: (text) => colorize(text, FG_YELLOW),
|
|
144
|
+
cyan: (text) => colorize(text, FG_CYAN),
|
|
145
|
+
gray: (text) => colorize(text, FG_GRAY)
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Output formatter for CLI commands.
|
|
149
|
+
* Supports human-readable, JSON, and table formats.
|
|
150
|
+
*/
|
|
151
|
+
var OutputFormatter = class {
|
|
152
|
+
constructor(format = "human", noColor = false) {
|
|
153
|
+
this.format = format;
|
|
154
|
+
this.noColor = noColor;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Returns true when the current format is JSON.
|
|
158
|
+
*/
|
|
159
|
+
isJson() {
|
|
160
|
+
return this.format === "json";
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Output data in the configured format.
|
|
164
|
+
* Use format='json' for AI agents and structured data.
|
|
165
|
+
*/
|
|
166
|
+
output(data) {
|
|
167
|
+
switch (this.format) {
|
|
168
|
+
case "json":
|
|
169
|
+
console.log(JSON.stringify(data, null, 2));
|
|
170
|
+
break;
|
|
171
|
+
case "table":
|
|
172
|
+
this.outputTable(data);
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
console.log(data);
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Output a list with a human-readable one-liner per item and a table for table format.
|
|
181
|
+
* Falls back to JSON for json format.
|
|
182
|
+
*
|
|
183
|
+
* @param data - Array of items to display
|
|
184
|
+
* @param columns - Ordered list of field names to include in human/table output
|
|
185
|
+
* @param emptyMessage - Message shown when data is empty (human format only)
|
|
186
|
+
* @param lineFormat - Optional custom line formatter for human format
|
|
187
|
+
*/
|
|
188
|
+
outputList(data, columns, emptyMessage, lineFormat) {
|
|
189
|
+
if (this.format === "json") {
|
|
190
|
+
console.log(JSON.stringify(data, null, 2));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (this.format === "table") {
|
|
194
|
+
this.outputTable(data.map((item) => Object.fromEntries(columns.map((c) => [c, item[c]]))));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (data.length === 0) {
|
|
198
|
+
console.log(colors.cyan(emptyMessage));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (lineFormat) {
|
|
202
|
+
for (const item of data) console.log(lineFormat(item));
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const widths = columns.map((col) => Math.max(col.length, ...data.map((item) => String(item[col] ?? "").length)));
|
|
206
|
+
for (const item of data) {
|
|
207
|
+
const row = item;
|
|
208
|
+
const line = columns.map((col, i) => String(row[col] ?? "").padEnd(widths[i])).join(" ");
|
|
209
|
+
console.log(line.trimEnd());
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Output a single resource in human-readable format.
|
|
214
|
+
* For json format, uses JSON.stringify. For table format, uses a two-column key/value table.
|
|
215
|
+
*
|
|
216
|
+
* @param data - Object to display
|
|
217
|
+
* @param fields - Ordered list of fields to display (defaults to all keys)
|
|
218
|
+
*/
|
|
219
|
+
outputOne(data, fields) {
|
|
220
|
+
if (this.format === "json") {
|
|
221
|
+
console.log(JSON.stringify(data, null, 2));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const record = data;
|
|
225
|
+
const keys = fields ?? Object.keys(record);
|
|
226
|
+
if (this.format === "table") {
|
|
227
|
+
const rows = keys.map((k) => ({
|
|
228
|
+
field: k,
|
|
229
|
+
value: String(record[k] ?? "")
|
|
230
|
+
}));
|
|
231
|
+
this.outputTable(rows);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const keyWidth = Math.max(...keys.map((k) => k.length));
|
|
235
|
+
for (const key of keys) {
|
|
236
|
+
const value = record[key];
|
|
237
|
+
const valueStr = value !== null && typeof value === "object" ? JSON.stringify(value) : String(value ?? "");
|
|
238
|
+
console.log(`${colors.cyan(key.padEnd(keyWidth))} ${valueStr}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
success(message) {
|
|
242
|
+
if (this.format === "json") console.log(JSON.stringify({
|
|
243
|
+
status: "success",
|
|
244
|
+
message
|
|
245
|
+
}));
|
|
246
|
+
else console.log(colors.green(`✓ ${message}`));
|
|
247
|
+
}
|
|
248
|
+
error(message, details) {
|
|
249
|
+
if (this.format === "json") console.error(JSON.stringify({
|
|
250
|
+
status: "error",
|
|
251
|
+
message,
|
|
252
|
+
details
|
|
253
|
+
}));
|
|
254
|
+
else {
|
|
255
|
+
console.error(colors.red(`✗ ${message}`));
|
|
256
|
+
if (details !== void 0) console.error(details);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
warning(message) {
|
|
260
|
+
if (this.format === "json") console.log(JSON.stringify({
|
|
261
|
+
status: "warning",
|
|
262
|
+
message
|
|
263
|
+
}));
|
|
264
|
+
else console.log(colors.yellow(`⚠ ${message}`));
|
|
265
|
+
}
|
|
266
|
+
info(message) {
|
|
267
|
+
if (this.format === "json") console.log(JSON.stringify({
|
|
268
|
+
status: "info",
|
|
269
|
+
message
|
|
270
|
+
}));
|
|
271
|
+
else console.log(colors.cyan(message));
|
|
272
|
+
}
|
|
273
|
+
outputTable(data) {
|
|
274
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
275
|
+
const headers = Object.keys(data[0]);
|
|
276
|
+
const colWidths = headers.map((h) => {
|
|
277
|
+
const maxDataWidth = Math.max(...data.map((row) => String(row[h] ?? "").length));
|
|
278
|
+
return Math.max(h.length, maxDataWidth);
|
|
279
|
+
});
|
|
280
|
+
const headerRow = headers.map((h, i) => h.padEnd(colWidths[i])).join(" | ");
|
|
281
|
+
console.log(headerRow);
|
|
282
|
+
console.log(colWidths.map((w) => "-".repeat(w)).join("-+-"));
|
|
283
|
+
for (const row of data) {
|
|
284
|
+
const rowStr = headers.map((h, i) => String(row[h] ?? "").padEnd(colWidths[i])).join(" | ");
|
|
285
|
+
console.log(rowStr);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Creates a command context from CLI options.
|
|
292
|
+
*/
|
|
293
|
+
function createContext(options = {}) {
|
|
294
|
+
return {
|
|
295
|
+
formatter: new OutputFormatter(options.format ?? options.f ?? "human", options["no-color"] === true),
|
|
296
|
+
options,
|
|
297
|
+
createExecutorContext(token) {
|
|
298
|
+
return { client: new HttpClient({ token }) };
|
|
299
|
+
},
|
|
300
|
+
getToken() {
|
|
301
|
+
if (typeof options.token === "string" && options.token) return options.token;
|
|
302
|
+
const stored = getToken$1(createConfigStore$1());
|
|
303
|
+
if (stored) return stored;
|
|
304
|
+
throw ConfigError.missingToken();
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Creates a test context for unit tests.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* const ctx = createTestContext({
|
|
314
|
+
* mockClient: { get: async () => ({ servers: [] }) } as never,
|
|
315
|
+
* });
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
function createTestContext(overrides) {
|
|
319
|
+
const opts = overrides.options ?? {
|
|
320
|
+
format: "json",
|
|
321
|
+
"no-color": true
|
|
322
|
+
};
|
|
323
|
+
const format = opts.format ?? "json";
|
|
324
|
+
return {
|
|
325
|
+
formatter: overrides.formatter ?? new OutputFormatter(format, true),
|
|
326
|
+
options: opts,
|
|
327
|
+
createExecutorContext(_token) {
|
|
328
|
+
if (!overrides.mockClient) throw new Error("createTestContext: provide mockClient to use createExecutorContext in tests");
|
|
329
|
+
return { client: overrides.mockClient };
|
|
330
|
+
},
|
|
331
|
+
getToken() {
|
|
332
|
+
if (overrides.token) return overrides.token;
|
|
333
|
+
if (typeof opts.token === "string") return opts.token;
|
|
334
|
+
return "test-token";
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Exit codes for different error categories.
|
|
340
|
+
*/
|
|
341
|
+
const ExitCode = {
|
|
342
|
+
SUCCESS: 0,
|
|
343
|
+
GENERAL_ERROR: 1,
|
|
344
|
+
AUTHENTICATION_ERROR: 2,
|
|
345
|
+
VALIDATION_ERROR: 3,
|
|
346
|
+
CONFIG_ERROR: 4,
|
|
347
|
+
NOT_FOUND_ERROR: 5
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* Determine the appropriate exit code for an error.
|
|
351
|
+
*/
|
|
352
|
+
function getExitCode(error) {
|
|
353
|
+
if (error instanceof ValidationError) return ExitCode.VALIDATION_ERROR;
|
|
354
|
+
if (error instanceof ApiError) {
|
|
355
|
+
if (error.statusCode === 401) return ExitCode.AUTHENTICATION_ERROR;
|
|
356
|
+
if (error.statusCode === 404) return ExitCode.NOT_FOUND_ERROR;
|
|
357
|
+
}
|
|
358
|
+
if (isCliError(error) && error.code === "CONFIG_ERROR") return ExitCode.CONFIG_ERROR;
|
|
359
|
+
return ExitCode.GENERAL_ERROR;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Central error handler for all commands.
|
|
363
|
+
*/
|
|
364
|
+
function handleError(error, formatter, options) {
|
|
365
|
+
const shouldExit = options?.exit ?? true;
|
|
366
|
+
let cliError;
|
|
367
|
+
if (isCliError(error)) cliError = error;
|
|
368
|
+
else cliError = ApiError.fromForgeError(error);
|
|
369
|
+
if (formatter.format === "json") formatter.output(cliError.toJSON());
|
|
370
|
+
else formatter.error(cliError.toFormattedMessage());
|
|
371
|
+
const exitCode = getExitCode(cliError);
|
|
372
|
+
if (shouldExit) process.exit(exitCode);
|
|
373
|
+
return exitCode;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Wraps a command function with automatic error handling.
|
|
377
|
+
*/
|
|
378
|
+
async function runCommand(fn, formatter) {
|
|
379
|
+
try {
|
|
380
|
+
return await fn();
|
|
381
|
+
} catch (error) {
|
|
382
|
+
handleError(error, formatter);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Exits with a validation error for a missing required argument.
|
|
388
|
+
*/
|
|
389
|
+
function exitWithValidationError(field, usage, formatter) {
|
|
390
|
+
const error = ValidationError.required(field, [`Usage: ${usage}`]);
|
|
391
|
+
handleError(error, formatter);
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
export { ConfigError as _, createContext as a, colors as c, deleteToken as d, getConfig as f, CliError as g, ApiError as h, runCommand as i, setColorEnabled as l, setToken as m, exitWithValidationError as n, createTestContext as o, getToken$1 as p, handleError as r, OutputFormatter as s, ExitCode as t, createConfigStore$1 as u, ValidationError as v, isCliError as y };
|
|
395
|
+
|
|
396
|
+
//# sourceMappingURL=error-handler-BahHMt6t.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler-BahHMt6t.js","names":[],"sources":["../src/errors.ts","../src/config.ts","../src/utils/colors.ts","../src/output.ts","../src/context.ts","../src/error-handler.ts"],"sourcesContent":["/**\n * Error types for forge-cli.\n *\n * Provides specific error types for different failure scenarios with\n * recovery hints for both humans and AI agents.\n */\n\n/**\n * Base error class for all CLI errors.\n */\nexport abstract class CliError extends Error {\n abstract readonly code: string;\n abstract readonly isRecoverable: boolean;\n\n constructor(\n message: string,\n public readonly hints?: string[],\n public readonly cause?: unknown,\n ) {\n super(message);\n this.name = this.constructor.name;\n\n Error.captureStackTrace?.(this, this.constructor);\n }\n\n toJSON(): Record<string, unknown> {\n return {\n error: this.code,\n name: this.name,\n message: this.message,\n isRecoverable: this.isRecoverable,\n ...(this.hints && this.hints.length > 0 ? { hints: this.hints } : {}),\n ...(this.cause instanceof Error ? { cause: { message: this.cause.message } } : {}),\n };\n }\n\n toFormattedMessage(): string {\n let msg = this.message;\n if (this.hints && this.hints.length > 0) {\n msg += \"\\n\\nHints:\\n\" + this.hints.map((h) => ` • ${h}`).join(\"\\n\");\n }\n return msg;\n }\n}\n\n// ── Config Errors ────────────────────────────────────\n\nexport class ConfigError extends CliError {\n readonly code = \"CONFIG_ERROR\";\n readonly isRecoverable = true;\n\n static missingToken(): ConfigError {\n return new ConfigError(\"API token not configured\", [\n \"Set via CLI flag: --token <token>\",\n \"Set via environment: export FORGE_API_TOKEN=<token>\",\n \"Set via config: forge-cli config set YOUR_TOKEN\",\n ]);\n }\n}\n\n// ── Validation Errors ────────────────────────────────\n\nexport class ValidationError extends CliError {\n readonly code = \"VALIDATION_ERROR\";\n readonly isRecoverable = true;\n\n constructor(\n message: string,\n public readonly field?: string,\n hints?: string[],\n cause?: unknown,\n ) {\n super(message, hints, cause);\n }\n\n override toJSON() {\n return { ...super.toJSON(), field: this.field };\n }\n\n static required(field: string, hints?: string[]): ValidationError {\n return new ValidationError(`${field} is required`, field, hints);\n }\n}\n\n// ── API Errors ───────────────────────────────────────\n\nexport class ApiError extends CliError {\n readonly code = \"API_ERROR\";\n readonly isRecoverable: boolean;\n\n constructor(\n message: string,\n public readonly statusCode?: number,\n hints?: string[],\n cause?: unknown,\n ) {\n super(message, hints ?? getApiErrorHints(statusCode), cause);\n this.isRecoverable = statusCode === undefined || (statusCode >= 500 && statusCode < 600);\n }\n\n override toJSON() {\n return { ...super.toJSON(), statusCode: this.statusCode };\n }\n\n static fromForgeError(error: unknown): ApiError {\n if (error instanceof Error && \"statusCode\" in error) {\n const e = error as Error & { statusCode?: number };\n return new ApiError(e.message, e.statusCode, undefined, e);\n }\n if (error instanceof Error) {\n return new ApiError(error.message, undefined, undefined, error);\n }\n return new ApiError(String(error));\n }\n}\n\nfunction getApiErrorHints(statusCode?: number): string[] {\n if (statusCode === 401) {\n return [\"Check that your API token is valid\", \"Set via: export FORGE_API_TOKEN=<token>\"];\n }\n if (statusCode === 403) {\n return [\"You may not have permission to access this resource\"];\n }\n if (statusCode === 404) {\n return [\n \"The resource may not exist\",\n \"Verify the ID is correct\",\n \"Use the list command to find valid IDs\",\n ];\n }\n if (statusCode === 429) {\n return [\"Too many requests — wait before retrying\"];\n }\n if (statusCode !== undefined && statusCode >= 500) {\n return [\"Server error — try again later\"];\n }\n return [];\n}\n\n// ── Type Guards ──────────────────────────────────────\n\nexport function isCliError(error: unknown): error is CliError {\n return error instanceof CliError;\n}\n","/**\n * Config loading for forge-cli.\n *\n * Resolution priority (highest to lowest):\n * 1. CLI arguments (--token)\n * 2. Environment variable (FORGE_API_TOKEN)\n * 3. Config file (XDG-compliant)\n */\n\nimport { createConfigStore, getToken } from \"@studiometa/forge-api\";\n\nexport interface ForgeCliConfig {\n /** Forge API token */\n apiToken: string | undefined;\n}\n\n/**\n * Resolve config from multiple sources with priority order.\n */\nexport function getConfig(\n cliOptions?: Record<string, string | boolean | string[]>,\n): ForgeCliConfig {\n // 1. CLI argument --token\n const cliToken = cliOptions?.token;\n\n // 2. Environment variable / config file (handled by getToken)\n const storedToken = getToken(createConfigStore());\n\n return {\n apiToken: typeof cliToken === \"string\" ? cliToken : (storedToken ?? undefined),\n };\n}\n\nexport { createConfigStore, getToken, setToken, deleteToken } from \"@studiometa/forge-api\";\n","/**\n * ANSI color utilities using native Node.js.\n * Provides terminal colors without external dependencies.\n */\n\n// ANSI escape codes\nconst RESET = \"\\x1b[0m\";\nconst BOLD = \"\\x1b[1m\";\nconst DIM = \"\\x1b[2m\";\n\n// Foreground colors\nconst FG_RED = \"\\x1b[31m\";\nconst FG_GREEN = \"\\x1b[32m\";\nconst FG_YELLOW = \"\\x1b[33m\";\nconst FG_CYAN = \"\\x1b[36m\";\nconst FG_GRAY = \"\\x1b[90m\";\n\n// Colors enabled by default, disabled by NO_COLOR env var\nlet colorEnabled = process.env.NO_COLOR === undefined;\n\nexport function setColorEnabled(enabled: boolean): void {\n colorEnabled = enabled;\n}\n\nexport function isColorEnabled(): boolean {\n return colorEnabled;\n}\n\nfunction colorize(text: string, code: string): string {\n if (!colorEnabled) return text;\n return `${code}${text}${RESET}`;\n}\n\nexport const colors = {\n reset: (text: string) => (colorEnabled ? `${RESET}${text}` : text),\n bold: (text: string) => colorize(text, BOLD),\n dim: (text: string) => colorize(text, DIM),\n red: (text: string) => colorize(text, FG_RED),\n green: (text: string) => colorize(text, FG_GREEN),\n yellow: (text: string) => colorize(text, FG_YELLOW),\n cyan: (text: string) => colorize(text, FG_CYAN),\n gray: (text: string) => colorize(text, FG_GRAY),\n};\n","import type { OutputFormat } from \"./types.ts\";\n\nimport { colors } from \"./utils/colors.ts\";\n\n/**\n * Output formatter for CLI commands.\n * Supports human-readable, JSON, and table formats.\n */\nexport class OutputFormatter {\n constructor(\n private format: OutputFormat = \"human\",\n private noColor: boolean = false,\n ) {}\n\n /**\n * Returns true when the current format is JSON.\n */\n isJson(): boolean {\n return this.format === \"json\";\n }\n\n /**\n * Output data in the configured format.\n * Use format='json' for AI agents and structured data.\n */\n output(data: unknown): void {\n switch (this.format) {\n case \"json\":\n console.log(JSON.stringify(data, null, 2));\n break;\n case \"table\":\n this.outputTable(data);\n break;\n case \"human\":\n default:\n console.log(data);\n break;\n }\n }\n\n /**\n * Output a list with a human-readable one-liner per item and a table for table format.\n * Falls back to JSON for json format.\n *\n * @param data - Array of items to display\n * @param columns - Ordered list of field names to include in human/table output\n * @param emptyMessage - Message shown when data is empty (human format only)\n * @param lineFormat - Optional custom line formatter for human format\n */\n outputList<T extends object>(\n data: T[],\n columns: (keyof T & string)[],\n emptyMessage: string,\n lineFormat?: (item: T) => string,\n ): void {\n if (this.format === \"json\") {\n console.log(JSON.stringify(data, null, 2));\n return;\n }\n\n if (this.format === \"table\") {\n this.outputTable(data.map((item) => Object.fromEntries(columns.map((c) => [c, item[c]]))));\n return;\n }\n\n // human\n if (data.length === 0) {\n console.log(colors.cyan(emptyMessage));\n return;\n }\n\n if (lineFormat) {\n for (const item of data) {\n console.log(lineFormat(item));\n }\n return;\n }\n\n // Default: padded columns\n const widths = columns.map((col) =>\n Math.max(\n col.length,\n ...data.map((item) => String((item as Record<string, unknown>)[col] ?? \"\").length),\n ),\n );\n for (const item of data) {\n const row = item as Record<string, unknown>;\n const line = columns.map((col, i) => String(row[col] ?? \"\").padEnd(widths[i])).join(\" \");\n console.log(line.trimEnd());\n }\n }\n\n /**\n * Output a single resource in human-readable format.\n * For json format, uses JSON.stringify. For table format, uses a two-column key/value table.\n *\n * @param data - Object to display\n * @param fields - Ordered list of fields to display (defaults to all keys)\n */\n outputOne<T extends object>(data: T, fields?: (keyof T & string)[]): void {\n if (this.format === \"json\") {\n console.log(JSON.stringify(data, null, 2));\n return;\n }\n\n const record = data as Record<string, unknown>;\n const keys = fields ?? (Object.keys(record) as (keyof T & string)[]);\n\n if (this.format === \"table\") {\n const rows = keys.map((k) => ({ field: k, value: String(record[k] ?? \"\") }));\n this.outputTable(rows);\n return;\n }\n\n // human: key: value pairs\n const keyWidth = Math.max(...keys.map((k) => k.length));\n for (const key of keys) {\n const value = record[key];\n const valueStr =\n value !== null && typeof value === \"object\" ? JSON.stringify(value) : String(value ?? \"\");\n console.log(`${colors.cyan(key.padEnd(keyWidth))} ${valueStr}`);\n }\n }\n\n success(message: string): void {\n if (this.format === \"json\") {\n console.log(JSON.stringify({ status: \"success\", message }));\n } else {\n console.log(colors.green(`✓ ${message}`));\n }\n }\n\n error(message: string, details?: unknown): void {\n if (this.format === \"json\") {\n console.error(JSON.stringify({ status: \"error\", message, details }));\n } else {\n console.error(colors.red(`✗ ${message}`));\n if (details !== undefined) {\n console.error(details);\n }\n }\n }\n\n warning(message: string): void {\n if (this.format === \"json\") {\n console.log(JSON.stringify({ status: \"warning\", message }));\n } else {\n console.log(colors.yellow(`⚠ ${message}`));\n }\n }\n\n info(message: string): void {\n if (this.format === \"json\") {\n console.log(JSON.stringify({ status: \"info\", message }));\n } else {\n console.log(colors.cyan(message));\n }\n }\n\n private outputTable(data: unknown): void {\n if (Array.isArray(data) && data.length > 0) {\n const headers = Object.keys(data[0] as Record<string, unknown>);\n const colWidths = headers.map((h) => {\n const maxDataWidth = Math.max(\n ...data.map((row) => String((row as Record<string, unknown>)[h] ?? \"\").length),\n );\n return Math.max(h.length, maxDataWidth);\n });\n\n // Header\n const headerRow = headers.map((h, i) => h.padEnd(colWidths[i])).join(\" | \");\n console.log(headerRow);\n console.log(colWidths.map((w) => \"-\".repeat(w)).join(\"-+-\"));\n\n // Rows\n for (const row of data) {\n const rowStr = headers\n .map((h, i) => String((row as Record<string, unknown>)[h] ?? \"\").padEnd(colWidths[i]))\n .join(\" | \");\n console.log(rowStr);\n }\n }\n }\n}\nexport const x = { a: 1, b: 2 };\n","/**\n * CLI execution context with dependency injection.\n *\n * Instead of hidden dependencies in command handlers, this module provides\n * explicit dependency passing for testability and transparency.\n */\n\nimport type { HttpClient } from \"@studiometa/forge-api\";\nimport type { ExecutorContext } from \"@studiometa/forge-core\";\n\nimport type { OutputFormat } from \"./types.ts\";\n\nimport { HttpClient as ForgeHttpClient } from \"@studiometa/forge-api\";\nimport { ConfigError } from \"./errors.ts\";\nimport { createConfigStore, getToken } from \"./config.ts\";\nimport { OutputFormatter } from \"./output.ts\";\n\nexport interface CommandOptions {\n [key: string]: string | boolean | string[] | undefined;\n format?: string;\n f?: string;\n token?: string;\n \"no-color\"?: boolean;\n}\n\n/**\n * Context containing all dependencies needed by command handlers.\n */\nexport interface CommandContext {\n /** Output formatter for the current format */\n readonly formatter: OutputFormatter;\n /** Raw CLI options */\n readonly options: CommandOptions;\n /** Create an ExecutorContext from this command context */\n createExecutorContext(token: string): ExecutorContext;\n /** Resolve the API token or throw ConfigError */\n getToken(): string;\n}\n\n/**\n * Creates a command context from CLI options.\n */\nexport function createContext(options: CommandOptions = {}): CommandContext {\n const format = (options.format ?? options.f ?? \"human\") as OutputFormat;\n const noColor = options[\"no-color\"] === true;\n const formatter = new OutputFormatter(format, noColor);\n\n return {\n formatter,\n options,\n\n createExecutorContext(token: string): ExecutorContext {\n const client = new ForgeHttpClient({ token }) as unknown as HttpClient;\n return { client };\n },\n\n getToken(): string {\n // 1. CLI arg\n if (typeof options.token === \"string\" && options.token) {\n return options.token;\n }\n // 2. Env var / config file\n const stored = getToken(createConfigStore());\n if (stored) {\n return stored;\n }\n // 3. Not found — throw\n throw ConfigError.missingToken();\n },\n };\n}\n\n/**\n * Creates a test context for unit tests.\n *\n * @example\n * ```typescript\n * const ctx = createTestContext({\n * mockClient: { get: async () => ({ servers: [] }) } as never,\n * });\n * ```\n */\nexport function createTestContext(overrides: {\n options?: CommandOptions;\n formatter?: OutputFormatter;\n token?: string;\n mockClient?: HttpClient;\n}): CommandContext {\n const opts: CommandOptions = overrides.options ?? {\n format: \"json\",\n \"no-color\": true,\n };\n const format = (opts.format ?? \"json\") as OutputFormat;\n const formatter = overrides.formatter ?? new OutputFormatter(format, true);\n\n return {\n formatter,\n options: opts,\n createExecutorContext(_token: string): ExecutorContext {\n if (!overrides.mockClient) {\n throw new Error(\n \"createTestContext: provide mockClient to use createExecutorContext in tests\",\n );\n }\n return { client: overrides.mockClient };\n },\n getToken(): string {\n if (overrides.token) return overrides.token;\n if (typeof opts.token === \"string\") return opts.token;\n return \"test-token\";\n },\n };\n}\n","/**\n * Centralized error handling for forge-cli.\n */\n\nimport type { OutputFormatter } from \"./output.ts\";\n\nimport { ApiError, CliError, ConfigError, ValidationError, isCliError } from \"./errors.ts\";\n\n/**\n * Exit codes for different error categories.\n */\nexport const ExitCode = {\n SUCCESS: 0,\n GENERAL_ERROR: 1,\n AUTHENTICATION_ERROR: 2,\n VALIDATION_ERROR: 3,\n CONFIG_ERROR: 4,\n NOT_FOUND_ERROR: 5,\n} as const;\n\nexport type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];\n\n/**\n * Determine the appropriate exit code for an error.\n */\nexport function getExitCode(error: unknown): ExitCode {\n if (error instanceof ValidationError) {\n return ExitCode.VALIDATION_ERROR;\n }\n if (error instanceof ApiError) {\n if (error.statusCode === 401) return ExitCode.AUTHENTICATION_ERROR;\n if (error.statusCode === 404) return ExitCode.NOT_FOUND_ERROR;\n }\n if (isCliError(error) && error.code === \"CONFIG_ERROR\") {\n return ExitCode.CONFIG_ERROR;\n }\n return ExitCode.GENERAL_ERROR;\n}\n\n/**\n * Central error handler for all commands.\n */\nexport function handleError(\n error: unknown,\n formatter: OutputFormatter,\n options?: { exit?: boolean },\n): ExitCode {\n const shouldExit = options?.exit ?? true;\n\n let cliError: CliError;\n if (isCliError(error)) {\n cliError = error;\n } else {\n cliError = ApiError.fromForgeError(error);\n }\n\n // Output error in appropriate format\n const opts = formatter as unknown as { format?: string };\n if (opts.format === \"json\") {\n formatter.output(cliError.toJSON());\n } else {\n formatter.error(cliError.toFormattedMessage());\n }\n\n const exitCode = getExitCode(cliError);\n\n if (shouldExit) {\n process.exit(exitCode);\n }\n\n return exitCode;\n}\n\n/**\n * Wraps a command function with automatic error handling.\n */\nexport async function runCommand<T>(\n fn: () => Promise<T>,\n formatter: OutputFormatter,\n): Promise<T | undefined> {\n try {\n return await fn();\n } catch (error) {\n handleError(error, formatter);\n return undefined; // unreachable due to process.exit\n }\n}\n\n/**\n * Exits with a validation error for a missing required argument.\n */\nexport function exitWithValidationError(\n field: string,\n usage: string,\n formatter: OutputFormatter,\n): never {\n const error = ValidationError.required(field, [`Usage: ${usage}`]);\n handleError(error, formatter);\n // Unreachable in production\n throw error;\n}\n\n/**\n * Exits with a config error when token is missing.\n */\nexport function exitWithConfigError(formatter: OutputFormatter): never {\n const error = ConfigError.missingToken();\n handleError(error, formatter);\n throw error;\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAsB,WAAtB,cAAuC,MAAM;CAI3C,YACE,SACA,OACA,OACA;AACA,QAAM,QAAQ;AAHE,OAAA,QAAA;AACA,OAAA,QAAA;AAGhB,OAAK,OAAO,KAAK,YAAY;AAE7B,QAAM,oBAAoB,MAAM,KAAK,YAAY;;CAGnD,SAAkC;AAChC,SAAO;GACL,OAAO,KAAK;GACZ,MAAM,KAAK;GACX,SAAS,KAAK;GACd,eAAe,KAAK;GACpB,GAAI,KAAK,SAAS,KAAK,MAAM,SAAS,IAAI,EAAE,OAAO,KAAK,OAAO,GAAG,EAAE;GACpE,GAAI,KAAK,iBAAiB,QAAQ,EAAE,OAAO,EAAE,SAAS,KAAK,MAAM,SAAS,EAAE,GAAG,EAAE;GAClF;;CAGH,qBAA6B;EAC3B,IAAI,MAAM,KAAK;AACf,MAAI,KAAK,SAAS,KAAK,MAAM,SAAS,EACpC,QAAO,iBAAiB,KAAK,MAAM,KAAK,MAAM,OAAO,IAAI,CAAC,KAAK,KAAK;AAEtE,SAAO;;;AAMX,IAAa,cAAb,MAAa,oBAAoB,SAAS;CACxC,OAAgB;CAChB,gBAAyB;CAEzB,OAAO,eAA4B;AACjC,SAAO,IAAI,YAAY,4BAA4B;GACjD;GACA;GACA;GACD,CAAC;;;AAMN,IAAa,kBAAb,MAAa,wBAAwB,SAAS;CAC5C,OAAgB;CAChB,gBAAyB;CAEzB,YACE,SACA,OACA,OACA,OACA;AACA,QAAM,SAAS,OAAO,MAAM;AAJZ,OAAA,QAAA;;CAOlB,SAAkB;AAChB,SAAO;GAAE,GAAG,MAAM,QAAQ;GAAE,OAAO,KAAK;GAAO;;CAGjD,OAAO,SAAS,OAAe,OAAmC;AAChE,SAAO,IAAI,gBAAgB,GAAG,MAAM,eAAe,OAAO,MAAM;;;AAMpE,IAAa,WAAb,MAAa,iBAAiB,SAAS;CACrC,OAAgB;CACh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O,SAAS;;;;;AAMlB,SAAgB,YACd,OACA,WACA,SACU;CACV,MAAM,aAAa,SAAS,QAAQ;CAEpC,IAAI;AACJ,KAAI,WAAW,MAAM,CACnB,YAAW;KAEX,YAAW,SAAS,eAAe,MAAM;AAK3C,KADa,UACJ,WAAW,OAClB,WAAU,OAAO,SAAS,QAAQ,CAAC;KAEnC,WAAU,MAAM,SAAS,oBAAoB,CAAC;CAGhD,MAAM,WAAW,YAAY,SAAS;AAEtC,KAAI,WACF,SAAQ,KAAK,SAAS;AAGxB,QAAO;;;;;AAMT,eAAsB,WACpB,IACA,WACwB;AACxB,KAAI;AACF,SAAO,MAAM,IAAI;UACV,OAAO;AACd,cAAY,OAAO,UAAU;AAC7B;;;;;;AAOJ,SAAgB,wBACd,OACA,OACA,WACO;CACP,MAAM,QAAQ,gBAAgB,SAAS,OAAO,CAAC,UAAU,QAAQ,CAAC;AAClE,aAAY,OAAO,UAAU;AAE7B,OAAM"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized error handling for forge-cli.
|
|
3
|
+
*/
|
|
4
|
+
import type { OutputFormatter } from "./output.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Exit codes for different error categories.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ExitCode: {
|
|
9
|
+
readonly SUCCESS: 0;
|
|
10
|
+
readonly GENERAL_ERROR: 1;
|
|
11
|
+
readonly AUTHENTICATION_ERROR: 2;
|
|
12
|
+
readonly VALIDATION_ERROR: 3;
|
|
13
|
+
readonly CONFIG_ERROR: 4;
|
|
14
|
+
readonly NOT_FOUND_ERROR: 5;
|
|
15
|
+
};
|
|
16
|
+
export type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];
|
|
17
|
+
/**
|
|
18
|
+
* Determine the appropriate exit code for an error.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getExitCode(error: unknown): ExitCode;
|
|
21
|
+
/**
|
|
22
|
+
* Central error handler for all commands.
|
|
23
|
+
*/
|
|
24
|
+
export declare function handleError(error: unknown, formatter: OutputFormatter, options?: {
|
|
25
|
+
exit?: boolean;
|
|
26
|
+
}): ExitCode;
|
|
27
|
+
/**
|
|
28
|
+
* Wraps a command function with automatic error handling.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runCommand<T>(fn: () => Promise<T>, formatter: OutputFormatter): Promise<T | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Exits with a validation error for a missing required argument.
|
|
33
|
+
*/
|
|
34
|
+
export declare function exitWithValidationError(field: string, usage: string, formatter: OutputFormatter): never;
|
|
35
|
+
/**
|
|
36
|
+
* Exits with a config error when token is missing.
|
|
37
|
+
*/
|
|
38
|
+
export declare function exitWithConfigError(formatter: OutputFormatter): never;
|
|
39
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;;;CAOX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAEhE;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAYpD;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,eAAe,EAC1B,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3B,QAAQ,CAyBV;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,EAAE,eAAe,GACzB,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAOxB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,eAAe,GACzB,KAAK,CAKP;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,eAAe,GAAG,KAAK,CAIrE"}
|