Skip to content

Commit 4517903

Browse files
jesseturner21claude
andcommitted
fix: respect --json flag in policy remove command
The remove action always output JSON regardless of whether --json was passed. Now matches the add command behavior: plain text by default, JSON only when --json is specified. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5799f8e commit 4517903

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

src/cli/primitives/PolicyPrimitive.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,23 +365,34 @@ export class PolicyPrimitive extends BasePrimitive<AddPolicyOptions, RemovablePo
365365

366366
if (cliOptions.name || cliOptions.force || cliOptions.json) {
367367
if (!cliOptions.name) {
368-
console.log(JSON.stringify({ success: false, error: '--name is required' }));
368+
if (cliOptions.json) {
369+
console.log(JSON.stringify({ success: false, error: '--name is required' }));
370+
} else {
371+
console.error('--name is required');
372+
}
369373
process.exit(1);
370374
}
371375

372376
// Build composite key when --engine is provided for unambiguous removal
373377
const removeKey = cliOptions.engine ? `${cliOptions.engine}/${cliOptions.name}` : cliOptions.name;
374378
const result = await this.remove(removeKey);
375-
console.log(
376-
JSON.stringify({
377-
success: result.success,
378-
resourceType: this.kind,
379-
resourceName: cliOptions.name,
380-
message: result.success ? `Removed policy '${cliOptions.name}'` : undefined,
381-
note: result.success ? SOURCE_CODE_NOTE : undefined,
382-
error: !result.success ? result.error : undefined,
383-
})
384-
);
379+
380+
if (cliOptions.json) {
381+
console.log(
382+
JSON.stringify({
383+
success: result.success,
384+
resourceType: this.kind,
385+
resourceName: cliOptions.name,
386+
message: result.success ? `Removed policy '${cliOptions.name}'` : undefined,
387+
note: result.success ? SOURCE_CODE_NOTE : undefined,
388+
error: !result.success ? result.error : undefined,
389+
})
390+
);
391+
} else if (result.success) {
392+
console.log(`Removed policy '${cliOptions.name}'`);
393+
} else {
394+
console.error(result.error);
395+
}
385396
process.exit(result.success ? 0 : 1);
386397
} else {
387398
const [{ render }, { default: React }, { RemoveFlow }] = await Promise.all([

0 commit comments

Comments
 (0)