Skip to content

Commit 4d555c9

Browse files
authored
fix: cdk flags outputs empty table when recommended flags are already set (#836)
Fixes #834 ### Description DX improvement. Previously, when the user ran `cdk flags` but already had all recommended flags configured, an empty table was displayed. <img width="1177" height="160" alt="Screenshot 2025-09-03 at 12 01 43" src="https://github.com/user-attachments/assets/3b41df96-4256-49a3-88fc-1e405a04d8e8" /> *No context here, what does the table mean?* In this change, we added a message to inform the user why they are seeing an empty table. We still print the table to maintain API consistency. <img width="1102" height="542" alt="Screenshot 2025-09-05 at 21 16 11" src="https://github.com/user-attachments/assets/6c389d01-31b2-4c48-a609-fa545f5453f1" /> *Now the user knows why the table is empty, and is given guidance to display all flags* ### Testing Added unit tests for positive and negative cases. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent ccef4c6 commit 4d555c9

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

packages/aws-cdk/lib/commands/flag-operations.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,13 @@ export async function displayFlags(params: FlagOperationsParams): Promise<void>
477477
}
478478

479479
await displayFlagTable(flagsToDisplay, ioHelper);
480+
481+
// Add helpful message after empty table when not using --all
482+
if (!all && flagsToDisplay.length === 0) {
483+
await ioHelper.defaults.info('');
484+
await ioHelper.defaults.info('✅ All feature flags are already set to their recommended values.');
485+
await ioHelper.defaults.info('Use \'cdk flags --all --unstable=flags\' to see all flags and their current values.');
486+
}
480487
}
481488

482489
function isUserValueEqualToRecommended(flag: FeatureFlag): boolean {

packages/aws-cdk/test/commands/flag-operations.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,68 @@ describe('displayFlags', () => {
325325
expect(plainTextOutput).not.toContain(' @aws-cdk/s3:anotherFlag');
326326
expect(plainTextOutput).not.toContain(' @aws-cdk/core:anothermatchingFlag');
327327
});
328+
329+
test('displays empty table message when all flags are set to recommended values', async () => {
330+
// Create test data where all flags are set to their recommended values
331+
const allRecommendedFlagsData: FeatureFlag[] = [
332+
{
333+
module: 'aws-cdk-lib',
334+
name: '@aws-cdk/core:flag1',
335+
recommendedValue: 'true',
336+
userValue: 'true',
337+
explanation: 'Flag 1 set to recommended value',
338+
},
339+
{
340+
module: 'aws-cdk-lib',
341+
name: '@aws-cdk/core:flag2',
342+
recommendedValue: 'false',
343+
userValue: 'false',
344+
explanation: 'Flag 2 set to recommended value',
345+
},
346+
];
347+
348+
const params = {
349+
flagData: allRecommendedFlagsData,
350+
toolkit: createMockToolkit(),
351+
ioHelper,
352+
// Not using --all, so it should filter to only show non-recommended flags
353+
};
354+
await displayFlags(params);
355+
356+
const plainTextOutput = output();
357+
// Should still show the table headers for API consistency
358+
expect(plainTextOutput).toContain('Feature Flag Name');
359+
expect(plainTextOutput).toContain('Recommended Value');
360+
// Should show helpful message after the empty table
361+
expect(plainTextOutput).toContain('✅ All feature flags are already set to their recommended values.');
362+
expect(plainTextOutput).toContain('Use \'cdk flags --all --unstable=flags\' to see all flags and their current values.');
363+
// Should not show the actual flag names since they're filtered out
364+
expect(plainTextOutput).not.toContain(' @aws-cdk/core:flag1');
365+
expect(plainTextOutput).not.toContain(' @aws-cdk/core:flag2');
366+
});
367+
368+
test('does not show empty table message when some flags are not set to recommended values', async () => {
369+
// Use the original mockFlagsData which has mixed flag states
370+
// @aws-cdk/core:testFlag has userValue 'false' but recommendedValue 'true'
371+
// @aws-cdk/s3:anotherFlag has userValue undefined (not set to recommended)
372+
const params = {
373+
flagData: mockFlagsData,
374+
toolkit: createMockToolkit(),
375+
ioHelper,
376+
// Not using --all, so it should show flags that need attention
377+
};
378+
await displayFlags(params);
379+
380+
const plainTextOutput = output();
381+
// Should show the table with flags that need attention
382+
expect(plainTextOutput).toContain('Feature Flag Name');
383+
expect(plainTextOutput).toContain('Recommended Value');
384+
expect(plainTextOutput).toContain(' @aws-cdk/core:testFlag');
385+
expect(plainTextOutput).toContain(' @aws-cdk/s3:anotherFlag');
386+
// Should NOT show the helpful message since there are flags to display
387+
expect(plainTextOutput).not.toContain('✅ All feature flags are already set to their recommended values.');
388+
expect(plainTextOutput).not.toContain('Use \'cdk flags --all --unstable=flags\' to see all flags and their current values.');
389+
});
328390
});
329391

330392
describe('handleFlags', () => {

0 commit comments

Comments
 (0)