Skip to content

Commit 80f3b94

Browse files
committed
refactor code
1 parent 90e1f1f commit 80f3b94

File tree

8 files changed

+687
-688
lines changed

8 files changed

+687
-688
lines changed

packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,14 +1290,16 @@ export class Toolkit extends CloudAssemblySourceBuilder {
12901290
const properties = report.properties as FeatureFlagReportProperties;
12911291
const moduleName = properties.module;
12921292

1293-
return Object.entries(properties.flags).map(([flagName, flagInfo]) => ({
1294-
module: moduleName,
1295-
name: flagName,
1296-
recommendedValue: flagInfo.recommendedValue,
1297-
userValue: flagInfo.userValue ?? undefined,
1298-
explanation: flagInfo.explanation ?? '',
1299-
unconfiguredBehavesLike: flagInfo.unconfiguredBehavesLike,
1300-
}));
1293+
return Object.entries(properties.flags).map(([flagName, flagInfo]) => {
1294+
return {
1295+
module: moduleName,
1296+
name: flagName,
1297+
recommendedValue: isBoolean(flagInfo.recommendedValue) ? toBooleanValue(flagInfo.recommendedValue) : flagInfo.recommendedValue,
1298+
userValue: isBoolean(flagInfo.userValue) ? toBooleanValue(flagInfo.userValue) : flagInfo.userValue,
1299+
explanation: flagInfo.explanation ?? '',
1300+
unconfiguredBehavesLike: flagInfo.unconfiguredBehavesLike,
1301+
};
1302+
});
13011303
});
13021304
}
13031305

@@ -1307,3 +1309,18 @@ export class Toolkit extends CloudAssemblySourceBuilder {
13071309
}
13081310
}
13091311
}
1312+
1313+
function isBoolean(value: unknown): boolean {
1314+
return typeof value === 'boolean' || value === 'true' || value === 'false';
1315+
}
1316+
1317+
function toBooleanValue(value: unknown): boolean {
1318+
if (typeof value === 'boolean') {
1319+
return value;
1320+
}
1321+
if (typeof value === 'string') {
1322+
return value.toLowerCase() === 'true';
1323+
}
1324+
return false;
1325+
}
1326+

packages/aws-cdk/lib/cli/cli-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ export async function makeConfig(): Promise<CliConfig> {
126126
unconfigured: { type: 'boolean', desc: 'Modify unconfigured feature flags', requiresArg: false },
127127
recommended: { type: 'boolean', desc: 'Change flags to recommended states', requiresArg: false },
128128
default: { type: 'boolean', desc: 'Change flags to default state', requiresArg: false },
129-
interactive: { type: 'boolean', alias: ['i'], desc: 'Interactive option for the flags command', requiresArg: false },
129+
interactive: { type: 'boolean', alias: ['i'], desc: 'Interactive option for the flags command' },
130130
safe: { type: 'boolean', desc: 'Enable all feature flags that do not impact the user\'s application', requiresArg: false },
131-
concurrency: { type: 'number', alias: ['conc'], desc: 'Maximum number of simultaneous synths to execute.', default: 4, requiresArg: true },
131+
concurrency: { type: 'number', alias: ['t'], desc: 'Maximum number of simultaneous synths to execute.', default: 4, requiresArg: true },
132132
},
133133
},
134134
'deploy': {

packages/aws-cdk/lib/cli/cli-type-registry.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@
371371
"alias": [
372372
"i"
373373
],
374-
"desc": "Interactive option for the flags command",
375-
"requiresArg": false
374+
"desc": "Interactive option for the flags command"
376375
},
377376
"safe": {
378377
"type": "boolean",
@@ -382,7 +381,7 @@
382381
"concurrency": {
383382
"type": "number",
384383
"alias": [
385-
"conc"
384+
"t"
386385
],
387386
"desc": "Maximum number of simultaneous synths to execute.",
388387
"default": 4,

packages/aws-cdk/lib/cli/cli.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type { Settings } from '../api/settings';
2525
import { contextHandler as context } from '../commands/context';
2626
import { docs } from '../commands/docs';
2727
import { doctor } from '../commands/doctor';
28-
import { handleFlags } from '../commands/flag-operations';
28+
import { DetermineSafeFlags } from '../commands/flag-operations';
2929
import { cliInit, printAvailableTemplates } from '../commands/init';
3030
import { getMigrateScanType } from '../commands/migrate';
3131
import { execProgram, CloudExecutable } from '../cxapp';
@@ -463,7 +463,8 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
463463
unstableFeatures: configuration.settings.get(['unstable']),
464464
});
465465
const flagsData = await toolkit.flags(cloudExecutable);
466-
return handleFlags(flagsData, ioHelper, args, toolkit);
466+
const handler = new DetermineSafeFlags(flagsData, ioHelper, args, toolkit);
467+
return handler.handleFlags();
467468

468469
case 'synthesize':
469470
case 'synth':

packages/aws-cdk/lib/cli/parse-command-line-arguments.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ export function parseCommandLineArguments(args: Array<string>): any {
395395
type: 'boolean',
396396
alias: ['i'],
397397
desc: 'Interactive option for the flags command',
398-
requiresArg: false,
399398
})
400399
.option('safe', {
401400
default: undefined,
@@ -406,7 +405,7 @@ export function parseCommandLineArguments(args: Array<string>): any {
406405
.option('concurrency', {
407406
default: 4,
408407
type: 'number',
409-
alias: ['conc'],
408+
alias: ['t'],
410409
desc: 'Maximum number of simultaneous synths to execute.',
411410
requiresArg: true,
412411
}),

packages/aws-cdk/lib/cli/user-input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ export interface FlagsOptions {
676676
/**
677677
* Maximum number of simultaneous synths to execute.
678678
*
679-
* aliases: conc
679+
* aliases: t
680680
*
681681
* @default - 4
682682
*/

0 commit comments

Comments
 (0)