@crediolabs/policy-builder-cli 0.1.17 → 0.2.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/src/output.ts CHANGED
@@ -1,4 +1,4 @@
1
- // apps/policy-builder-cli/src/output.ts
1
+ // packages/policy-builder-cli/src/output.ts
2
2
  //
3
3
  // Output helpers for the CLI: formatToolResponse for the `--json` flag and
4
4
  // file I/O for `--out`. The CLI is intentionally tiny - no commander / yargs
@@ -120,18 +120,16 @@ export function formatToolResponse<T>(
120
120
  flags: CliFlags,
121
121
  outLabel = 'result'
122
122
  ): T {
123
- if (res.ok) {
124
- const envelope = { ok: true as const, data: res.data }
125
- if (flags.out) writeJsonFile(flags.out, envelope)
126
- if (flags.json) {
127
- // newline-terminated JSON so it pipes cleanly
128
- process.stdout.write(`${JSON.stringify(envelope)}\n`)
129
- } else if (!flags.quiet) {
130
- process.stdout.write(`${outLabel}: ok\n`)
131
- }
132
- return res.data
123
+ if (!res.ok) throw new CliError(res.error)
124
+ const envelope = { ok: true as const, data: res.data }
125
+ if (flags.out) writeJsonFile(flags.out, envelope)
126
+ if (flags.json) {
127
+ // newline-terminated JSON so it pipes cleanly
128
+ process.stdout.write(`${JSON.stringify(envelope)}\n`)
129
+ } else if (!flags.quiet) {
130
+ process.stdout.write(`${outLabel}: ok\n`)
133
131
  }
134
- throw new CliError(res.error)
132
+ return res.data
135
133
  }
136
134
 
137
135
  /** CLI-specific error codes, distinct from the core's ErrorCode union. They