Skip to content

Commit fa4e860

Browse files
authored
Revert "feat(cli): cannot pass objects and numbers as context arguments (#20068)"
This reverts commit ec2d68a.
1 parent 9e6d2cd commit fa4e860

2 files changed

Lines changed: 2 additions & 52 deletions

File tree

packages/aws-cdk/lib/settings.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -300,35 +300,6 @@ export class Settings {
300300
return ret;
301301
}
302302

303-
/**
304-
* Context can be passed as CLI arguments in the format
305-
* --context foo=bar
306-
*
307-
* The context value can be of any type, but when it is parsed
308-
* it is always a string. Here we attempt to determine the actual
309-
* type of the value.
310-
*/
311-
private static parseContextValue(contextValue: string): any {
312-
// If the value is a JSON object, then we try and parse it and return
313-
// the object.
314-
try {
315-
return JSON.parse(contextValue);
316-
} catch {}
317-
const num = parseFloat(contextValue);
318-
// parseFloat tries to convert any string to a number, but
319-
// if the string begins with a number it will convert that and
320-
// ignore the rest so only return a number if the number and the
321-
// string are the same
322-
if (!isNaN(num) && num.toString() === contextValue) {
323-
return num;
324-
}
325-
// The string value 'false' is truthy so explicitely check for 'false'
326-
if (contextValue === 'false') {
327-
return false;
328-
}
329-
return contextValue;
330-
}
331-
332303
private static parseStringContextListToObject(argv: Arguments): any {
333304
const context: any = {};
334305

@@ -339,15 +310,14 @@ export class Settings {
339310
if (parts[0].match(/^aws:.+/)) {
340311
throw new Error(`User-provided context cannot use keys prefixed with 'aws:', but ${parts[0]} was provided.`);
341312
}
342-
context[parts[0]] = this.parseContextValue(parts[1]);
313+
context[parts[0]] = parts[1];
343314
} else {
344315
warning('Context argument is not an assignment (key=value): %s', assignment);
345316
}
346317
}
347318
return context;
348319
}
349320

350-
351321
/**
352322
* Parse tags out of arguments
353323
*

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,6 @@ test('can parse string context from command line arguments with equals sign in v
8080
expect(settings2.get(['context']).foo).toEqual( 'bar=');
8181
});
8282

83-
test('can parse context from command line arguments and convert value to correct type', () => {
84-
// GIVEN
85-
const settings1 = Settings.fromCommandLineArguments({ context: ['foo=false'], _: [Command.DEPLOY] });
86-
const settings2 = Settings.fromCommandLineArguments({ context: ['foo=0'], _: [Command.DEPLOY] });
87-
const settings3 = Settings.fromCommandLineArguments({ context: ['foo=true'], _: [Command.DEPLOY] });
88-
const settings4 = Settings.fromCommandLineArguments({ context: ['foo={"a": "b", "c": true, "d": ["a", "b"]}'], _: [Command.DEPLOY] });
89-
const settings5 = Settings.fromCommandLineArguments({ context: ['foo=34'], _: [Command.DEPLOY] });
90-
const settings6 = Settings.fromCommandLineArguments({ context: ['foo=34 35'], _: [Command.DEPLOY] });
91-
const settings7 = Settings.fromCommandLineArguments({ context: ['foo=0x22'], _: [Command.DEPLOY] });
92-
93-
// THEN
94-
expect(settings1.get(['context']).foo).toEqual(false);
95-
expect(settings2.get(['context']).foo).toEqual(0);
96-
expect(settings3.get(['context']).foo).toEqual(true);
97-
expect(settings4.get(['context']).foo).toEqual({ a: 'b', c: true, d: ['a', 'b'] });
98-
expect(settings5.get(['context']).foo).toEqual(34);
99-
expect(settings6.get(['context']).foo).toEqual('34 35');
100-
expect(settings7.get(['context']).foo).toEqual('0x22');
101-
});
102-
10383
test('bundling stacks defaults to an empty list', () => {
10484
// GIVEN
10585
const settings = Settings.fromCommandLineArguments({
@@ -174,4 +154,4 @@ test('providing a build arg', () => {
174154

175155
// THEN
176156
expect(settings.get(['build'])).toEqual('mvn package');
177-
});
157+
});

0 commit comments

Comments
 (0)