feat(core): add root level forwardAllArgs (#22753)

This commit is contained in:
Emily Xiong 2024-04-22 16:13:00 -04:00 committed by GitHub
parent 55a933855c
commit c3a3d1b0a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 57 additions and 3 deletions

View File

@ -121,6 +121,11 @@
"items": { "type": "string" },
"$default": { "$source": "unparsed" },
"x-priority": "internal"
},
"forwardAllArgs": {
"type": "boolean",
"description": "Whether arguments should be forwarded when interpolation is not present.",
"default": true
}
},
"additionalProperties": true,

View File

@ -37,19 +37,61 @@ describe('Run Commands', () => {
});
it('should not pass --args into underlying command', async () => {
const f = fileSync().name;
const result = await runCommands(
{
command: `echo`,
__unparsed__: ['--args=--key=123'],
args: '--key=123',
unparsedCommandArgs: { args: '--key=123' },
},
context
);
expect(result.terminalOutput.trim()).not.toContain('--args=--key=123');
});
it('should not foward any args to underlying command if forwardAllArgs is false', async () => {
let result = await runCommands(
{
command: `echo`,
key: 123,
__unparsed__: [],
forwardAllArgs: false,
},
context
);
expect(result.terminalOutput.trim()).not.toContain('--key=123');
result = await runCommands(
{
command: `echo`,
key: 123,
__unparsed__: [],
forwardAllArgs: true,
},
context
);
expect(result.terminalOutput.trim()).toContain('--key=123');
result = await runCommands(
{
commands: [
{
command: `echo 1`,
forwardAllArgs: true,
},
{
command: `echo 2`,
},
],
__unparsed__: ['--args=--key=123'],
args: '--key=123',
forwardAllArgs: false,
},
context
);
expect(result.terminalOutput).toContain('1 --key=123');
expect(result.terminalOutput).not.toContain('2 --key=123');
});
it('should interpolate all unknown args as if they were --args', async () => {
const f = fileSync().name;
const result = await runCommands(

View File

@ -54,6 +54,7 @@ export interface RunCommandsOptions extends Json {
readyWhen?: string;
cwd?: string;
env?: Record<string, string>;
forwardAllArgs?: boolean; // default is true
args?: string | string[];
envFile?: string;
__unparsed__: string[];
@ -75,6 +76,7 @@ const propKeys = [
'usePty',
'streamOutput',
'verbose',
'forwardAllArgs',
];
export interface NormalizedRunCommandsOptions extends RunCommandsOptions {
@ -244,7 +246,7 @@ function normalizeOptions(
c.command = interpolateArgsIntoCommand(
c.command,
options as NormalizedRunCommandsOptions,
c.forwardAllArgs ?? true
c.forwardAllArgs ?? options.forwardAllArgs ?? true
);
});
return options as NormalizedRunCommandsOptions;

View File

@ -135,6 +135,11 @@
"$source": "unparsed"
},
"x-priority": "internal"
},
"forwardAllArgs": {
"type": "boolean",
"description": "Whether arguments should be forwarded when interpolation is not present.",
"default": true
}
},
"additionalProperties": true,