Skip to content

Commit 8c58b25

Browse files
authored
feat(cli): exposed synth's quiet option in cdk.json (#24793)
The `quiet` option for `synth` can now be specified in `cdk.json` as: ``` { "quiet": true } ``` Closes #24251 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 1a43f6d commit 8c58b25

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts

+11
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,17 @@ integTest('synthing a stage with errors can be suppressed', withDefaultFixture(a
717717
});
718718
}));
719719

720+
integTest('synth --quiet can be specified in cdk.json', withDefaultFixture(async (fixture) => {
721+
let cdkJson = JSON.parse(await fs.readFile(path.join(fixture.integTestDir, 'cdk.json'), 'utf8'));
722+
cdkJson = {
723+
...cdkJson,
724+
quiet: true,
725+
};
726+
await fs.writeFile(path.join(fixture.integTestDir, 'cdk.json'), JSON.stringify(cdkJson));
727+
const synthOutput = await fixture.cdk(['synth', fixture.fullStackName('test-2')]);
728+
expect(synthOutput).not.toContain('topic152D84A37');
729+
}));
730+
720731
integTest('deploy stack without resource', withDefaultFixture(async (fixture) => {
721732
// Deploy the stack without resources
722733
await fixture.cdkDeploy('conditional-resource', { modEnv: { NO_RESOURCE: 'TRUE' } });

packages/aws-cdk/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ $ # Synthesize cloud assembly for StackName, but don't cloudFormation template o
131131
$ cdk synth MyStackName --quiet
132132
```
133133

134+
The `quiet` option can be set in the `cdk.json` file.
135+
136+
```json
137+
{
138+
"quiet": true
139+
}
140+
```
141+
134142
See the [AWS Documentation](https://docs.aws.amazon.com/cdk/latest/guide/apps.html#apps_cloud_assembly) to learn more about cloud assemblies.
135143
See the [CDK reference documentation](https://docs.aws.amazon.com/cdk/api/latest/docs/cloud-assembly-schema-readme.html) for details on the cloud assembly specification
136144

packages/aws-cdk/lib/cli.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,11 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
622622

623623
case 'synthesize':
624624
case 'synth':
625+
const quiet = configuration.settings.get(['quiet']) ?? args.quiet;
625626
if (args.exclusively) {
626-
return cli.synth(args.STACKS, args.exclusively, args.quiet, args.validation, argv.json);
627+
return cli.synth(args.STACKS, args.exclusively, quiet, args.validation, argv.json);
627628
} else {
628-
return cli.synth(args.STACKS, true, args.quiet, args.validation, argv.json);
629+
return cli.synth(args.STACKS, true, quiet, args.validation, argv.json);
629630
}
630631

631632
case 'notices':

packages/aws-cdk/test/usersettings.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,26 @@ test('throws an error if the `build` key is specified in the user config', async
8989

9090
// THEN
9191
await expect(new Configuration().load()).rejects.toEqual(new Error('The `build` key cannot be specified in the user config (~/.cdk.json), specify it in the project config (cdk.json) instead'));
92+
});
93+
94+
test('Can specify the `quiet` key in the user config', async () => {
95+
// GIVEN
96+
const GIVEN_CONFIG: Map<string, any> = new Map([
97+
[USER_CONFIG, {
98+
quiet: true,
99+
}],
100+
]);
101+
102+
// WHEN
103+
mockedFs.pathExists.mockImplementation(path => {
104+
return GIVEN_CONFIG.has(path);
105+
});
106+
mockedFs.readJSON.mockImplementation(path => {
107+
return GIVEN_CONFIG.get(path);
108+
});
109+
110+
// THEN
111+
const config = await new Configuration().load();
112+
113+
expect(config.settings.get(['quiet'])).toBe(true);
92114
});

0 commit comments

Comments
 (0)