@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/README.md +41 -104
- package/dist/bin/policy-builder.js +10 -1
- package/dist/src/commands/merge.d.ts +2 -0
- package/dist/src/commands/merge.js +58 -0
- package/dist/src/commands/record.js +1 -1
- package/dist/src/commands/synthesize.js +70 -78
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +2 -1
- package/dist/src/output.js +13 -14
- package/dist-cjs/src/commands/merge.d.ts +2 -0
- package/dist-cjs/src/commands/merge.js +61 -0
- package/dist-cjs/src/commands/record.js +1 -1
- package/dist-cjs/src/commands/synthesize.js +70 -78
- package/dist-cjs/src/index.d.ts +1 -0
- package/dist-cjs/src/index.js +4 -2
- package/dist-cjs/src/output.js +13 -14
- package/package.json +6 -6
- package/src/commands/merge.ts +65 -0
- package/src/commands/record.ts +1 -1
- package/src/commands/synthesize.ts +74 -90
- package/src/index.ts +2 -1
- package/src/output.ts +10 -12
package/src/output.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
132
|
+
return res.data
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
/** CLI-specific error codes, distinct from the core's ErrorCode union. They
|